Extension API: add token type provider
Created by: chrismwendt
Prior to this change, hover tooltips (specifically the "Find references" button) would be shown even on comments, whitespace, etc. There was no way for extensions to prevent that from happening.
After this change, there will be a token type provider in the extension API that can be used to prevent hover tooltips from showing up on comments, whitespace, etc. Here's how you will be able to use it:
const identifier: sourcegraph.TokenType = 'identifier'
const whitespace: sourcegraph.TokenType = 'whitespace'
ctx.subscriptions.add(
sourcegraph.languages.registerTokenTypeProvider(
[{ pattern: '*.go' }],
{
provideTokenType: (doc, pos) => {
// toy example: returns identifier on even lines and whitespace on odd
return Promise.resolve(pos.line % 2 === 0 ? identifier : whitespace)
},
}
)
)
Test plan:
- Sideload an extension that registers a token type provider that emits
identifier
on even lines andwhitespace
on odd lines, make sure hover tooltips show up on even lines and not on odd lines - Make sure existing extensions still show hover tooltips even though they haven't registered a token type provider
Previous implementation attempt https://github.com/sourcegraph/sourcegraph/pull/3188
TODO
-
Add proper docstrings -
Add tests