-
Notifications
You must be signed in to change notification settings - Fork 118
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
Add option to enable/disable clangd #636
Add option to enable/disable clangd #636
Conversation
@sam-mccall @hokein sorry to bother you, but could you or one of your associates take a quick look at this? It's pretty short :) |
I support the addition of this feature. In our organization we also use a mix between |
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.
Thanks for the patch, this looks like a reasonable change to me.
Needs a rebase.
src/clangd-context.ts
Outdated
@@ -66,6 +66,10 @@ export class ClangdContext implements vscode.Disposable { | |||
if (!clangdPath) | |||
return; | |||
|
|||
if (!config.get<boolean>('enable')) { |
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.
Any reason not to move the check even earlier (in particular before the install.activate
call, but maybe even at the top of the activate
function in extension.ts
, thereby avoiding the need for the added check there)?
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.
No reason except my lack of familiarity with the code. Thanks for the feedback! I'll give this a go.
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.
I tried this out and it's a bit more complicated than I expected. In extension.ts
I can't return early because activate
needs to return a ClangdExtension
so at least some of that code needs to run to create and configure the context used to create the ClangdExtensionImpl
. I think the safest simplification I can make that doesn't result in a half-initialized context is to do this in extension.ts
:
let shouldCheck = false;
if (!vscode.workspace.getConfiguration('clangd').get<boolean>('enable')) {
await clangdContext.activate(context.globalStoragePath, outputChannel);
shouldCheck = vscode.workspace.getConfiguration('clangd').get<boolean>(
'detectExtensionConflicts') ?? false;
}
if (shouldCheck) {
const interval = setInterval(function() {
...
Would you like me to make this change?
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.
This actually raises an interesting issue. The reason activate()
returns anything is that we expose an API for use by other extensions. So the question is: how should the API behave if clangd.enable
is set to false
.
With the current patch, it looks like we pass a null
client to ClangdExtension
. This is technically not permitted by the API, since the client object it exposes has type BaseLanguageClient
, not BaseLanguageClient | null
. However, it type-checks because we fudge the check on the nullness of ClangdContext.client
itself.
I guess we already have a codepath that can leave ClangdContext.client
as null, so adding another one is fine for now. But we should revisit this in a follow-up issue and consider changing the API to explicitly make the exposed client object nullable (or maybe allow a null ClangdExtension
return value for activate
itself).
TL;DR: Yes, please go ahead and make the described simplification.
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.
we should revisit this in a follow-up issue and consider changing the API to explicitly make the exposed client object nullable (or maybe allow a null
ClangdExtension
return value foractivate
itself).
I filed #721 about this.
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.
Thanks again for your help. I rebased, applied the simplified change, and re-tested this.
b9ad23b
to
70a165c
Compare
70a165c
to
ec98aea
Compare
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.
LGTM
Released in 0.1.30. |
I know that this could be done by disabling the extension for a given workspace, but that requires everyone working in the repository to do that via the VS Code GUI. This allows the extension to be disabled in the workspace settings which can be committed to the repo.
In our organization we're looking to transition from using
cpptools
toclangd
and having an easy way to have both extensions installed but only one enabled in a given workspace will be extremely helpful for us. We can already have a workspace that has been migrated toclangd
disable Intellisense viacpptools
, but there's no equivalent on theclangd
side that I was able to find. For workspaces that haven't been migrated,clangd
andcpptools
will conflict until theclangd
extension is disabled manually.