GithubHelp home page GithubHelp logo

Comments (7)

jrieken avatar jrieken commented on May 18, 2024

@mtsmfm Can you provide some more context please? Is executeCommandProvider the name of your command. The error you point to happens when registering the same command twice.

from vscode-extension-samples.

mtsmfm avatar mtsmfm commented on May 18, 2024

@jrieken Sorry for being late.

I created an example extension to describe this problem:

https://github.com/Microsoft/vscode-extension-samples/compare/master...mtsmfm:command-with-multi-server?expand=1

Please try this extension with https://github.com/mtsmfm/example-workspace

This extension just inserts workspace folder name as a code action.
So it should insert file:///path/to/example-workspace/foo for foo/foo.txt and file:///path/to/example-workspace/bar for bar/bar.txt.
But I got file:///path/to/example-workspace/foo for bar/bar.txt.

vscode

from vscode-extension-samples.

mtsmfm avatar mtsmfm commented on May 18, 2024

I met command already exists error.

Actually, we can't notice this error normally because it's suppressed in this line:

https://github.com/Microsoft/vscode-languageserver-node/blob/020764e3eacc76138ffbf63f09489adbfb9e1be8/client/src/client.ts#L2546

from vscode-extension-samples.

mtsmfm avatar mtsmfm commented on May 18, 2024

@jrieken Isn't this explanation enough?

from vscode-extension-samples.

mtsmfm avatar mtsmfm commented on May 18, 2024

@jrieken I guess you're busy though, could you have a look at this?
I think this is a critical problem to provide commands/actions from multi-server.

from vscode-extension-samples.

nwolverson avatar nwolverson commented on May 18, 2024

I just ran into this, been using a multi-server LSP setup following the example here without realising the major limitation that it won't even initialize if it contains an executeCommandProvider. If it can't be resolved it could at least be listed as a limitation.

(My plan is to avoid executeCommandProvider and manually register/proxy commands to the appropriate LS server)

from vscode-extension-samples.

Tehnix avatar Tehnix commented on May 18, 2024

I think this should be related to this one.

What I've ended up doing is using a global clients: Map<string, LanguageClient> (as showed in the multi-server lsp example) and then I locate the correct client for when I have to launch commands. Something like,

async function registerHiePointCommand(name: string,
                                       command: string,
                                       context: ExtensionContext) {
  const editorCmd = commands.registerTextEditorCommand(name, (editor, edit) => {
    const cmd = {
      command,
      arguments: [
        {
          file: editor.document.uri.toString(),
          pos: editor.selections[0].active,
        },
      ],
    };
    // Get the current file and workspace folder.
    const uri = editor.document.uri;
    const folder = workspace.getWorkspaceFolder(uri);
    // If there is a client registered for this workspace, use that client.
    if (clients.has(folder.uri.toString())) {
      const client = clients.get(folder.uri.toString());
      client.sendRequest('workspace/executeCommand', cmd).then(hints => {
        return true;
      }, e => {
        console.error(e);
      });
    }
  });
  context.subscriptions.push(editorCmd);
}

It gets the current file, then looks up the workspace folder. It uses this folder.uri.toString() as the key for the language server.

Then to get rid of the command already exists, I simply check if commands have been registered, else I register them. E.g. a global let hieCommandsRegistered: boolean = false;, and then check if (!hieCommandsRegistered) { ...; hieCommandsRegistered = true; }.

from vscode-extension-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.