Open martin-azpillaga opened 3 months ago
🆙
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.
What do you think?
I think we could also extract this bit of logic to make the APIs a bit friendlier:
override fun semanticTokensFull(params: SemanticTokensParams): CompletableFuture<SemanticTokens> {
val ast = files[params.textDocument.uri]?.root ?: return CompletableFuture.completedFuture(SemanticTokens())
val tokens = semanticTokens(ast)
return CompletableFuture.completedFuture(encode(tokens))
}
open fun semanticTokens(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:
enum class SemanticTokenType (val legendName: String) { NAMESPACE("namespace"), CLASS("class"), ENUM("enum"), INTERFACE("interface"), STRUCT("struct"), TYPE_PARAMETER("typeParameter"), TYPE("type"), PARAMETER("parameter"), VARIABLE("variable"), PROPERTY("property"), ENUM_MEMBER("enumMember"), DECORATOR("decorator"), EVENT("event"), FUNCTION("function"), METHOD("method"), MACRO("macro"), LABEL("label"), COMMENT("comment"), STRING("string"), KEYWORD("keyword"), NUMBER("number"), REGULAR_EXPRESSION("regexp"), OPERATOR("operator") }
enum class SemanticTokenModifier(val legendName: String, val bit: Int) { DECLARATION("declaration", 1), DEFINITION("definition", 2), READ_ONLY("readonly", 4), STATIC("static", 8), DEPRECATED("deprecated", 16), ABSTRACT("abstract", 32), ASYNCHRONOUS("async", 64), MODIFICATION("modification", 128), DOCUMENTATION("documentation", 256), DEFAULT_LIBRARY("defaultLibrary", 512) }