microsoft / microsoft/language-server-protocol

Attach `TextDocumentEdit[]` to completion item

Open
#1,605 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

completion feature-request
Dominant language
TypeScript
Stars
13k
Forks
1k
Avg merge
6d 1h
Merged PRs (30d)
10

Description

Right now, the additionalTextEdits field on CompletionItem only allows providing a list of TextEdits that accepting the completion will add.

We have a use case where accepting a completion item needs to modify a separate file, not the file where the user is currently typing. TextEdit can only change the current file, while a TextDocumentEdit can change any file.

The use case is vaguely registering that the current "package" depends on another package. Some examples:

  • Concretely: I am working on Sorbet, a Ruby language server. Sorbet provides a custom notion of packages to encourage developers to be explicit about dependencies and module boundaries in a large Ruby monorepo. Package dependencies are specified in separate files, not using import statements at the top of the file.
  • Another idea: an LSP server wants to automatically add the relevant npm package to a user's package.json file which provides an import (or a relevant RubyGems package to a user's Gemfile)
  • Another: accepting a completion item changes a Bazel build file target to allow a dependency to be used from the current file.

etc. etc.

I have yet to begin an implementation, but our current recourse is to use the Command associated with a completion item to make these edits. Using Commands for this purpose is particularly heavy-weight, though, and it would be much easier if we could find a way to pass TextDocumentEdits back to the client directly.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with CompletionItem.additionalTextEdits and the TextEdit/TextDocumentEdit definitions described in the issue. Compare the requested cross-file completion behavior with the existing Command workaround and define a protocol shape that lets clients apply edits to another file. Done means the proposal specifies the behavior and its compatibility implications.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.