clang-tools  9.0.0
SemanticHighlighting.h
Go to the documentation of this file.
1 //==-- SemanticHighlighting.h - Generating highlights from the AST-- C++ -*-==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // An implementation of semantic highlighting based on this proposal:
10 // https://github.com/microsoft/vscode-languageserver-node/pull/367 in clangd.
11 // Semantic highlightings are calculated for an AST by visiting every AST node
12 // and classifying nodes that are interesting to highlight (variables/function
13 // calls etc.).
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H
18 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHTING_H
19 
20 #include "ClangdUnit.h"
21 #include "Protocol.h"
22 
23 namespace clang {
24 namespace clangd {
25 
26 enum class HighlightingKind {
27  Variable = 0,
28  Function,
29  Method,
30  Field,
31  Class,
32  Enum,
34  Namespace,
36 
37  NumKinds,
38 };
39 
40 // Contains all information needed for the highlighting a token.
44 };
45 
46 bool operator==(const HighlightingToken &Lhs, const HighlightingToken &Rhs);
47 
48 // Returns all HighlightingTokens from an AST. Only generates highlights for the
49 // main AST.
50 std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST);
51 
52 /// Converts a HighlightingKind to a corresponding TextMate scope
53 /// (https://manual.macromates.com/en/language_grammars).
54 llvm::StringRef toTextMateScope(HighlightingKind Kind);
55 
56 // Convert to LSP's semantic highlighting information.
57 std::vector<SemanticHighlightingInformation>
58 toSemanticHighlightingInformation(llvm::ArrayRef<HighlightingToken> Tokens);
59 
60 } // namespace clangd
61 } // namespace clang
62 
63 #endif
llvm::StringRef toTextMateScope(HighlightingKind Kind)
Converts a HighlightingKind to a corresponding TextMate scope (https://manual.macromates.com/en/language_grammars).
BindArgumentKind Kind
bool operator==(const Ref &L, const Ref &R)
Definition: Ref.h:61
StringRef Tokens
std::vector< SemanticHighlightingInformation > toSemanticHighlightingInformation(llvm::ArrayRef< HighlightingToken > Tokens)
Stores and provides access to parsed AST.
Definition: ClangdUnit.h:73
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< HighlightingToken > getSemanticHighlightings(ParsedAST &AST)