File tree Expand file tree Collapse file tree 10 files changed +418
-90
lines changed Expand file tree Collapse file tree 10 files changed +418
-90
lines changed Original file line number Diff line number Diff line change @@ -523,6 +523,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
523
523
if (Opts.UseDirBasedCDB ) {
524
524
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts (TFS);
525
525
CDBOpts.CompileCommandsDir = Opts.CompileCommandsDir ;
526
+ CDBOpts.ContextProvider = Opts.ContextProvider ;
526
527
BaseCDB =
527
528
std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
528
529
BaseCDB = getQueryDriverDatabase (llvm::makeArrayRef (Opts.QueryDriverGlobs ),
Original file line number Diff line number Diff line change @@ -52,11 +52,19 @@ struct Config {
52
52
Config (Config &&) = default ;
53
53
Config &operator =(Config &&) = default ;
54
54
55
+ struct CDBSearchSpec {
56
+ enum { Ancestors, FixedDir, NoCDBSearch } Policy = Ancestors;
57
+ // Absolute, native slashes, no trailing slash.
58
+ llvm::Optional<std::string> FixedCDBPath;
59
+ };
60
+
55
61
// / Controls how the compile command for the current file is determined.
56
62
struct {
57
- // Edits to apply to the compile command, in sequence.
63
+ // / Edits to apply to the compile command, in sequence.
58
64
std::vector<llvm::unique_function<void (std::vector<std::string> &) const >>
59
65
Edits;
66
+ // / Where to search for compilation databases for this file's flags.
67
+ CDBSearchSpec CDBSearch = {CDBSearchSpec::Ancestors, llvm::None};
60
68
} CompileFlags;
61
69
62
70
enum class BackgroundPolicy { Build, Skip };
Original file line number Diff line number Diff line change @@ -263,6 +263,36 @@ struct FragmentCompiler {
263
263
});
264
264
});
265
265
}
266
+
267
+ if (F.CompilationDatabase ) {
268
+ llvm::Optional<Config::CDBSearchSpec> Spec;
269
+ if (**F.CompilationDatabase == " Ancestors" ) {
270
+ Spec.emplace ();
271
+ Spec->Policy = Config::CDBSearchSpec::Ancestors;
272
+ } else if (**F.CompilationDatabase == " None" ) {
273
+ Spec.emplace ();
274
+ Spec->Policy = Config::CDBSearchSpec::NoCDBSearch;
275
+ } else {
276
+ if (auto Path =
277
+ makeAbsolute (*F.CompilationDatabase , " CompilationDatabase" ,
278
+ llvm::sys::path::Style::native)) {
279
+ // Drop trailing slash to put the path in canonical form.
280
+ // Should makeAbsolute do this?
281
+ llvm::StringRef Rel = llvm::sys::path::relative_path (*Path);
282
+ if (!Rel.empty () && llvm::sys::path::is_separator (Rel.back ()))
283
+ Path->pop_back ();
284
+
285
+ Spec.emplace ();
286
+ Spec->Policy = Config::CDBSearchSpec::FixedDir;
287
+ Spec->FixedCDBPath = std::move (Path);
288
+ }
289
+ }
290
+ if (Spec)
291
+ Out.Apply .push_back (
292
+ [Spec (std::move (*Spec))](const Params &, Config &C) {
293
+ C.CompileFlags .CDBSearch = Spec;
294
+ });
295
+ }
266
296
}
267
297
268
298
void compile (Fragment::IndexBlock &&F) {
Original file line number Diff line number Diff line change @@ -151,6 +151,13 @@ struct Fragment {
151
151
// /
152
152
// / Flags added by the same CompileFlags entry will not be removed.
153
153
std::vector<Located<std::string>> Remove;
154
+
155
+ // / Directory to search for compilation database (compile_comands.json etc).
156
+ // / Valid values are:
157
+ // / - A single path to a directory (absolute, or relative to the fragment)
158
+ // / - Ancestors: search all parent directories (the default)
159
+ // / - None: do not use a compilation database, just default flags.
160
+ llvm::Optional<Located<std::string>> CompilationDatabase;
154
161
};
155
162
CompileFlagsBlock CompileFlags;
156
163
Original file line number Diff line number Diff line change @@ -95,6 +95,9 @@ class Parser {
95
95
if (auto Values = scalarValues (N))
96
96
F.Remove = std::move (*Values);
97
97
});
98
+ Dict.handle (" CompilationDatabase" , [&](Node &N) {
99
+ F.CompilationDatabase = scalarValue (N, " CompilationDatabase" );
100
+ });
98
101
Dict.parse (N);
99
102
}
100
103
You can’t perform that action at this time.
0 commit comments