FurqanSoftware / codemirror-languageserver

Language Server integration for CodeMirror 6
BSD 3-Clause "New" or "Revised" License
183 stars 24 forks source link

Fix and improved TypeScript types #18

Open marc2332 opened 2 years ago

marc2332 commented 2 years ago

Hey, I am playing with some changes to the API that would fix https://github.com/FurqanSoftware/codemirror-languageserver/issues/14 and make it slightly better.

Examples:

WebSockets transport

import { languageServer } from "codemirror-languageserver";

const lsPlugin = languageServer({
  serverUri, // WebSocket server uri.
  rootUri: "file:///",
  documentUri: `file:///${filename}`,
  languageId: "cpp", // As defined at https://microsoft.github.io/language-server-protocol/specification#textDocumentItem.
});

const view = new EditorView({
  state: EditorState.create({
    extensions: [
      // ...
      lsPlugin,
      // ...
    ],
  }),
});

Re using the same client

import { languageServer } from "codemirror-languageserver";

const client = new LanguageServerClient({
  transport: new WebSocketTransport(serverUri),
  rootUri: "file:///",
});

const firstView = new EditorView({
  state: EditorState.create({
    extensions: [
      // ...
      languageServerWithClient({
        client,
        documentUri: `file:///${secondFileName}`,
        languageId: "cpp",
      }),
      // ...
    ],
  }),
});

const secondView = new EditorView({
  state: EditorState.create({
    extensions: [
      // ...
      languageServerWithClient({
        client,
        documentUri: `file:///${firstFileName}`,
        languageId: "cpp",
      }),
      // ...
    ],
  }),
});

Custom transport

import { languageServer } from "codemirror-languageserver";

const client = new LanguageServerClient({
  transport: new AwesomeCustomTransport(),
  rootUri: "file:///",
});

const lsPlugin = languageServerWithClient({
  client,
  documentUri: `file:///${filename}`,
  languageId: "cpp",
});

const view = new EditorView({
  state: EditorState.create({
    extensions: [
      // ...
      lsPlugin,
      // ...
    ],
  }),
});

Thoughts?

hjr265 commented 2 years ago

@marc2332 Can we do this without removing languageServerWithTransport. The improvements suggested here are great. I just also want to make sure that the update won't require the users of this library to have to then "fix" their code.

We can mark languageServerWithTransport as deprecated, and then remove it eventually after a while.

How does that sound to you?

P.S: Sorry for taking so much time to get back to you.