Skip to content

feat: add textDocument/_vs_onAutoInsert handler for VS closing tag auto-insertion#3436

Open
lucygramley wants to merge 12 commits intomicrosoft:mainfrom
lucygramley:fix/closing-tag-completion-textedit
Open

feat: add textDocument/_vs_onAutoInsert handler for VS closing tag auto-insertion#3436
lucygramley wants to merge 12 commits intomicrosoft:mainfrom
lucygramley:fix/closing-tag-completion-textedit

Conversation

@lucygramley
Copy link
Copy Markdown

Implement the VS-specific _vs_onAutoInsert LSP method so that closing HTML/JSX tags are automatically inserted and properly mapped when typing '>' in Visual Studio.

  • Add VsOnAutoInsertOptions, VsOnAutoInsertParams, and VsOnAutoInsertResponseItem protocol types with correct vs prefixed JSON field names matching VS LSP client expectations
  • Register _vs_onAutoInsertProvider server capability with _vs_triggerCharacters
  • Add handler that delegates to existing ProvideClosingTagCompletion
  • Fix jsonName bug in code generator unmarshal switch case

Copilot AI review requested due to automatic review settings April 17, 2026 22:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Visual Studio–specific support for automatic closing-tag insertion via the textDocument/_vs_onAutoInsert LSP request, integrating it with the existing JSX closing-tag completion logic and updating lsproto codegen to support overridden JSON field names.

Changes:

  • Register and implement textDocument/_vs_onAutoInsert request handling in the LSP server and advertise the _vs_onAutoInsertProvider capability with _vs_triggerCharacters.
  • Extend lsproto with VS-specific protocol types and _vs_-prefixed JSON field mappings.
  • Update JSX closing-tag completion to provide VS-formatted snippet TextEdit data and enhance fourslash baseline range selection accordingly.
  • Fix lsproto code generator to respect per-property jsonName overrides in JSON tags and unmarshal switch cases.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/lsp/server.go Registers the new VS auto-insert request, advertises capability, and implements the handler delegating to closing-tag completion.
internal/lsp/lsproto/lsp_generated.go Adds new protocol capability/types/method wiring and VS-prefixed JSON fields in generated protocol code.
internal/lsp/lsproto/_generate/metaModelSchema.mts Extends the meta-model schema to allow a jsonName override per property.
internal/lsp/lsproto/_generate/generate.mts Implements jsonName support in generated tags/unmarshal logic and defines VS auto-insert/custom structure/request metadata.
internal/ls/jsxclosingtag.go Enriches closing-tag completion results with VS snippet TextEdit + format.
internal/fourslash/fourslash.go Updates closing-tag baseline range selection to prefer VS text-edit range when present.

Comment thread internal/lsp/server.go Outdated
Comment thread internal/lsp/server.go Outdated
Comment thread internal/lsp/lsproto/_generate/generate.mts
Comment thread internal/lsp/lsproto/_generate/metaModelSchema.mts Outdated
Comment thread internal/lsp/server.go Outdated
Comment thread internal/lsp/server.go Outdated
Comment thread internal/ls/jsxclosingtag.go Outdated
Comment thread internal/lsp/lsproto/_generate/generate.mts Outdated
@jakebailey
Copy link
Copy Markdown
Member

There's a lot of overlap between this code and what's in _extension/src/languageFeatures/tagClosing.ts; that also construct snippets. It seems to me that we should be reconsidering how everything works and try and even it out instead of adding all new code.

…to-insertion

Implement the VS-specific _vs_onAutoInsert LSP method so that closing
HTML/JSX tags are automatically inserted when typing '>' in Visual Studio.

- Add VsOnAutoInsertOptions, VsOnAutoInsertParams, and
  VsOnAutoInsertResponseItem protocol types with correct _vs_ prefixed
  JSON field names matching VS LSP client expectations
- Register _vs_onAutoInsertProvider server capability with
  _vs_triggerCharacters
- Add handler that delegates to existing ProvideClosingTagCompletion
- Fix jsonName bug in code generator unmarshal switch case

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lucygramley lucygramley force-pushed the fix/closing-tag-completion-textedit branch from 30c5c6e to fb11b7e Compare April 20, 2026 23:40
lucygramley and others added 7 commits April 21, 2026 10:09
…ptional

- Only populate _vs_textEdit/_vs_textEditFormat when client is VS
- Mark VS fields as optional in generate.mts (omitted from JSON for non-VS clients)
- Extract buildClosingTagResponse helper to eliminate duplicated response construction
- Guard VS handler on VsTextEdit != nil for safety

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The goFieldName() helper already converts _vs_ prefixed names to proper
Go field names (e.g., _vs_textEdit -> VSTextEdit). Use property names
that match the JSON wire format directly instead of adding a separate
jsonName override. Also update hasTextDocumentURI/hasTextDocumentPosition
to detect _vs_ variants for accessor method generation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the VS auto-insert business logic from handleVsOnAutoInsert in
server.go into a new ProvideOnAutoInsert method in ls/jsxclosingtag.go.
This keeps server.go as a thin wrapper and consolidates closing tag
logic in one place, as ProvideOnAutoInsert delegates to the existing
ProvideClosingTagCompletion internally.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread internal/lsp/lsproto/_generate/generate.mts
@jakebailey
Copy link
Copy Markdown
Member

Pushed in some changes which serve to deduplicate this; now, VS Code uses the VS style API, which removes the duplication entirely. The code gets simpler from this.

I can see no difference in editor responsiveness; this is still way less chatty than completions.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread internal/ls/jsxclosingtag.go Outdated
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.

3 participants