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 /// Configures code completion feature.
161 struct {
162 /// Whether code completion includes results that are not visible in current
163 /// scopes.
164 bool AllScopes = true;
165 /// controls the completion options for argument lists.
167 /// Controls if headers should be inserted when completions are accepted
169 /// Enables code patterns & snippets suggestions
172
173 /// Configures hover feature.
174 struct {
175 /// Whether hover show a.k.a type.
176 bool ShowAKA = true;
177 /// Limit the number of characters returned when hovering a macro;
178 /// 0 is no limit.
179 uint32_t MacroContentsLimit = 2048;
181
182 struct {
183 /// If false, inlay hints are completely disabled.
184 bool Enabled = true;
185
186 // Whether specific categories of hints are enabled.
187 bool Parameters = true;
188 bool DeducedTypes = true;
189 bool Designators = true;
190 bool BlockEnd = false;
191 bool DefaultArguments = false;
192 // Limit the length of type names in inlay hints. (0 means no limit)
193 uint32_t TypeNameLimit = 32;
195
196 struct {
197 /// Controls highlighting kinds that are disabled.
198 std::vector<std::string> DisabledKinds;
199 /// Controls highlighting modifiers that are disabled.
200 std::vector<std::string> DisabledModifiers;
202
204 /// Treat comments as plain text.
206 /// Treat comments as Markdown.
208 /// Treat comments as doxygen.
210 };
211
212 struct {
215};
216
217} // namespace clangd
218} // namespace clang
219
220namespace llvm {
221template <> struct DenseMapInfo<clang::clangd::Config::ExternalIndexSpec> {
224 return {ExternalIndexSpec::File, "", ""};
225 }
227 return {ExternalIndexSpec::File, "TOMB", "STONE"};
228 }
229 static unsigned getHashValue(const ExternalIndexSpec &Val) {
230 return llvm::hash_combine(Val.Kind, Val.Location, Val.MountPoint);
231 }
232 static bool isEqual(const ExternalIndexSpec &LHS,
233 const ExternalIndexSpec &RHS) {
234 return std::tie(LHS.Kind, LHS.Location, LHS.MountPoint) ==
235 std::tie(RHS.Kind, RHS.Location, RHS.MountPoint);
236 }
237};
238} // namespace llvm
239
240#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:66
enum clang::clangd::Config::CDBSearchSpec::@204212152173327223063121202366143221204051341004 Policy
std::optional< std::string > FixedCDBPath
Definition Config.h:59
Describes an external index configuration.
Definition Config.h:78
enum clang::clangd::Config::ExternalIndexSpec::@216221346246105351024304277277130164055373233215 Kind
std::string Location
This is one of:
Definition Config.h:83
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
std::string Checks
Definition Config.h:110
struct clang::clangd::Config::@224206046260313204212274150166346126315121140114::@177170157270305170147304143303331271375010045063 ClangTidy
Configures what clang-tidy checks to run and options to use with them.
FastCheckPolicy FastCheckFilter
Definition Config.h:112
struct clang::clangd::Config::@207031361004214306046114203113272307064216033306 Completion
Configures code completion feature.
struct clang::clangd::Config::@200054163263130041273073333055327265124363067160 InlayHints
bool AllScopes
Whether code completion includes results that are not visible in current scopes.
Definition Config.h:164
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:166
@ Markdown
Treat comments as Markdown.
Definition Config.h:207
@ Doxygen
Treat comments as doxygen.
Definition Config.h:209
@ PlainText
Treat comments as plain text.
Definition Config.h:205
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:176
llvm::StringSet Suppress
Definition Config.h:105
Config & operator=(const Config &)=delete
struct clang::clangd::Config::@224206046260313204212274150166346126315121140114::@156270132341007275067327044370330143015036321054 Includes
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:198
struct clang::clangd::Config::@340212122325041323223256240301061135214102252040 Documentation
IncludesPolicy UnusedIncludes
Definition Config.h:115
std::vector< std::function< bool(llvm::StringRef)> > QuotedHeaders
Definition Config.h:134
std::vector< std::string > FullyQualifiedNamespaces
Definition Config.h:131
CodePatternsPolicy CodePatterns
Enables code patterns & snippets suggestions.
Definition Config.h:170
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::@224206046260313204212274150166346126315121140114 Diagnostics
Controls warnings and errors when parsing code.
llvm::StringMap< std::string > CheckOptions
Definition Config.h:111
Config & operator=(Config &&)=default
struct clang::clangd::Config::@072252370142323110175010006107105013140064217165 Index
Controls index behavior.
uint32_t TypeNameLimit
Definition Config.h:193
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:200
CommentFormatPolicy CommentFormat
Definition Config.h:213
uint32_t MacroContentsLimit
Limit the number of characters returned when hovering a macro; 0 is no limit.
Definition Config.h:179
std::vector< std::function< bool(llvm::StringRef)> > AngledHeaders
Definition Config.h:135
struct clang::clangd::Config::@365336221326264215251130354321073040111277322060 Style
Style of the codebase.
bool Enabled
If false, inlay hints are completely disabled.
Definition Config.h:184
HeaderInsertionPolicy HeaderInsertion
Controls if headers should be inserted when completions are accepted.
Definition Config.h:168
struct clang::clangd::Config::@221333032074173032305210224173260176341176220132 CompileFlags
Controls how the compile command for the current file is determined.
A versioned set of tokens.
Definition Protocol.h:1842
static unsigned getHashValue(const ExternalIndexSpec &Val)
Definition Config.h:229
static bool isEqual(const ExternalIndexSpec &LHS, const ExternalIndexSpec &RHS)
Definition Config.h:232
clang::clangd::Config::ExternalIndexSpec ExternalIndexSpec
Definition Config.h:222