clang-tools 22.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/StringMap.h"
30#include "llvm/ADT/StringSet.h"
31#include <functional>
32#include <optional>
33#include <string>
34#include <vector>
35
36namespace clang {
37namespace clangd {
38
39/// Settings that express user/project preferences and control clangd behavior.
40///
41/// Generally, features should consume Config::current() and the caller is
42/// responsible for setting it appropriately. In practice these callers are
43/// ClangdServer, TUScheduler, and BackgroundQueue.
44struct Config {
45 /// Returns the Config of the current Context, or an empty configuration.
46 static const Config &current();
47 /// Context key which can be used to set the current Config.
49
50 Config() = default;
51 Config(const Config &) = delete;
52 Config &operator=(const Config &) = delete;
53 Config(Config &&) = default;
54 Config &operator=(Config &&) = default;
55
58 // Absolute, native slashes, no trailing slash.
59 std::optional<std::string> FixedCDBPath;
60 };
61
63 /// Controls how the compile command for the current file is determined.
64 struct {
65 /// Edits to apply to the compile command, in sequence.
66 std::vector<llvm::unique_function<void(std::vector<std::string> &) const>>
68 /// Where to search for compilation databases for this file's flags.
70
71 /// Whether to use clangd's own builtin headers, or ones from the system
72 /// include extractor, if available.
75
76 enum class BackgroundPolicy { Build, Skip };
77 /// Describes an external index configuration.
79 enum { None, File, Server } Kind = None;
80 /// This is one of:
81 /// - Address of a clangd-index-server, in the form of "ip:port".
82 /// - Absolute path to an index produced by clangd-indexer.
83 std::string Location;
84 /// Absolute path to source root this index is associated with, uses
85 /// forward-slashes.
86 std::string MountPoint;
87 };
88 /// Controls index behavior.
89 struct {
90 /// Whether this TU should be background-indexed.
93 bool StandardLibrary = true;
95
96 enum class IncludesPolicy {
97 /// Diagnose missing and unused includes.
100 };
102 /// Controls warnings and errors when parsing code.
103 struct {
104 bool SuppressAll = false;
105 llvm::StringSet<> Suppress;
106
107 /// Configures what clang-tidy checks to run and options to use with them.
108 struct {
109 // A comma-separated list of globs specify which clang-tidy checks to run.
110 std::string Checks;
111 llvm::StringMap<std::string> CheckOptions;
114
117
118 struct {
119 /// IncludeCleaner will not diagnose usages of these headers matched by
120 /// these regexes.
121 std::vector<std::function<bool(llvm::StringRef)>> IgnoreHeader;
125
126 /// Style of the codebase.
127 struct {
128 // Namespaces that should always be fully qualified, meaning no "using"
129 // declarations, always spell out the whole name (with or without leading
130 // ::). All nested namespaces are affected as well.
131 std::vector<std::string> FullyQualifiedNamespaces;
132
133 // List of matcher functions for inserting certain headers with <> or "".
134 std::vector<std::function<bool(llvm::StringRef)>> QuotedHeaders;
135 std::vector<std::function<bool(llvm::StringRef)>> AngledHeaders;
137
138 /// controls the completion options for argument lists.
140 /// nothing, no argument list and also NO Delimiters "()" or "<>".
142 /// open, only opening delimiter "(" or "<".
144 /// empty pair of delimiters "()" or "<>".
146 /// full name of both type and variable.
148 };
149
151 IWYU, // Include what you use
152 NeverInsert // Never insert headers as part of code completion
153 };
154
156 All, // Suggest all code patterns and snippets
157 None // Suggest none of the code patterns and snippets
158 };
159
160 enum class MacroFilterPolicy {
161 ExactPrefix, // Suggest macros if the prefix matches exactly
162 FuzzyMatch, // Fuzzy-match macros if they do not have "_" as prefix or
163 // suffix
164 };
165
166 /// Configures code completion feature.
167 struct {
168 /// Whether code completion includes results that are not visible in current
169 /// scopes.
170 bool AllScopes = true;
171 /// controls the completion options for argument lists.
173 /// Controls if headers should be inserted when completions are accepted
175 /// Enables code patterns & snippets suggestions
177 /// Controls how macros are filtered
180
181 /// Configures hover feature.
182 struct {
183 /// Whether hover show a.k.a type.
184 bool ShowAKA = true;
185 /// Limit the number of characters returned when hovering a macro;
186 /// 0 is no limit.
187 uint32_t MacroContentsLimit = 2048;
189
190 struct {
191 /// If false, inlay hints are completely disabled.
192 bool Enabled = true;
193
194 // Whether specific categories of hints are enabled.
195 bool Parameters = true;
196 bool DeducedTypes = true;
197 bool Designators = true;
198 bool BlockEnd = false;
199 bool DefaultArguments = false;
200 // Limit the length of type names in inlay hints. (0 means no limit)
201 uint32_t TypeNameLimit = 32;
203
204 struct {
205 /// Controls highlighting kinds that are disabled.
206 std::vector<std::string> DisabledKinds;
207 /// Controls highlighting modifiers that are disabled.
208 std::vector<std::string> DisabledModifiers;
210
212 /// Treat comments as plain text.
214 /// Treat comments as Markdown.
216 /// Treat comments as doxygen.
218 };
219
220 struct {
223};
224
225} // namespace clangd
226} // namespace clang
227
228namespace llvm {
229template <> struct DenseMapInfo<clang::clangd::Config::ExternalIndexSpec> {
232 return {ExternalIndexSpec::File, "", ""};
233 }
235 return {ExternalIndexSpec::File, "TOMB", "STONE"};
236 }
237 static unsigned getHashValue(const ExternalIndexSpec &Val) {
238 return llvm::hash_combine(Val.Kind, Val.Location, Val.MountPoint);
239 }
240 static bool isEqual(const ExternalIndexSpec &LHS,
241 const ExternalIndexSpec &RHS) {
242 return std::tie(LHS.Kind, LHS.Location, LHS.MountPoint) ==
243 std::tie(RHS.Kind, RHS.Location, RHS.MountPoint);
244 }
245};
246} // namespace llvm
247
248#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:45
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
Definition Generators.h:145
enum clang::clangd::Config::CDBSearchSpec::@161062317271326205360254020036256036377317332042 Policy
std::optional< std::string > FixedCDBPath
Definition Config.h:59
Describes an external index configuration.
Definition Config.h:78
std::string Location
This is one of:
Definition Config.h:83
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:86
static clangd::Key< Config > Key
Context key which can be used to set the current Config.
Definition Config.h:48
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:110
FastCheckPolicy FastCheckFilter
Definition Config.h:112
bool AllScopes
Whether code completion includes results that are not visible in current scopes.
Definition Config.h:170
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:139
@ Delimiters
empty pair of delimiters "()" or "<>".
Definition Config.h:145
@ OpenDelimiter
open, only opening delimiter "(" or "<".
Definition Config.h:143
@ FullPlaceholders
full name of both type and variable.
Definition Config.h:147
@ Strict
Diagnose missing and unused includes.
Definition Config.h:98
ArgumentListsPolicy ArgumentLists
controls the completion options for argument lists.
Definition Config.h:172
@ Markdown
Treat comments as Markdown.
Definition Config.h:215
@ Doxygen
Treat comments as doxygen.
Definition Config.h:217
@ PlainText
Treat comments as plain text.
Definition Config.h:213
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:69
BackgroundPolicy Background
Whether this TU should be background-indexed.
Definition Config.h:91
bool ShowAKA
Whether hover show a.k.a type.
Definition Config.h:184
llvm::StringSet Suppress
Definition Config.h:105
Config & operator=(const Config &)=delete
ExternalIndexSpec External
Definition Config.h:92
std::vector< std::function< bool(llvm::StringRef)> > IgnoreHeader
IncludeCleaner will not diagnose usages of these headers matched by these regexes.
Definition Config.h:121
Config(const Config &)=delete
std::vector< std::string > DisabledKinds
Controls highlighting kinds that are disabled.
Definition Config.h:206
IncludesPolicy UnusedIncludes
Definition Config.h:115
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:134
struct clang::clangd::Config::@107213227304366036033370262336131167154154367111 Index
Controls index behavior.
std::vector< std::string > FullyQualifiedNamespaces
Definition Config.h:131
CodePatternsPolicy CodePatterns
Enables code patterns & snippets suggestions.
Definition Config.h:176
Config(Config &&)=default
IncludesPolicy MissingIncludes
Definition Config.h:116
std::vector< llvm::unique_function< void(std::vector< std::string > &) const > > Edits
Edits to apply to the compile command, in sequence.
Definition Config.h:67
struct clang::clangd::Config::@041344304366110202143331236314370324353035136032 InlayHints
llvm::StringMap< std::string > CheckOptions
Definition Config.h:111
Config & operator=(Config &&)=default
struct clang::clangd::Config::@343034053122374337352226322054223376344037116252::@071062222350100361347361256113054264067045123352 Includes
uint32_t TypeNameLimit
Definition Config.h:201
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:73
std::vector< std::string > DisabledModifiers
Controls highlighting modifiers that are disabled.
Definition Config.h:208
MacroFilterPolicy MacroFilter
Controls how macros are filtered.
Definition Config.h:178
CommentFormatPolicy CommentFormat
Definition Config.h:221
uint32_t MacroContentsLimit
Limit the number of characters returned when hovering a macro; 0 is no limit.
Definition Config.h:187
std::vector< std::function< bool(llvm::StringRef)> > AngledHeaders
Definition Config.h:135
bool Enabled
If false, inlay hints are completely disabled.
Definition Config.h:192
HeaderInsertionPolicy HeaderInsertion
Controls if headers should be inserted when completions are accepted.
Definition Config.h:174
A versioned set of tokens.
Definition Protocol.h:1848
static unsigned getHashValue(const ExternalIndexSpec &Val)
Definition Config.h:237
static bool isEqual(const ExternalIndexSpec &LHS, const ExternalIndexSpec &RHS)
Definition Config.h:240
clang::clangd::Config::ExternalIndexSpec ExternalIndexSpec
Definition Config.h:230