Closed HighCommander4 closed 5 days ago
My personal opinion is to undertake the following:
client!
. This is bad form and could lead to other issueslanguageClient
can never be populated without a client, so we need to decide how to indicate this to the userI can see two approaches to the last situation:
languageClient
type optional or BaseLanguageClient | null
. This effectively changes the API and we should be good citizens and bump the API version (or is it really we are reflecting reality?)languageClient
and client
is undefined. This approach keeps the API and allows the user to catch and read an error why it failed. However I think the addition of a try..catch
complicates the API usage.My preference I think is to use the first option.
LMK if you want a PR.
- Make the
languageClient
type optional orBaseLanguageClient | null
.
+1
This effectively changes the API and we should be good citizens and bump the API version (or is it really we are reflecting reality?)
I think we can keep things simple and do it without bumping the API version; the API is unlikely to have a lot of consumers to break at this point.
LMK if you want a PR.
That would be great, thanks.
Opened #727. Quite a bit of churn removing the non-null assertions, though.
Opened #727. Quite a bit of churn removing the non-null assertions, though.
Indeed, it would be preferable to avoid having to check the client in so many places.
I wrote up a different approach at https://github.com/clangd/vscode-clangd/pull/728, perhaps you could have a look?
While reviewing #636, I realized that even though the extension's public API is specified to expose a non-null
BaseLanguageClient
object (rather thanBaseLanguageClient | null
), the value can in fact be null if the server binary cannot be found and this codepath is taken during plugin activation.(This technically shouldn't type-check, but it does because
ClangdContext.client
is declared asclient!: ClangdLanguageClient;
, which I guess overrides the type checker.)In #636, we are adding a second codepath where
client
can be null (the patch is adding a"clangd.enable"
setting that disables operation of the server if set to false).@thegecko do you have any thoughts on how the API should deal with this? Should we change the type of
ClangdApiV1.languageClient
toBaseLanguageClient | null
, to give API users a heads up that the value could be null? Or alternatively should we haveactivate()
returnClangdExtension | null
, where if we don't have a client we returnnull
there?