Skip to content

Conversation

@mgoertz-msft
Copy link
Collaborator

Created OnAutoInsertFeature which supports static capability registration for C# and dynamic capability registration for XAML.

Fixes #7030 Support for dynamic OnAutoInsert capability registration

@mgoertz-msft mgoertz-msft requested a review from a team as a code owner April 9, 2024 15:19
@mgoertz-msft
Copy link
Collaborator Author

FYI @dibarbet

Copy link
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the changes!

import * as Is from 'vscode-languageclient/lib/common/utils/is';
import * as UUID from 'vscode-languageclient/lib/common/utils/uuid';

export class OnAutoInsertFeature implements DynamicFeature<RoslynProtocol.OnAutoInsertRegistrationOptions> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know this could be extended in this way. This is super useful!

}
}
dispose(): void {
this._registrations.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume VSCode calls this when the instance shuts down? We don't need to manually do anything right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation says this:

    /**
     * Called when the client is stopped to dispose this feature. Usually a feature
     * un-registers listeners registered hooked up with the VS Code extension host.
     */

That said, it didnt' actually get called on shutdown. Perhaps there's a different way to trigger this.

return undefined;
}

private *getDocumentSelectors(): IterableIterator<VDocumentSelector> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm learning so many new things in this PR...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too. I haven't really written any TypeScript before. :)

return undefined;
}
return (
Is.boolean(capability) && capability === true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doubtful but TextDocumentLanguageFeature does it like this so I kept it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is because there are a lot of capabilities that are either booleans or an object - https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#serverCapabilities

Since we control this end to end (and its never a boolean), I believe we should remove the boolean check

}
}
const registrations = count > 0;
return { kind: 'document', id: this.registrationType.method, registrations, matches: false };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering - could this implement DynamicDocumentFeature instead? Looks like it might already have this state management code
https://github.com/microsoft/vscode-languageserver-node/blob/54dd4abae40251a18fbe263285e6e97f27457e62/client/src/common/features.ts#L177

This is also probably outside ofthe scope of this PR, but it seems like most vscode features implement TextDocumentLanguageFeature, and then also have the implementation of the feature inside that type.
Wondering if that is something we can do here (instead of having a separate place where the implementation vs the capabilities happen).
e.g. https://github.com/microsoft/vscode-languageserver-node/blob/54dd4abae40251a18fbe263285e6e97f27457e62/client/src/common/hover.ts#L28

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did go down that road initially. However, I wasn't able to get all the way there because it started making hardcoded assumptions about the list of language features. For example, it requires a client that implements FeatureClient<Middleware, LanguageClientOptions> but MiddleWare is hardcoded to this: https://github.com/microsoft/vscode-languageserver-node/blob/54dd4abae40251a18fbe263285e6e97f27457e62/client/src/common/client.ts#L338

@mgoertz-msft
Copy link
Collaborator Author

@dibarbet Would you mind re-running the checks? Looks like some package downloads failed. Network issues?

@dibarbet
Copy link
Member

@dibarbet Would you mind re-running the checks? Looks like some package downloads failed. Network issues?

rerunning - this doesn't need the server side change to go in first, right?

@mgoertz-msft
Copy link
Collaborator Author

No, the server side change is really just for XAML. C# continues to use static registration, which still works with this change.

@dibarbet dibarbet merged commit e726f27 into dotnet:main Apr 17, 2024
@mgoertz-msft mgoertz-msft deleted the dev/mgoertz/autoinsert branch April 17, 2024 23:51
davidwengier added a commit to dotnet/razor that referenced this pull request May 7, 2025
Fixes #11822

Thanks to the awesome work of @mgoertz-msft and the sheer mind-blowing
PR that is dotnet/vscode-csharp#7033 Roslyn has
fully poly-filled OnAutoInsert support, so this PR is super easy.

I feel like I should buy a lottery ticket!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for dynamic OnAutoInsert capability registration

2 participants