-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Add --project-root to clangd #155905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add --project-root to clangd #155905
Changes from all commits
9a30c2b
1c040db
e80072c
267071c
d0b4357
82f80c0
03b26a6
f824d5d
220b823
a21f748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,8 @@ struct ProjectInfo { | |
| /// Provides compilation arguments used for parsing C and C++ files. | ||
| class GlobalCompilationDatabase { | ||
| public: | ||
| GlobalCompilationDatabase(std::optional<std::string> WorkingDirectory) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would give this parameter a default to minimize the disruption caused by this change. (I'm not just talking about test code in this repo; I think this class has out-of-tree subclasses as well.) |
||
| : WorkingDirectory(WorkingDirectory) {} | ||
| virtual ~GlobalCompilationDatabase() = default; | ||
|
|
||
| /// If there are any known-good commands for building this file, returns one. | ||
|
|
@@ -69,14 +71,17 @@ class GlobalCompilationDatabase { | |
| } | ||
|
|
||
| protected: | ||
| std::optional<std::string> WorkingDirectory; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this only applies to fallback commands, let's call it |
||
| mutable CommandChanged OnCommandChanged; | ||
| }; | ||
|
|
||
| // Helper class for implementing GlobalCompilationDatabases that wrap others. | ||
| class DelegatingCDB : public GlobalCompilationDatabase { | ||
| public: | ||
| DelegatingCDB(const GlobalCompilationDatabase *Base); | ||
| DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base); | ||
| DelegatingCDB(const GlobalCompilationDatabase *Base, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise here, we may want to give these added parameters a default |
||
| std::optional<std::string> WorkingDirectory); | ||
| DelegatingCDB(std::unique_ptr<GlobalCompilationDatabase> Base, | ||
| std::optional<std::string> WorkingDirectory); | ||
|
|
||
| std::optional<tooling::CompileCommand> | ||
| getCompileCommand(PathRef File) const override; | ||
|
|
@@ -117,6 +122,12 @@ class DirectoryBasedGlobalCompilationDatabase | |
| // Only look for a compilation database in this one fixed directory. | ||
| // FIXME: fold this into config/context mechanism. | ||
| std::optional<Path> CompileCommandsDir; | ||
| // Working directory for fallback commands | ||
| // If unset, parent directory of file should be used | ||
| std::optional<std::string> WorkingDirectory; | ||
|
|
||
| void | ||
| applyWorkingDirectory(const std::optional<std::string> &&WorkingDirectory); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the purpose of using |
||
| }; | ||
|
|
||
| DirectoryBasedGlobalCompilationDatabase(const Options &Opts); | ||
|
|
@@ -196,7 +207,8 @@ class OverlayCDB : public DelegatingCDB { | |
| // Adjuster is applied to all commands, fallback or not. | ||
| OverlayCDB(const GlobalCompilationDatabase *Base, | ||
| std::vector<std::string> FallbackFlags = {}, | ||
| CommandMangler Mangler = nullptr); | ||
| CommandMangler Mangler = nullptr, | ||
| std::optional<std::string> WorkingDirectory = std::nullopt); | ||
|
|
||
| std::optional<tooling::CompileCommand> | ||
| getCompileCommand(PathRef File) const override; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -236,6 +236,8 @@ class TUScheduler { | |
| /// Typically to inject per-file configuration. | ||
| /// If the path is empty, context sholud be "generic". | ||
| std::function<Context(PathRef)> ContextProvider; | ||
|
|
||
| bool test; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftover debug code? |
||
| }; | ||
|
|
||
| TUScheduler(const GlobalCompilationDatabase &CDB, const Options &Opts, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,6 +500,16 @@ opt<bool> EnableConfig{ | |
| init(true), | ||
| }; | ||
|
|
||
| opt<bool> StrongWorkspaceMode{ | ||
| "strong-workspace-mode", | ||
| cat(Features), | ||
| desc("An alternate mode of operation for clangd, operating more closely to " | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggested reword: "operating more closely to the workspace" --> "where the clangd instance is used to edit a single workspace". |
||
| "the workspace.\n" | ||
| "When enabled, fallback commands use the workspace directory as their " | ||
| "working directory instead of the parent folder."), | ||
| init(false), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this option hidden for now (example), until the feature is more fleshed out with other behaviours. (This just means it won't show up in |
||
| }; | ||
|
|
||
| opt<bool> UseDirtyHeaders{"use-dirty-headers", cat(Misc), | ||
| desc("Use files open in the editor when parsing " | ||
| "headers instead of reading from the disk"), | ||
|
|
@@ -907,6 +917,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var | |
| } | ||
| if (!ResourceDir.empty()) | ||
| Opts.ResourceDir = ResourceDir; | ||
| Opts.StrongWorkspaceMode = StrongWorkspaceMode; | ||
| Opts.BuildDynamicSymbolIndex = true; | ||
| #if CLANGD_ENABLE_REMOTE | ||
| if (RemoteIndexAddress.empty() != ProjectRoot.empty()) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth a comment explaining why we need a fallback here. Something like "the user asked for strong workspace mode, but the client didn't provide a workspace path, so use the working directory as a fallback".