From 973705db5887df46de5fd74d78bcd1614b808f86 Mon Sep 17 00:00:00 2001 From: ykiko Date: Fri, 26 Jul 2024 00:02:09 +0800 Subject: [PATCH] update for SemanticTokens. --- include/Feature/SemanticToken.h | 7 ++ include/Protocol/Language/SemanticToken.h | 117 +++++++++++++++++++++- include/Protocol/Protocol.h | 2 +- include/Protocol/SemanticTokens.h | 53 ---------- src/Feature/SemanticToken.cpp | 0 5 files changed, 124 insertions(+), 55 deletions(-) create mode 100644 include/Feature/SemanticToken.h delete mode 100644 include/Protocol/SemanticTokens.h create mode 100644 src/Feature/SemanticToken.cpp diff --git a/include/Feature/SemanticToken.h b/include/Feature/SemanticToken.h new file mode 100644 index 00000000..1e254fcb --- /dev/null +++ b/include/Feature/SemanticToken.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace clice { + +} diff --git a/include/Protocol/Language/SemanticToken.h b/include/Protocol/Language/SemanticToken.h index 0db606af..b2c3aae5 100644 --- a/include/Protocol/Language/SemanticToken.h +++ b/include/Protocol/Language/SemanticToken.h @@ -4,6 +4,121 @@ namespace clice::protocol { +enum class SemanticTokenTypes : uint8_t { + Namespace = 0, + Type, + Class, + Enum, + Interface, + Struct, + TypeParameter, + Parameter, + Variable, + Property, + EnumMember, + Event, + Function, + Method, + Macro, + Keyword, + Modifier, + Comment, + String, + Number, + Regexp, + Operator, + Decorator +}; +enum class SemanticTokenModifiers : uint8_t { + Declaration = 0, + Definition, + Readonly, + Static, + Deprecated, + Abstract, + Async, + Modification, + Documentation, + DefaultLibrary +}; -} \ No newline at end of file +/// Client Capability: +/// - property name(optional): `textDocument.semanticTokens` +/// - property type: `SemanticTokensClientCapabilities` defined as follows: +struct SemanticTokensClientCapabilities { + /// Whether implementation supports dynamic registration. If this is set to `true` the client + bool dynamicRegistration = false; + + struct Requests { + // FIXME: + }; + + /// The token types that the client supports. + std::vector tokenTypes; + + /// The token modifiers that the client supports. + std::vector tokenModifiers; + + /// The formats the client supports. + /// formats: TokenFormat[]; + + /// Whether the client supports tokens that can overlap each other. + bool overlappingTokenSupport = false; + + /// Whether the client supports tokens that can span multiple lines. + bool multilineTokenSupport = false; + + /// Whether the client allows the server to actively cancel a semantic token request. + bool serverCancelSupport = false; + + /// Whether the client uses semantic tokens to augment existing syntax tokens. + bool serverCancelSupports = false; +}; + +struct SemanticTokensLegend { + /// The token types a server uses. + std::vector tokenTypes; + + /// The token modifiers a server uses. + std::vector tokenModifiers; +}; + +/// Server Capability: +/// - property name(optional): `textDocument.semanticTokens` +/// - property type: `SemanticTokensOptionss` defined as follows: +struct SemanticTokensOptions { + /// The legend used by the server. + SemanticTokensLegend legend; + + /// Server supports providing semantic tokens for a specific range. + bool range = false; + + /// Server supports providing semantic tokens for a full document. + bool full = false; +}; + +/// Request: +/// - method: `textDocument/semanticTokens/full` +/// - params: `SemanticTokensParams` defined as follows: +struct SemanticTokensParamsBody { + /// The text document. + TextDocumentIdentifier textDocument; +}; + +using SemanticTokensParams = Combine< + // WorkDoneProgressParams, + // PartialResultParams, + SemanticTokensParamsBody>; + +/// Response: +/// - result: `SemanticTokens` defined as follows: +struct SemanticTokens { + /// An optional result id. + String resultId; + + /// The actual tokens. + std::vector data; +}; + +} // namespace clice::protocol diff --git a/include/Protocol/Protocol.h b/include/Protocol/Protocol.h index 919b79ec..b703ec4b 100644 --- a/include/Protocol/Protocol.h +++ b/include/Protocol/Protocol.h @@ -5,7 +5,7 @@ #include #include -#include "SemanticTokens.h" +#include "Language/SemanticToken.h" namespace clice { diff --git a/include/Protocol/SemanticTokens.h b/include/Protocol/SemanticTokens.h deleted file mode 100644 index 6ed1c86f..00000000 --- a/include/Protocol/SemanticTokens.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -namespace clice { - -// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_semanticTokens -// The protocol defines a set of token types and modifiers but clients are -// allowed to extend these and announce the values they support in the -// corresponding client capability. -enum class SemanticTokenTypes { - Namespace, - Type, - Class, - Enum, - Interface, - Struct, - TypeParameter, - Parameter, - Variable, - Property, - EnumMember, - Event, - Function, - Method, - Macro, - Keyword, - Modifier, - Comment, - String, - Number, - Regexp, - Operator, - Decorator // @since 3.17.0 -}; - -enum SemanticTokenModifiers { - Declaration, - Definition, - Readonly, - Static, - Deprecated, - Abstract, - Async, - Modification, - Documentation, - DefaultLibrary -}; - -struct SemanticTokensLegend { - std::vector tokenTypes; - std::vector tokenModifiers; -}; - -} // namespace clice diff --git a/src/Feature/SemanticToken.cpp b/src/Feature/SemanticToken.cpp new file mode 100644 index 00000000..e69de29b