clang-tools 19.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
62 /// Controls how the compile command for the current file is determined.
63 struct {
64 /// Edits to apply to the compile command, in sequence.
65 std::vector<llvm::unique_function<void(std::vector<std::string> &) const>>
67 /// Where to search for compilation databases for this file's flags.
70
71 enum class BackgroundPolicy { Build, Skip };
72 /// Describes an external index configuration.
74 enum { None, File, Server } Kind = None;
75 /// This is one of:
76 /// - Address of a clangd-index-server, in the form of "ip:port".
77 /// - Absolute path to an index produced by clangd-indexer.
78 std::string Location;
79 /// Absolute path to source root this index is associated with, uses
80 /// forward-slashes.
81 std::string MountPoint;
82 };
83 /// Controls index behavior.
84 struct {
85 /// Whether this TU should be background-indexed.
88 bool StandardLibrary = true;
90
91 enum class IncludesPolicy {
92 /// Diagnose missing and unused includes.
93 Strict,
94 None,
95 };
96 enum class FastCheckPolicy { Strict, Loose, None };
97 /// Controls warnings and errors when parsing code.
98 struct {
99 bool SuppressAll = false;
100 llvm::StringSet<> Suppress;
101
102 /// Configures what clang-tidy checks to run and options to use with them.
103 struct {
104 // A comma-separated list of globs specify which clang-tidy checks to run.
105 std::string Checks;
106 llvm::StringMap<std::string> CheckOptions;
109
112
113 /// IncludeCleaner will not diagnose usages of these headers matched by
114 /// these regexes.
115 struct {
116 std::vector<std::function<bool(llvm::StringRef)>> IgnoreHeader;
119
120 /// Style of the codebase.
121 struct {
122 // Namespaces that should always be fully qualified, meaning no "using"
123 // declarations, always spell out the whole name (with or without leading
124 // ::). All nested namespaces are affected as well.
125 std::vector<std::string> FullyQualifiedNamespaces;
127
128 /// Configures code completion feature.
129 struct {
130 /// Whether code completion includes results that are not visible in current
131 /// scopes.
132 bool AllScopes = true;
134
135 /// Configures hover feature.
136 struct {
137 /// Whether hover show a.k.a type.
138 bool ShowAKA = true;
140
141 struct {
142 /// If false, inlay hints are completely disabled.
143 bool Enabled = true;
144
145 // Whether specific categories of hints are enabled.
146 bool Parameters = true;
147 bool DeducedTypes = true;
148 bool Designators = true;
149 bool BlockEnd = false;
150 // Limit the length of type names in inlay hints. (0 means no limit)
151 uint32_t TypeNameLimit = 32;
153
154 struct {
155 /// Controls highlighting kinds that are disabled.
156 std::vector<std::string> DisabledKinds;
157 /// Controls highlighting modifiers that are disabled.
158 std::vector<std::string> DisabledModifiers;
160};
161
162} // namespace clangd
163} // namespace clang
164
165namespace llvm {
166template <> struct DenseMapInfo<clang::clangd::Config::ExternalIndexSpec> {
169 return {ExternalIndexSpec::File, "", ""};
170 }
172 return {ExternalIndexSpec::File, "TOMB", "STONE"};
173 }
174 static unsigned getHashValue(const ExternalIndexSpec &Val) {
175 return llvm::hash_combine(Val.Kind, Val.Location, Val.MountPoint);
176 }
177 static bool isEqual(const ExternalIndexSpec &LHS,
178 const ExternalIndexSpec &RHS) {
179 return std::tie(LHS.Kind, LHS.Location, LHS.MountPoint) ==
180 std::tie(RHS.Kind, RHS.Location, RHS.MountPoint);
181 }
182};
183} // namespace llvm
184
185#endif
Values in a Context are indexed by typed keys.
Definition: Context.h:40
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
enum clang::clangd::Config::CDBSearchSpec::@10 Policy
std::optional< std::string > FixedCDBPath
Definition: Config.h:59
Describes an external index configuration.
Definition: Config.h:73
enum clang::clangd::Config::ExternalIndexSpec::@11 Kind
std::string Location
This is one of:
Definition: Config.h:78
std::string MountPoint
Absolute path to source root this index is associated with, uses forward-slashes.
Definition: Config.h:81
Settings that express user/project preferences and control clangd behavior.
Definition: Config.h:44
static clangd::Key< Config > Key
Context key which can be used to set the current Config.
Definition: Config.h:48
struct clang::clangd::Config::@9 SemanticTokens
std::string Checks
Definition: Config.h:105
struct clang::clangd::Config::@4::@13 Includes
IncludeCleaner will not diagnose usages of these headers matched by these regexes.
FastCheckPolicy FastCheckFilter
Definition: Config.h:107
bool AllScopes
Whether code completion includes results that are not visible in current scopes.
Definition: Config.h:132
static const Config & current()
Returns the Config of the current Context, or an empty configuration.
Definition: Config.cpp:17
@ Strict
Diagnose missing and unused includes.
CDBSearchSpec CDBSearch
Where to search for compilation databases for this file's flags.
Definition: Config.h:68
BackgroundPolicy Background
Whether this TU should be background-indexed.
Definition: Config.h:86
bool ShowAKA
Whether hover show a.k.a type.
Definition: Config.h:138
llvm::StringSet Suppress
Definition: Config.h:100
struct clang::clangd::Config::@5 Style
Style of the codebase.
Config & operator=(const Config &)=delete
ExternalIndexSpec External
Definition: Config.h:87
struct clang::clangd::Config::@4::@12 ClangTidy
Configures what clang-tidy checks to run and options to use with them.
std::vector< std::function< bool(llvm::StringRef)> > IgnoreHeader
Definition: Config.h:116
struct clang::clangd::Config::@2 CompileFlags
Controls how the compile command for the current file is determined.
Config(const Config &)=delete
std::vector< std::string > DisabledKinds
Controls highlighting kinds that are disabled.
Definition: Config.h:156
IncludesPolicy UnusedIncludes
Definition: Config.h:110
struct clang::clangd::Config::@6 Completion
Configures code completion feature.
std::vector< std::string > FullyQualifiedNamespaces
Definition: Config.h:125
Config(Config &&)=default
struct clang::clangd::Config::@3 Index
Controls index behavior.
IncludesPolicy MissingIncludes
Definition: Config.h:111
std::vector< llvm::unique_function< void(std::vector< std::string > &) const > > Edits
Edits to apply to the compile command, in sequence.
Definition: Config.h:66
struct clang::clangd::Config::@7 Hover
Configures hover feature.
llvm::StringMap< std::string > CheckOptions
Definition: Config.h:106
Config & operator=(Config &&)=default
struct clang::clangd::Config::@4 Diagnostics
Controls warnings and errors when parsing code.
uint32_t TypeNameLimit
Definition: Config.h:151
std::vector< std::string > DisabledModifiers
Controls highlighting modifiers that are disabled.
Definition: Config.h:158
bool Enabled
If false, inlay hints are completely disabled.
Definition: Config.h:143
struct clang::clangd::Config::@8 InlayHints
static unsigned getHashValue(const ExternalIndexSpec &Val)
Definition: Config.h:174
static bool isEqual(const ExternalIndexSpec &LHS, const ExternalIndexSpec &RHS)
Definition: Config.h:177