microsoft / language-server-protocol

Defines a common protocol for language servers.

Home Page:https://microsoft.github.io/language-server-protocol/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting value after executing command programmatically

starcev opened this issue · comments

I have registered specific commands both on server and client. I am trying to fetch values from lang server when command is executed, but instead value is undefined. Is it possible to do that?

Can you please provide an example of what you want to achieve?

I have defined command in package.json, for e.g.

"commands": [
            {
                "command": "my_cmd",
                "title": "My cmd"
            }
]
 

What I want is to call vscode.commands.executeCommand('my_cmd') and get result returned by language server that I also created.
I have tried something like this:

var returned = vscode.commands.executeCommand('my_cmd')
                        .then(function(result)
                        {
                               // do something with result
                        });

but the result is undefined. So, is that even possible?
Thank you for your response.

From where do you call the command. From the client or the server. Command execution from the server is currently not possible and would require to specify valid commands which is almost impossible given that a server should work with n clients.

I am calling the command from the client. And on the server I have a function which has a command name and arguments as function parameters. So, I can handle different commands and return different objects from the server.
The flow is something like this:
executeCommand - client => hit function - server => process and return value - server => fetch value - client
and the problem is that I can't fetch value.

Actually that should work. Have you registered the commands from the server using the ServerCapabilities.executeCommandProvider property.

Hello, I am working on the same extension. I have looked at source code of vscode-languageclient module and tried to log server's response.
I have replaced this part:

client.sendRequest(vscode_languageserver_protocol_1.ExecuteCommandRequest.type, params) .then(undefined, (error) => { ... });

with this:

client.sendRequest(vscode_languageserver_protocol_1.ExecuteCommandRequest.type, params) .then((result) => console.log(result) , (error) => { ... });

to be sure that server is returning a value. And it does.

Our activation function:

export function activate(context: ExtensionContext) {
	context.subscriptions.push(startLangServer('...', [], []))

        // be sure that server is running
        setTimeout(() => {
               vscode.commands.executeCommand('my_cmd')
                        .then((result)=>
                        {
                               console.log(result); // undefined
                        });
        },2000);
}

package.json has commands section described in above comment.
Do we need to register command programmatically, too?
Although, we tried that (and removed commands section) and result is still undefined.

@danixeee now I understand. We should continue the discussion in https://github.com/Microsoft/vscode-languageserver-node. In general this should work and it is not a specification problem. Looks more like a bug either in VS Code or in one of the LSP libraries.

Can you try to produce a minimal example using the LSP client and server module I can clone and open a new issue here: https://github.com/Microsoft/vscode-languageserver-node. Then I can definitely have a look and see why it is not working.