Skip to content

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

Open
@angelozerr

Description

@angelozerr

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions