Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting value after executing command programmatically #329

Closed
starcev opened this issue Nov 2, 2017 · 7 comments
Closed

Getting value after executing command programmatically #329

starcev opened this issue Nov 2, 2017 · 7 comments
Labels
info-needed Issue requires more information from poster

Comments

@starcev
Copy link

starcev commented Nov 2, 2017

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?

@starcev starcev changed the title Getting value after executing command programmicly Getting value after executing command programmatically Nov 2, 2017
@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Nov 15, 2017
@dbaeumer
Copy link
Member

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

@starcev
Copy link
Author

starcev commented Nov 16, 2017

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.

@dbaeumer
Copy link
Member

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.

@starcev
Copy link
Author

starcev commented Nov 16, 2017

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.

@dbaeumer
Copy link
Member

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

@danixeee
Copy link

danixeee commented Nov 21, 2017

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.

@dbaeumer
Copy link
Member

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants