Acode language client plugin
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.
To update the server from npm run
npm update -g acode-lsp
To install the server from npm run
npm install -g acode-lsp
To run the server use
acode-ls
The following programming languages are currently supported.
These are supported without starting the server.
The following requires the server to work.
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
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
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/
orauto/
. If not useReconnectingWebSocket
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
constructor(config: object)
: This accepts a config object with possible keys
type: string
Can be one of (socket
, worker
)socket: WebSocket | ReconnectingWebsocket
: if type
option equalssocket
then this is required.worker: Worker
: if type
option equals worker
then this is required..connection
: This represents the connection object typically returned by
vscode-languageserver's
createConnection
method. Refer to the package to
learn more.
.ReconnectingWebsocket
This is a wrapper around WebSocket class but allows you to:
constructor(url: string, protocol: string, autoConnect: boolean, autoReconnect: boolean)
: The url
and protocol
option are passed to the WebSocket
class, autoConnect
refers to whether to connect to the server on creation or wait till a message is sent, defaults
to false
..connect()
: Connect to the server.close()
: Close connection to the server and don't try to reconnect..reconnect()
: Close connection if connected then connect to server.To setup and run this plugin locally:
git clone https://github.com/7HR4IZ3/acode-language-servers
)cd acode-language-servers
)npm install
src/main.js
e.g webpack (webpack build
)node server/server.js
)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.