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

LSP client that doesn't support any workspace capabilities will cause an error if the server is using workspace/workspaceFolders #257

Closed
rcjsuen opened this issue Oct 5, 2017 · 1 comment

Comments

@rcjsuen
Copy link
Contributor

rcjsuen commented Oct 5, 2017

If you create your server with let connection = createConnection(ProposedFeatures.all); and use a client that connects to it with only very rudimentary capabilities, an error will be thrown.

function initialize(id: number) {
  send(id, "initialize", {
    rootPath: process.cwd(),
    processId: process.pid,
    capabilities: {
      textDocument: {
        completion: {
          completionItem: {
            snippetSupport: true
          }
        }
      }
    }
  });
}
{
  jsonrpc: '2.0',
  id: 1,
  error: {
    code: -32603,
    message: 'Request initialize failed with message: Cannot read property \'workspaceFolders\' of undefined'
  }
}

This is because workspaceFolders.proposed.ts incorrectly assumes that clientCapabilities.workspace is set.
https://github.com/Microsoft/vscode-languageserver-node/blob/9059f83cd8fb25b4a0fe5429540c562aa899dc6e/server/src/workspaceFolders.proposed.ts#L23-L24

However, according to the protocol, that capability is optional as it is flagged with a ?.

interface ClientCapabilities {
	/**
	 * Workspace specific client capabilities.
	 */
	workspace?: WorkspaceClientCapabilities;

	/**
	 * Text document specific client capabilities.
	 */
	textDocument?: TextDocumentClientCapabilities;

	/**
	 * Experimental client capabilities.
	 */
	experimental?: any;
}
@rcjsuen
Copy link
Contributor Author

rcjsuen commented Oct 6, 2017

You can reproduce the problem with the following two files.

$ node bug.js
{ jsonrpc: '2.0',
  id: 1,
  error:
   { code: -32603,
     message: 'Request initialize failed with message: Cannot read property \'workspaceFolders\' of undefined' } }

server.js

var langserv = require(".");
let connection = langserv.createConnection(langserv.ProposedFeatures.all);
connection.listen();

bug.js

var langserv = require(".");
var cp = require("child_process");

let lspProcess = cp.fork("server.js", ["--node-ipc"]);
function send(method, params) {
    let message = {
        jsonrpc: "2.0",
        id: 1,
        method: method,
        params: params
    };
    lspProcess.send(message);
}
function initialize() {
    send("initialize", {
        rootPath: process.cwd(),
        processId: process.pid,
        capabilities: {}
    });
}
lspProcess.on('message', function (json) {
    console.log(json);
});
initialize();

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant