7HR4IZ3 / acode-language-client

Acode language client plugin
7 stars 1 forks source link

Acode Language Client


Note This plugin is meant to replace Acode Language Servers plugin. Uninstall before installing this plugin

WARNING Please update your server to the npm version.

WARNING Please update your server to v1.0.6 or higher for this plugin to work properly.

Acode plugin that adds support for language servers.


Udate your server

To update the server from npm run

npm update -g acode-lsp

Supported Features


New in v1.0.4

New in v1.0.2


To setup server

To install the server from npm run

npm install -g acode-lsp

To run the server use

acode-ls

Supported Languages

The following programming languages are currently supported.

These are supported without starting the server.

The following requires the server to work.


Usage

This section explains how to use the plugin and the exposed api's for usage in other Acode plugins

Youtube tutorial: https://youtu.be/e8Ge4qBd--c?si=314bPpChORcFu4jT


Server

The server is an express websocket application where:

/python sets up a jsonrpc websocket connection to the python language server. /javascript sets up a jsonrpc websocket connection to the javascript language server etc.

If you cloned this repo, it comes with the server so just run:

cd acode-language-servers
npm install
node server/server.mjs

To install the server run the following command:

npm install -g acode-lsp

acode-ls

API

The plugin exposes the following api's to create language clients for Acode

Example of a acode typescript plugin that adds typescript language client abilities

class TypescriptPlugin {
  init() {

    // Method to ensure Acode Language Client is setup before continuing
    let acodeLanguageClient = acode.require("acode-language-client");
    if (acodeLanguageClient) {
      this.setupLangaugeClient(acodeLanguageClient);
    } else {
      window.addEventListener("plugin.install", ({ detail }) => {
        if (detail.name === "acode-language-client") {
          acodeLanguageClient = acode.require("acode-language-client");
          this.setupLangaugeClient(acodeLanguageClient);
        }
      });
    }
  }

  setupLangaugeClient(acodeLanguageClient) {
    // Get Socket for typescript language server
    let socket = acodeLanguageClient.getSocketForCommand(
      "typescript-language-server", ["--stdio"]
    );

    // Create client for server
    let typescriptClient = new acodeLanguageClient.LanguageClient({
      type: "socket", socket
    });

    // Register client to the editor
    acodeLanguageClient.registerService(
      "typescript|javascript|tsx|jsx",
      typescriptClient
    );
  }
}

if (window.acode) {
  const typescript = new TypescriptPlugin();
  acode.setPluginInit(
    plugin.id,
    (baseUrl, $page, { cacheFileUrl, cacheFile }) => {
      if (!baseUrl.endsWith("/")) baseUrl += "/";
      typescript.baseUrl = baseUrl;
      typescript.init($page, cacheFile, cacheFileUrl);
    }
  );
  acode.setPluginUnmount(plugin.id, () => {
    typescript.destroy();
  });
}

.getSocket(url: string)

The argument url must start with either server/ or auto/. If not use ReconnectingWebSocket instead of .getSocket

This function returns a ReconnectingWebsocket instance. Use server/<language> the language is in:

Else use auto/<command_to_run>?args=<command_args> to execute an already installed language server by command.


.getSocketForCommand(command: string, args: Array)

This function returns a ReconnectingWebsocket instance. It servers as a helper for using auto/<command> server path.


.registerService(mode: string, client: LanguageClient)

Registers a LanguageClient instance to the editor. The mode option refers to the language mode you want this client to be used for, you can seperate modes by using | e.g ("html|css|javascript")


.LanguageClient

This returns ace_linters.LanguageClient class which represents a language client connection

Properties

.ReconnectingWebsocket

This is a wrapper around WebSocket class but allows you to:

Properties

Running locally

To setup and run this plugin locally:


Contributing

Users can also add other language servers and send a pull request so they are added to the plugin.

For an example on how to do so, check out the html, typescript and svelte serverMode examples in server/server.js.

You can also use the python mode as an example on how to setup a websocket proxy if the target language server can only be started as a websocket server.

An example of a stdin and stdout language server would be added in future.