0

I'm writing a vscode extension that should connect to tsserver in order to provide language support for typescript/javascript.

Here is how i'm doing it (in extension.ts, inside activate):

const serverModule = path.resolve(
  __dirname,
  "..",
  "node_modules",
  "typescript",
  "lib",
  "tsserver.js"
);

const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };

const serverOptions: ServerOptions = {
  run: { module: serverModule, transport: TransportKind.ipc },
  debug: {
    module: serverModule,
    transport: TransportKind.ipc,
    options: debugOptions,
  },
};

const clientOptions = {
  documentSelector: [
    {
      scheme: "file",
      language: "typescript",
    },
  ],
};

client = new LanguageClient(
  "server-id",
  "server-name",
  serverOptions,
  clientOptions
);

context.subscriptions.push(client.start());

But when I call client.onReady().then(() => client.sendRequest(...)); the request is not sent. I'm almost sure the problem is that the initialization phase is unsuccessful so the onReady() method is blocking me. How do I get it to work ?

Abdelhakim
  • 815
  • 1
  • 5
  • 19

1 Answers1

1

tsserver does not use the language server protocol, it has its own json based protocol. You cannot connect to it using the language server protocol apis

Matt Bierner
  • 58,117
  • 21
  • 175
  • 206
  • I tought tsserver was the default language server vscode uses to provide support for typescript/javascript. [Here](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29) it clearly says that tsserver is a standalone server that encapsulates typescript language services and is accessible with Json RPC. plus, I'm apparently able to connect to it using the command line interface (by just typing tsserver). May be you can better clarify your answer. – Abdelhakim May 29 '20 at 14:01
  • It doesn't use the language server protocol, it has its own json protocol – Matt Bierner May 29 '20 at 18:08
  • I am the maintainer of VS Code's TypeScript support. Also the [tsserver documentation](https://github.com/microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29) does not mention LSP and instead documents the protocol it uses – Matt Bierner May 30 '20 at 18:22