clang-tools 23.0.0git
Config.h
Go to the documentation of this file.
1//===--- Config.h - User configuration of clangd behavior --------*- 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// Various clangd features have configurable behaviour (or can be disabled).
10// This file defines "resolved" configuration seen by features within clangd.
11// For example, settings may vary per-file, the resolved Config only contains
12// settings that apply to the current file.
13//
14// This is distinct from how the config is specified by the user (Fragment)
15// interpreted (CompiledFragment), and combined (Provider).
16// ConfigFragment.h describes the steps to add a new configuration option.
17//
18// Because this structure is shared throughout clangd, it's a potential source
19// of layering problems. Config should be expressed in terms of simple
20// vocabulary types where possible.
21//
22//===----------------------------------------------------------------------===//
23
24#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONFIG_H
25#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONFIG_H
26
27#include "support/Context.h"
28#include "llvm/ADT/FunctionExtras.h"
29#include "llvm/ADT/Hashing.h"
30#include "llvm/ADT/StringMap.h"
31#include "llvm/ADT/StringSet.h"
32#include <functional>
33#include <optional>
34#include <string>
35#include <vector>
36
37namespace clang {
38namespace clangd {
39
40/// Settings that express user/project preferences and control clangd behavior.
41///
42/// Generally, features should consume Config::current() and the caller is
43/// responsible for setting it appropriately. In practice these callers are
44/// ClangdServer, TUScheduler, and BackgroundQueue.
45struct Config {
46 /// Returns the Config of the current Context, or an empty configuration.
47 static const Config &current();
48 /// Context key which can be used to set the current Config.
50
51 Config() = default;
52 Config(const Config &) = delete;
53 Config &operator=(const Config &) = delete;
54 Config(Config &&) = default;
55 Config &operator=(Config &&) = default;
56
59 // Absolute, native slashes, no trailing slash.
60 std::optional<std::string> FixedCDBPath;
61 };
62
64 /// Controls how the compile command for the current file is determined.
65 struct {
66 /// Edits to apply to the compile command, in sequence.
67 std::vector<llvm::unique_function<void(std::vector<std::string> &) const>>
69 /// Where to search for compilation databases for this file's flags.
71
72 /// Whether to use clangd's own builtin headers, or ones from the system
73 /// include extractor, if available.
76
77 enum class BackgroundPolicy { Build, Skip };
78 /// Describes an external index configuration.
80 enum { None, File, Server } Kind = None;
81 /// This is one of:
82 /// - Address of a clangd-index-server, in the form of "ip:port".
83 /// - Absolute path to an index produced by clangd-indexer.
84 std::string Location;
85 /// Absolute path to source root this index is associated with, uses
86 /// forward-slashes.
87 std::string MountPoint;
88 };
89 /// Controls index behavior.
90 struct {
91 /// Whether this TU should be background-indexed.
94 bool StandardLibrary = true;
96
97 enum class IncludesPolicy {
98 /// Diagnose missing and unused includes.
101 };
103 /// Controls warnings and errors when parsing code.
104 struct {
105 bool SuppressAll = false;
106 llvm::StringSet<> Suppress;
107
108 /// Configures what clang-tidy checks to run and options to use with them.
109 struct {
110 // A comma-separated list of globs specify which clang-tidy checks to run.
111 std::string Checks;
112 llvm::StringMap<std::string> CheckOptions;
115
118
119 struct {
120 /// IncludeCleaner will not diagnose usages of these headers matched by
121 /// these regexes.
122 std::vector<std::function<bool(llvm::StringRef)>> IgnoreHeader;
126
127 /// Style of the codebase.
128 struct {
129 // Namespaces that should always be fully qualified, meaning no "using"
130 // declarations, always spell out the whole name (with or without leading
131 // ::). All nested namespaces are affected as well.
132 std::vector<std::string> FullyQualifiedNamespaces;
133
134 // List of matcher functions for inserting certain headers with <> or "".
135 std::vector<std::function<bool(llvm::StringRef)>> QuotedHeaders;
136 std::vector<std::function<bool(llvm::StringRef)>> AngledHeaders;
138
139 /// controls the completion options for argument lists.
141 /// nothing, no argument list and also NO Delimiters "()" or "<>".
143 /// open, only opening delimiter "(" or "<".
145 /// empty pair of delimiters "()" or "<>".
147 /// full name of both type and variable.
149 };
150
152 IWYU, // Include what you use
153 NeverInsert // Never insert headers as part of code completion
154 };
155
157 All, // Suggest all code patterns and snippets
158 None // Suggest none of the code patterns and snippets
159 };
160
161 enum class MacroFilterPolicy {
162 ExactPrefix, // Suggest macros if the prefix matches exactly
163 FuzzyMatch, // Fuzzy-match macros if they do not have "_" as prefix or
164 // suffix
165 };
166
167 /// Configures code completion feature.
168 struct {
169 /// Whether code completion includes results that are not visible in current
170 /// scopes.
171 bool AllScopes = true;
172 /// controls the completion options for argument lists.
174 /// Controls if headers should be inserted when completions are accepted
176 /// Enables code patterns & snippets suggestions
178 /// Controls how macros are filtered
181
182 /// Configures hover feature.
183 struct {
184 /// Whether hover show a.k.a type.
185 bool ShowAKA = true;
186 /// Limit the number of characters returned when hovering a macro;
187 /// 0 is no limit.
188 uint32_t MacroContentsLimit = 2048;
190
191 struct {
192 /// If false, inlay hints are completely disabled.
193 bool Enabled = true;
194
195 // Whether specific categories of hints are enabled.
196 bool Parameters = true;
197 bool DeducedTypes = true;
198 bool Designators = true;
199 bool BlockEnd = false;
200 bool DefaultArguments = false;
201 // Limit the length of type names in inlay hints. (0 means no limit)
202 uint32_t TypeNameLimit = 32;
204
205 struct {
206 /// Controls highlighting kinds that are disabled.
207 std::vector<std::string> DisabledKinds;
208 /// Controls highlighting modifiers that are disabled.
209 std::vector<std::string> DisabledModifiers;
211
213 /// Treat comments as plain text.
215 /// Treat comments as Markdown.
217 /// Treat comments as doxygen.
219 };
220
221 struct {
224};
225
226} // namespace clangd
227} // namespace clang
228
229namespace llvm {
230template <> struct DenseMapInfo<clang::clangd::Config::ExternalIndexSpec> {
233 return {ExternalIndexSpec::File, "", ""};
234 }
236 return {ExternalIndexSpec::File, "TOMB", "STONE"};
237 }
238 static unsigned getHashValue(const ExternalIndexSpec &Val) {
239 return llvm::hash_combine(Val.Kind, Val.Location, Val.MountPoint);
240 }
241 static bool isEqual(const ExternalIndexSpec &LHS,
242 const ExternalIndexSpec &RHS) {
243 return std::tie(LHS.Kind, LHS.Location, LHS.MountPoint) ==
244 std::tie(RHS.Kind, RHS.Location, RHS.MountPoint);
245 }
246};
247} // namespace llvm
248
249#endif
Values in a Context are indexed by typed keys.
Definition Context.h:40
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition AST.cpp:44
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
Definition Generators.h:150
enum clang::clangd::Config::CDBSearchSpec::@161062317271326205360254020036256036377317332042 Policy
std::optional< std::string > FixedCDBPath
Definition Config.h:60
Describes an external index configuration.
Definition Config.h:79
std::string Location
This is one of:
Definition Config.h:84
enum clang::clangd::Config::ExternalIndexSpec::@312203371027245331141003236204003120156040237037 Kind
std::string MountPoint
Absolute path to source root this index is associated with, uses forward-slashes.
Definition Config.h:87
static clangd::Key< Config > Key
Context key which can be used to set the current Config.
Definition Config.h:49
struct clang::clangd::Config::@314053012031341203055315320366267371313202370174 Style
Style of the codebase.
struct clang::clangd::Config::@347104204155140144054042115114221214347344026246 CompileFlags
Controls how the compile command for the current file is determined.
std::string Checks
Definition Config.h:111
FastCheckPolicy FastCheckFilter
Definition Config.h:113
bool AllScopes
Whether code completion includes results that are not visible in current scopes.
Definition Config.h:171
static const Config & current()
Returns the Config of the current Context, or an empty configuration.
Definition Config.cpp:17
ArgumentListsPolicy
controls the completion options for argument lists.
Definition Config.h:140
@ Delimiters
empty pair of delimiters "()" or "<>".
Definition Config.h:146
@ OpenDelimiter
open, only opening delimiter "(" or "<".
Definition Config.h:144
@ FullPlaceholders
full name of both type and variable.
Definition Config.h:148
@ Strict
Diagnose missing and unused includes.
Definition Config.h:99
ArgumentListsPolicy ArgumentLists
controls the completion options for argument lists.
Definition Config.h:173
@ Markdown
Treat comments as Markdown.
Definition Config.h:216
@ Doxygen
Treat comments as doxygen.
Definition Config.h:218
@ PlainText
Treat comments as plain text.
Definition Config.h:214
struct clang::clangd::Config::@025253107333106252106023001214215004273337014125 Completion
Configures code completion feature.
struct clang::clangd::Config::@343034053122374337352226322054223376344037116252 Diagnostics
Controls warnings and errors when parsing code.
CDBSearchSpec CDBSearch
Where to search for compilation databases for this file's flags.
Definition Config.h:70
BackgroundPolicy Background
Whether this TU should be background-indexed.
Definition Config.h:92
bool ShowAKA
Whether hover show a.k.a type.
Definition Config.h:185
llvm::StringSet Suppress
Definition Config.h:106
Config & operator=(const Config &)=delete
ExternalIndexSpec External
Definition Config.h:93
std::vector< std::function< bool(llvm::StringRef)> > IgnoreHeader
IncludeCleaner will not diagnose usages of these headers matched by these regexes.
Definition Config.h:122
Config(const Config &)=delete
std::vector< std::string > DisabledKinds
Controls highlighting kinds that are disabled.
Definition Config.h:207
IncludesPolicy UnusedIncludes
Definition Config.h:116
struct clang::clangd::Config::@343034053122374337352226322054223376344037116252::@107156241027253143221327255130274177352007274355 ClangTidy
Configures what clang-tidy checks to run and options to use with them.
std::vector< std::function< bool(llvm::StringRef)> > QuotedHeaders
Definition Config.h:135
struct clang::clangd::Config::@107213227304366036033370262336131167154154367111 Index
Controls index behavior.
std::vector< std::string > FullyQualifiedNamespaces
Definition Config.h:132
CodePatternsPolicy CodePatterns
Enables code patterns & snippets suggestions.
Definition Config.h:177
Config(Config &&)=default
IncludesPolicy MissingIncludes
Definition Config.h:117
std::vector< llvm::unique_function< void(std::vector< std::string > &) const > > Edits
Edits to apply to the compile command, in sequence.
Definition Config.h:68
struct clang::clangd::Config::@041344304366110202143331236314370324353035136032 InlayHints
llvm::StringMap< std::string > CheckOptions
Definition Config.h:112
Config & operator=(Config &&)=default
struct clang::clangd::Config::@343034053122374337352226322054223376344037116252::@071062222350100361347361256113054264067045123352 Includes
uint32_t TypeNameLimit
Definition Config.h:202
struct clang::clangd::Config::@205014242342057164216030136313205137334246150047 Documentation
BuiltinHeaderPolicy BuiltinHeaders
Whether to use clangd's own builtin headers, or ones from the system include extractor,...
Definition Config.h:74
std::vector< std::string > DisabledModifiers
Controls highlighting modifiers that are disabled.
Definition Config.h:209
MacroFilterPolicy MacroFilter
Controls how macros are filtered.
Definition Config.h:179
CommentFormatPolicy CommentFormat
Definition Config.h:222
uint32_t MacroContentsLimit
Limit the number of characters returned when hovering a macro; 0 is no limit.
Definition Config.h:188
std::vector< std::function< bool(llvm::StringRef)> > AngledHeaders
Definition Config.h:136
bool Enabled
If false, inlay hints are completely disabled.
Definition Config.h:193
HeaderInsertionPolicy HeaderInsertion
Controls if headers should be inserted when completions are accepted.
Definition Config.h:175
A versioned set of tokens.
Definition Protocol.h:1901
static unsigned getHashValue(const ExternalIndexSpec &Val)
Definition Config.h:238
static bool isEqual(const ExternalIndexSpec &LHS, const ExternalIndexSpec &RHS)
Definition Config.h:241
clang::clangd::Config::ExternalIndexSpec ExternalIndexSpec
Definition Config.h:231