comparison clang-tools-extra/clangd/SemanticHighlighting.h @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
comparison
equal deleted inserted replaced
172:9fbae9c8bf63 173:0572611fdcc8
4 // See https://llvm.org/LICENSE.txt for license information. 4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // 6 //
7 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
8 // 8 //
9 // An implementation of semantic highlighting based on this proposal: 9 // This file supports semantic highlighting: categorizing tokens in the file so
10 // https://github.com/microsoft/vscode-languageserver-node/pull/367 in clangd. 10 // that the editor can color/style them differently.
11 //
12 // This is particularly valuable for C++: its complex and context-dependent
13 // grammar is a challenge for simple syntax-highlighting techniques.
14 //
15 // We support two protocols for providing highlights to the client:
16 // - the `textDocument/semanticTokens` request from LSP 3.16
17 // https://github.com/microsoft/vscode-languageserver-node/blob/release/protocol/3.16.0-next.1/protocol/src/protocol.semanticTokens.proposed.ts
18 // - the earlier proposed `textDocument/semanticHighlighting` notification
19 // https://github.com/microsoft/vscode-languageserver-node/pull/367
20 // This is referred to as "Theia" semantic highlighting in the code.
21 // It was supported from clangd 9 but should be considered deprecated as of
22 // clangd 11 and eventually removed.
23 //
11 // Semantic highlightings are calculated for an AST by visiting every AST node 24 // Semantic highlightings are calculated for an AST by visiting every AST node
12 // and classifying nodes that are interesting to highlight (variables/function 25 // and classifying nodes that are interesting to highlight (variables/function
13 // calls etc.). 26 // calls etc.).
14 // 27 //
15 //===----------------------------------------------------------------------===// 28 //===----------------------------------------------------------------------===//
73 86
74 // Returns all HighlightingTokens from an AST. Only generates highlights for the 87 // Returns all HighlightingTokens from an AST. Only generates highlights for the
75 // main AST. 88 // main AST.
76 std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST); 89 std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST);
77 90
91 std::vector<SemanticToken> toSemanticTokens(llvm::ArrayRef<HighlightingToken>);
92 llvm::StringRef toSemanticTokenType(HighlightingKind Kind);
93 std::vector<SemanticTokensEdit> diffTokens(llvm::ArrayRef<SemanticToken> Before,
94 llvm::ArrayRef<SemanticToken> After);
95
78 /// Converts a HighlightingKind to a corresponding TextMate scope 96 /// Converts a HighlightingKind to a corresponding TextMate scope
79 /// (https://manual.macromates.com/en/language_grammars). 97 /// (https://manual.macromates.com/en/language_grammars).
80 llvm::StringRef toTextMateScope(HighlightingKind Kind); 98 llvm::StringRef toTextMateScope(HighlightingKind Kind);
81 99
82 /// Convert to LSP's semantic highlighting information. 100 /// Convert to LSP's semantic highlighting information.
83 std::vector<SemanticHighlightingInformation> 101 std::vector<TheiaSemanticHighlightingInformation>
84 toSemanticHighlightingInformation(llvm::ArrayRef<LineHighlightings> Tokens); 102 toTheiaSemanticHighlightingInformation(
103 llvm::ArrayRef<LineHighlightings> Tokens);
85 104
86 /// Return a line-by-line diff between two highlightings. 105 /// Return a line-by-line diff between two highlightings.
87 /// - if the tokens on a line are the same in both highlightings, this line is 106 /// - if the tokens on a line are the same in both highlightings, this line is
88 /// omitted. 107 /// omitted.
89 /// - if a line exists in New but not in Old, the tokens on this line are 108 /// - if a line exists in New but not in Old, the tokens on this line are