You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function to encode a list of semantic tokens to the numerical encoding the LSP uses:
funencode(tokens:List<SemanticToken>): SemanticTokens {
var lastLine =1// ? To offset that Kolasu lines start at 1var lastColumn =0val data = mutableListOf<Int>()
for (token in tokens) {
data.addAll(listOf(
token.position.start.line - lastLine,
if (token.position.start.line == lastLine) token.position.start.column - lastColumn else token.position.start.column,
token.position.end.column - token.position.start.column, // ! assumes tokens are in a single line
token.type.ordinal,
token.modifiers.sumOf { it.bit }
))
lastLine = token.position.start.line
lastColumn = token.position.start.column
}
returnSemanticTokens(data)
}
Configuration to enable semantic highlighting capabilities in the server initialization request:
I am fine with this suggestion, perhaps we could merge it before the article on syntax/semantic highlighting comes out so that we do not need to say that the feature is still not public.
I think we could also extract this bit of logic to make the APIs a bit friendlier:
overridefunsemanticTokensFull(params:SemanticTokensParams): CompletableFuture<SemanticTokens> {
val ast = files[params.textDocument.uri]?.root ?:returnCompletableFuture.completedFuture(SemanticTokens())
val tokens = semanticTokens(ast)
returnCompletableFuture.completedFuture(encode(tokens))
}
openfunsemanticTokens(ast:T): List<SemanticToken> =listOf()
Like this, developers just need to populate the list of semantic tokens starting from an ast, which I find more intuitive than dealing with LSP specific constructs.
Let's discuss whether to publish these changes before the article quickly in the next technical meeting.
To facilitate the implementation of semantic highlighting in language servers, I suggest adding the following reusable parts to this plugin:
The text was updated successfully, but these errors were encountered: