Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

IntelliSense fails from sample code (for VSCode) #688

Open
frudman opened this issue Jul 11, 2020 · 0 comments
Open

IntelliSense fails from sample code (for VSCode) #688

frudman opened this issue Jul 11, 2020 · 0 comments

Comments

@frudman
Copy link

frudman commented Jul 11, 2020

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:

  1. Is this code still supposed to work (or was it meant perhaps for an earlier version of lsp or vscode)?
  2. 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)
  3. Is there a param missing (e.g. in ClientOptions) that I'm suppose to set for the rootUri/.Path to be set explicitly?
  4. 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());
}
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