Skip to content

Commit

Permalink
Support semantic highlight, introduced in specification 3.16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jlahoda authored and MaskRay committed Jun 6, 2021
1 parent 80d06eb commit b731d59
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ target_sources(ccls PRIVATE
src/messages/textDocument_hover.cc
src/messages/textDocument_references.cc
src/messages/textDocument_rename.cc
src/messages/textDocument_semanticToken.cc
src/messages/textDocument_signatureHelp.cc
src/messages/workspace.cc
)
Expand Down
2 changes: 2 additions & 0 deletions src/message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ MessageHandler::MessageHandler() {
bind("textDocument/rename", &MessageHandler::textDocument_rename);
bind("textDocument/signatureHelp", &MessageHandler::textDocument_signatureHelp);
bind("textDocument/typeDefinition", &MessageHandler::textDocument_typeDefinition);
bind("textDocument/semanticTokens/full", &MessageHandler::textDocument_semanticTokensFull);
bind("textDocument/semanticTokens/range", &MessageHandler::textDocument_semanticTokensRange);
bind("workspace/didChangeConfiguration", &MessageHandler::workspace_didChangeConfiguration);
bind("workspace/didChangeWatchedFiles", &MessageHandler::workspace_didChangeWatchedFiles);
bind("workspace/didChangeWorkspaceFolders", &MessageHandler::workspace_didChangeWorkspaceFolders);
Expand Down
11 changes: 11 additions & 0 deletions src/message_handler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ struct TextDocumentPositionParam {
TextDocumentIdentifier textDocument;
Position position;
};
struct SemanticTokensParams {
TextDocumentIdentifier textDocument;
};
REFLECT_STRUCT(SemanticTokensParams, textDocument);
struct SemanticTokensRangeParams {
TextDocumentIdentifier textDocument;
lsRange range;
};
REFLECT_STRUCT(SemanticTokensRangeParams, textDocument, range);
struct TextDocumentEdit {
VersionedTextDocumentIdentifier textDocument;
std::vector<TextEdit> edits;
Expand Down Expand Up @@ -287,6 +296,8 @@ private:
void textDocument_rename(RenameParam &, ReplyOnce &);
void textDocument_signatureHelp(TextDocumentPositionParam &, ReplyOnce &);
void textDocument_typeDefinition(TextDocumentPositionParam &, ReplyOnce &);
void textDocument_semanticTokensFull(SemanticTokensParams &, ReplyOnce &);
void textDocument_semanticTokensRange(SemanticTokensRangeParams &, ReplyOnce &);
void workspace_didChangeConfiguration(EmptyParam &);
void workspace_didChangeWatchedFiles(DidChangeWatchedFilesParam &);
void workspace_didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParam &);
Expand Down
53 changes: 52 additions & 1 deletion src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,47 @@
namespace ccls {
using namespace llvm;

std::vector<const char *> SEMANTIC_TOKENS = {
"unknown",

"file",
"module",
"namespace",
"package",
"class",
"method",
"property",
"field",
"constructor",
"enum",
"interface",
"function",
"variable",
"constant",
"string",
"number",
"boolean",
"array",
"object",
"key",
"null",
"enumMember",
"struct",
"event",
"operator",
"typeParameter",
"typeAlias", //252 => 27
"parameter",
"staticMethod",
"macro"
};

std::vector<const char *> SEMANTIC_MODIFIERS = {
"declaration", //1
"definition", //2
"static" //4
};

extern std::vector<std::string> g_init_options;

namespace {
Expand Down Expand Up @@ -89,6 +130,14 @@ struct ServerCap {
std::vector<const char *> commands = {ccls_xref};
} executeCommandProvider;
Config::ServerCap::Workspace workspace;
struct SemanticTokenProvider {
struct SemanticTokensLegend {
std::vector<const char *> tokenTypes = SEMANTIC_TOKENS;
std::vector<const char *> tokenModifiers = SEMANTIC_MODIFIERS;
} legend;
bool range = true;
bool full = true;
} semanticTokensProvider;
};
REFLECT_STRUCT(ServerCap::CodeActionOptions, codeActionKinds);
REFLECT_STRUCT(ServerCap::CodeLensOptions, resolveProvider);
Expand All @@ -109,7 +158,9 @@ REFLECT_STRUCT(ServerCap, textDocumentSync, hoverProvider, completionProvider,
documentRangeFormattingProvider,
documentOnTypeFormattingProvider, renameProvider,
documentLinkProvider, foldingRangeProvider,
executeCommandProvider, workspace);
executeCommandProvider, workspace, semanticTokensProvider);
REFLECT_STRUCT(ServerCap::SemanticTokenProvider, legend, range, full);
REFLECT_STRUCT(ServerCap::SemanticTokenProvider::SemanticTokensLegend, tokenTypes, tokenModifiers);

struct DynamicReg {
bool dynamicRegistration = false;
Expand Down
Loading

0 comments on commit b731d59

Please sign in to comment.