IntelliSense fails from sample code (for VSCode) #688
Description
Using your included sample for VSCode and a skeleton method to call it (in activate, as per your code), I get the following error when trying to hover or code-complete:
ERROR Handler for textDocument/hover failed: TypeError: Cannot read property 'ensureReferencedFiles' of undefined
After looking at your code I realized that that's .projectManager that's not set in the initialize() method (line 237 in typescript-service.ts). And this seems likely due that somehow params.rootUri and/or .rootPath are not set in that call. This is of course supposed to be set from vscode on the first call to the language server.
I have some questions:
- Is this code still supposed to work (or was it meant perhaps for an earlier version of lsp or vscode)?
- is that part of the code still being maintained/updated? (I ask because the latest updates are from 2019, and most from 1 or 2 years before that)
- Is there a param missing (e.g. in ClientOptions) that I'm suppose to set for the rootUri/.Path to be set explicitly?
- Is it supposed to use a lower version of typescript (tsserver)? I'm currently at v3.15 (client & server v6.0.0) and at least 1 other (unrelated) error was created because of this (a breaking change from microsoft's typescript language service)
Any help would be welcome. Thanks.
FYI: the vscode I'm using is as follows (vscode-insider on macos/catalina):
Version: 1.48.0-insider
Commit: e7920dce7bfd0b707ebfc0a5379c6edd2233e475
Date: 2020-07-10T11:55:11.286Z (1 day ago)
Electron: 8.3.3
Chrome: 80.0.3987.165
Node.js: 12.13.0
V8: 8.0.426.27-electron.0
OS: Darwin x64 19.5.0
For your info, here's the stub code method I've been using:
function FROM_SOURCE_GRAPH(vscContext) {
// FROM: https://github.com/sourcegraph/vscode-javascript-typescript/blob/master/src/extension.ts
const serverOptions = async () => { //: ServerOptions
log('spawning...');
try{
// DON'T FORGET TO FIRST: `npm install javascript-typescript-langserver`
const childProcess = spawn(process.execPath, [path.resolve(__dirname, 'node_modules', 'javascript-typescript-langserver', 'lib', 'language-server-stdio.js')]);
childProcess.stderr.on('data', (chunk) => { //: Buffer
log('err cp', chunk + '');
client.error(chunk + '');
});
log('spawned!'); // this works
return childProcess;
}
catch(ex) {
log('NOT SPAWNED', ex);
}
};
const clientOptions = { // : LanguageClientOptions
revealOutputChannelOn: RevealOutputChannelOn.Never,
// Register the server for php documents
documentSelector: [{ scheme: 'file', language: 'rehtml'}],//['typescript', 'javascript', 'typescriptreact', 'javascriptreact'],
uriConverters: {
// VS Code by default %-encodes even the colon after the drive letter
// NodeJS handles it much better
code2Protocol: uri => url.format(url.parse(uri.toString(true))),
protocol2Code: str => vscode.Uri.parse(str)
},
completion: true,
};
// Create the language client and start the client.
let client = new LanguageClient(
'freddyLanguageServerExample',
'Freddy Language Server Examplex',
serverOptions,
clientOptions);
vscContext.subscriptions.push(client.start());
}