brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.4 KiB · 01997ce Raw
241 lines · c
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-exception6//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 contains12// 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 source19// of layering problems. Config should be expressed in terms of simple20// vocabulary types where possible.21//22//===----------------------------------------------------------------------===//23 24#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONFIG_H25#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CONFIG_H26 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 is42/// responsible for setting it appropriately. In practice these callers are43/// 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.48  static clangd::Key<Config> Key;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 56  struct CDBSearchSpec {57    enum { Ancestors, FixedDir, NoCDBSearch } Policy = Ancestors;58    // Absolute, native slashes, no trailing slash.59    std::optional<std::string> FixedCDBPath;60  };61 62  enum class BuiltinHeaderPolicy { Clangd, QueryDriver };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>>67        Edits;68    /// Where to search for compilation databases for this file's flags.69    CDBSearchSpec CDBSearch = {CDBSearchSpec::Ancestors, std::nullopt};70 71    /// Whether to use clangd's own builtin headers, or ones from the system72    /// include extractor, if available.73    BuiltinHeaderPolicy BuiltinHeaders = BuiltinHeaderPolicy::Clangd;74  } CompileFlags;75 76  enum class BackgroundPolicy { Build, Skip };77  /// Describes an external index configuration.78  struct ExternalIndexSpec {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, uses85    /// forward-slashes.86    std::string MountPoint;87  };88  /// Controls index behavior.89  struct {90    /// Whether this TU should be background-indexed.91    BackgroundPolicy Background = BackgroundPolicy::Build;92    ExternalIndexSpec External;93    bool StandardLibrary = true;94  } Index;95 96  enum class IncludesPolicy {97    /// Diagnose missing and unused includes.98    Strict,99    None,100  };101  enum class FastCheckPolicy { Strict, Loose, None };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;112      FastCheckPolicy FastCheckFilter = FastCheckPolicy::Strict;113    } ClangTidy;114 115    IncludesPolicy UnusedIncludes = IncludesPolicy::Strict;116    IncludesPolicy MissingIncludes = IncludesPolicy::None;117 118    struct {119      /// IncludeCleaner will not diagnose usages of these headers matched by120      /// these regexes.121      std::vector<std::function<bool(llvm::StringRef)>> IgnoreHeader;122      bool AnalyzeAngledIncludes = false;123    } Includes;124  } Diagnostics;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 leading130    // ::). 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;136  } Style;137 138  /// controls the completion options for argument lists.139  enum class ArgumentListsPolicy {140    /// nothing, no argument list and also NO Delimiters "()" or "<>".141    None,142    /// open, only opening delimiter "(" or "<".143    OpenDelimiter,144    /// empty pair of delimiters "()" or "<>".145    Delimiters,146    /// full name of both type and variable.147    FullPlaceholders,148  };149 150  enum class HeaderInsertionPolicy {151    IWYU,       // Include what you use152    NeverInsert // Never insert headers as part of code completion153  };154 155  enum class CodePatternsPolicy {156    All, // Suggest all code patterns and snippets157    None // Suggest none of the code patterns and snippets158  };159 160  /// Configures code completion feature.161  struct {162    /// Whether code completion includes results that are not visible in current163    /// scopes.164    bool AllScopes = true;165    /// controls the completion options for argument lists.166    ArgumentListsPolicy ArgumentLists = ArgumentListsPolicy::FullPlaceholders;167    /// Controls if headers should be inserted when completions are accepted168    HeaderInsertionPolicy HeaderInsertion = HeaderInsertionPolicy::IWYU;169    /// Enables code patterns & snippets suggestions170    CodePatternsPolicy CodePatterns = CodePatternsPolicy::All;171  } Completion;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;180  } Hover;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;194  } InlayHints;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;201  } SemanticTokens;202 203  enum class CommentFormatPolicy {204    /// Treat comments as plain text.205    PlainText,206    /// Treat comments as Markdown.207    Markdown,208    /// Treat comments as doxygen.209    Doxygen,210  };211 212  struct {213    CommentFormatPolicy CommentFormat = CommentFormatPolicy::PlainText;214  } Documentation;215};216 217} // namespace clangd218} // namespace clang219 220namespace llvm {221template <> struct DenseMapInfo<clang::clangd::Config::ExternalIndexSpec> {222  using ExternalIndexSpec = clang::clangd::Config::ExternalIndexSpec;223  static inline ExternalIndexSpec getEmptyKey() {224    return {ExternalIndexSpec::File, "", ""};225  }226  static inline ExternalIndexSpec getTombstoneKey() {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 llvm239 240#endif241