clang-tools  12.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 // vocubulary 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 <string>
30 #include <vector>
31 
32 namespace clang {
33 namespace clangd {
34 
35 /// Settings that express user/project preferences and control clangd behavior.
36 ///
37 /// Generally, features should consume Config::current() and the caller is
38 /// responsible for setting it appropriately. In practice these callers are
39 /// ClangdServer, TUScheduler, and BackgroundQueue.
40 struct Config {
41  /// Returns the Config of the current Context, or an empty configuration.
42  static const Config &current();
43  /// Context key which can be used to set the current Config.
45 
46  Config() = default;
47  Config(const Config &) = delete;
48  Config &operator=(const Config &) = delete;
49  Config(Config &&) = default;
50  Config &operator=(Config &&) = default;
51 
52  /// Controls how the compile command for the current file is determined.
53  struct {
54  // Edits to apply to the compile command, in sequence.
55  std::vector<llvm::unique_function<void(std::vector<std::string> &) const>>
57  } CompileFlags;
58 
59  enum class BackgroundPolicy { Build, Skip };
60  /// Controls background-index behavior.
61  struct {
62  /// Whether this TU should be indexed.
64  } Index;
65 };
66 
67 } // namespace clangd
68 } // namespace clang
69 
70 #endif
BackgroundPolicy Background
Whether this TU should be indexed.
Definition: Config.h:63
Values in a Context are indexed by typed keys.
Definition: Context.h:40
static clangd::Key< Config > Key
Context key which can be used to set the current Config.
Definition: Config.h:44
struct clang::clangd::Config::@1 Index
Controls background-index behavior.
std::vector< llvm::unique_function< void(std::vector< std::string > &) const > > Edits
Definition: Config.h:56
Settings that express user/project preferences and control clangd behavior.
Definition: Config.h:40
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Config & operator=(const Config &)=delete
static const Config & current()
Returns the Config of the current Context, or an empty configuration.
Definition: Config.cpp:17
struct clang::clangd::Config::@0 CompileFlags
Controls how the compile command for the current file is determined.