microsoft / microsoft/language-server-protocol

Standardize LSP Command like 'references', 'implementations', 'triggetSuggest', 'openUri'

Open
#788 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

A lot of language server provides references and implementations CodeLens. As there are no standardization about those 2 commands, it causes extra code:

  • On server side, it requires that :

    • CodeLens creates a custom references and implementations command name (ex: java.show.references for jdt.ls)
    • This command name is generated only if client can support references (click on references CodeLens must open the client references dialog). For instance client send a custom capability (ex : supportReferences) in the InitializeParams.
  • On client side:

    • Client send a custom capability (ex : supportReferences) in the InitializeParams.
    • Client implement the custom command (ex: java.show.references for jdt.ls) to open the references dialog.

To avoid doing those extra code (on server and client side) and give the capability to have references and implementations which works directly (without implementing custom command on client side and without implementing custom capability on server side), we could standardize the 2 commands. The idea is to consume a language server in a client and click on references and implementations works directly without extra code.

The idea is to provide for instance CodeLensKind (or perhaps a CommandKind) like this:

export namespace CodeLensKind {

	export const References: CodeLensKind = 'references';

	export const Implementations: CodeLensKind = 'implementations';

}
  • The client will send a CodeKindKindCapabilities in the InitializeParams with (references and implementations for instance).
  • vscode could implement those 2 commands by sending references or implementations request to the server. The only requirement is that server must return a CodeLens with the standardized Command name (ex: references, or implementations) and an argument list with the URI document and position.

Here the vscode implementation for references:

context.subscriptions.push(commands.registerCommand(CodeLensKind .References, (uriString: string, position: Position) => {
        const uri = Uri.parse(uriString);
        workspace.openTextDocument(uri).then(document => {
          // Consume references service from the Language Server
          let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
          languageClient.sendRequest(ReferencesRequest.type, param).then(locations => {
            commands.executeCommand('editor.action.showReferences' uri, languageClient.protocol2CodeConverter.asPosition(position), locations.map(languageClient.protocol2CodeConverter.asLocation));
          })
        })
      }));
  • on server side, Codelens must be created with a Command whit name CodeLensKind.References (only if client support it) and with the uri and position and that's all!

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 by reviewing the proposed CodeLensKind or CommandKind values, the InitializeParams capability, and the references and implementations requests described in the issue. Compare the server CodeLens command arguments with the client command behavior; done means the protocol specifies standardized commands, capability negotiation, and interoperable client handling without custom commands.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
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.