All Projects → rcjsuen → Dockerfile Language Server Nodejs

rcjsuen / Dockerfile Language Server Nodejs

Licence: mit
A language server for Dockerfiles powered by Node.js, TypeScript, and VSCode technologies.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Dockerfile Language Server Nodejs

Monaco Languageclient
NPM module to connect Monaco editor with language servers
Stars: ✭ 419 (+146.47%)
Mutual labels:  lsp, language-server-protocol, language-server
toy-language-server
Example language server (LSP) implementation for a toy language
Stars: ✭ 54 (-68.24%)
Mutual labels:  language-server, language-server-protocol, lsp
groovy-language-server
A language server for Groovy
Stars: ✭ 132 (-22.35%)
Mutual labels:  language-server, language-server-protocol, lsp
Typescript Language Server
TypeScript & JavaScript Language Server
Stars: ✭ 462 (+171.76%)
Mutual labels:  lsp, language-server-protocol, language-server
Glsl Language Server
Language server implementation for GLSL
Stars: ✭ 53 (-68.82%)
Mutual labels:  lsp, language-server-protocol, language-server
Csharp Language Server Protocol
Language Server Protocol in C#
Stars: ✭ 230 (+35.29%)
Mutual labels:  lsp, language-server-protocol, language-server
atom-ide-scala
Scala & Dotty support for Atom IDE (🧟‍♂️ zombie repo)
Stars: ✭ 47 (-72.35%)
Mutual labels:  language-server, language-server-protocol, lsp
Fsautocomplete
F# language server using Language Server Protocol
Stars: ✭ 208 (+22.35%)
Mutual labels:  lsp, language-server-protocol, language-server
Erlang ls
The Erlang Language Server
Stars: ✭ 363 (+113.53%)
Mutual labels:  lsp, language-server-protocol, language-server
Elm Language Server
Language server implementation for Elm
Stars: ✭ 298 (+75.29%)
Mutual labels:  lsp, language-server-protocol, language-server
typescript-language-server
TypeScript & JavaScript Language Server
Stars: ✭ 1,118 (+557.65%)
Mutual labels:  language-server, language-server-protocol, lsp
Nvim Lspconfig
Quickstart configurations for the Nvim LSP client
Stars: ✭ 3,410 (+1905.88%)
Mutual labels:  lsp, language-server-protocol, language-server
camel-language-server
The Apache Camel LSP server implementation
Stars: ✭ 31 (-81.76%)
Mutual labels:  language-server, language-server-protocol, lsp
Protocol Buffers Language Server
[WIP] Protocol Buffers Language Server
Stars: ✭ 44 (-74.12%)
Mutual labels:  lsp, language-server-protocol, language-server
Elm Language Client Vscode
Improving your Elm experience since 2019
Stars: ✭ 162 (-4.71%)
Mutual labels:  lsp, language-server-protocol, language-server
Clojure Lsp
Language Server (LSP) for Clojure
Stars: ✭ 547 (+221.76%)
Mutual labels:  lsp, language-server
Kotlin Language Server
Intelligent Kotlin support for any editor/IDE using the Language Server Protocol
Stars: ✭ 650 (+282.35%)
Mutual labels:  lsp, language-server
Pylance Release
Documentation and issues for Pylance
Stars: ✭ 782 (+360%)
Mutual labels:  language-server-protocol, language-server
Python Language Server
Microsoft Language Server for Python
Stars: ✭ 778 (+357.65%)
Mutual labels:  language-server-protocol, language-server
Jupyterlab Lsp
Coding assistance for JupyterLab (code navigation + hover suggestions + linters + autocompletion + rename) using Language Server Protocol
Stars: ✭ 796 (+368.24%)
Mutual labels:  lsp, language-server-protocol

Dockerfile Language Server

Build Status Coverage Status Build Dependencies License: MIT

This is a language server for Dockerfiles powered by Node.js written in TypeScript. To install and run this language server, you will need to have either Node.js or Docker installed on your computer.

Supported features:

  • code actions
  • code completion
  • definition
  • diagnostics
  • document highlight
  • document links
  • document symbols
  • folding ranges
  • formatting
  • hovers
  • prepare rename
  • rename
  • semantic highlighting (experimental support for the upcoming LSP 3.16 specification)
  • signature help

Projects that use this language server:

This repository only contains the code necessary for launching a Dockerfile language server that conforms to the language server protocol. The actual code for parsing a Dockerfile and offering editor features such as code completion or hovers is not contained within this repository.

The code for analyzing and processing a Dockerfile is contained in the following three libraries:

All of the language server protocol requests that help create a rich editing experience for the user is forwarded to the dockerfile-language-service library. You can test its features right in the browser. This online editor is a very good representation of what is possible when this language server is connected to an editor that supports the language server protocol.

Development Instructions

If you wish to build and compile this language server, you must first install Node.js if you have not already done so. After you have installed Node.js and cloned the repository with Git, you may now proceed to build and compile the language server with the following commands:

npm install
npm run build
npm test

If you are planning to change the code, use npm run watch to get the TypeScript files transpiled on-the-fly as they are modified.

Once the code has finished compiling, you can connect a language server client to the server via Node IPC, stdio, or sockets.

Installation Instructions

To install this language server onto your computer, please install the dockerfile-language-server-nodejs npm module. The -g flag will install the npm module globally onto your computer.

npm install -g dockerfile-language-server-nodejs

After the installation has completed, you can start the language server with the docker-langserver binary. You should specify the desired method of communicating with the language server via one of the three arguments shown below.

docker-langserver --node-ipc
docker-langserver --stdio
docker-langserver --socket=<port>

Docker Image

The docker-langserver binary is also available as a Docker image under the name rcjsuen/docker-langserver.

Language Server Settings

Clients may send a workspace/didChangeConfiguration notification to notify the server of settings changes.

The settings object that will be included with the notification must conform to the following specification.

interface Settings {
  docker: {
    languageserver: {
      diagnostics?: {
        // string values must be equal to "ignore", "warning", or "error"
        deprecatedMaintainer?: string,
        directiveCasing?: string,
        emptyContinuationLine?: string,
        instructionCasing?: string,
        instructionCmdMultiple?: string,
        instructionEntrypointMultiple?: string,
        instructionHealthcheckMultiple?: string,
        instructionJSONInSingleQuotes?: string
      }
    }
  }
}

Communicating with the Server

Node IPC

With the child_process API, you can fork() a new Node.js process running the language server and communicate with it using send(message) and on('message', ...).

import * as child_process from "child_process";

let lspProcess = child_process.fork("out/src/server.js", [ "--node-ipc" ]);
let messageId = 1;

function send(method: string, params: object) {
    let message = {
        jsonrpc: "2.0",
        id: messageId++,
        method: method,
        params: params
    };
    lspProcess.send(message);
}

function initialize() {
    send("initialize", {
        rootPath: process.cwd(),
        processId: process.pid,
        capabilities: {
            /* ... */
        }
    });
}


lspProcess.on('message', function (json) {
    console.log(json);
});
initialize();

Standard Input/Output

When writing directly to the process's stdin, the additional Content-Length header must be included. Similarly, when reading from the process's stdout, the header will be included in the response message.

import * as child_process from "child_process";

let lspProcess = child_process.spawn("node", [ "out/src/server.js", "--stdio" ]);
let messageId = 1;

function send(method: string, params: object) {
    let message = {
        jsonrpc: "2.0",
        id: messageId++,
        method: method,
        params: params
    };
    let json = JSON.stringify(message);
    let headers = "Content-Length: " + json.length + "\r\n\r\n";
    lspProcess.stdin.write(headers, "ASCII");
    lspProcess.stdin.write(json, "UTF-8");
}

function initialize() {
    send("initialize", {
        rootPath: process.cwd(),
        processId: process.pid,
        capabilities: {
            /* ... */
        }
    });
}

lspProcess.stdout.on("data", (message) => {
    // "Content-Length: ...\r\n\r\n\" will be included here
    console.log(message.toString());
});

initialize();

vscode-jsonrpc

The StreamMessageReader and StreamMessageWriter classes from the vscode-jsonrpc module will handle the Content-Length headers for you so you only have to worry about the actual request and response.

import * as child_process from "child_process";
import { StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc";

let lspProcess = child_process.spawn("node", [ "out/src/server.js", "--stdio" ]);
let messageId = 1;

const reader = new StreamMessageReader(lspProcess.stdout);
const writer = new StreamMessageWriter(lspProcess.stdin);

function send(method: string, params: object) {
    let message = {
        jsonrpc: "2.0",
        id: messageId++,
        method: method,
        params: params
    };
    writer.write(message);
}

function initialize() {
    send("initialize", {
        rootPath: process.cwd(),
        processId: process.pid,
        capabilities: {
            /* ... */
        }
    });
}

reader.listen((data) => {
    console.log(data);
})

initialize();

Sockets

To communicate with the langauge server via a socket, a port must be opened up first to listen for incoming connections. After the port is opened, the language server may be started and told to connect to the specified port. Messages can then be read from and written to the socket.

Just like when trying to communicate to the server using stdio, the Content-Length headers must be written and parsed explicitly.

import * as net from "net"
import * as child_process from "child_process"

let messageId = 1;

function send(socket: net.Socket, method: string, params: object) {
    let message = {
        jsonrpc: "2.0",
        id: messageId++,
        method: method,
        params: params
    };
    let json = JSON.stringify(message) + "\n";
    let headers = "Content-Length: " + json.length + "\r\n\r\n";
    socket.write(headers, "ASCII");
    socket.write(json, "UTF-8");
}

function initialize(socket: net.Socket) {
    send(socket, "initialize", {
        rootPath: process.cwd(),
        processId: process.pid,
        capabilities: {
            textDocument: {
                /* ... */
            },
            workspace: {
                /* ... */
            }
        }
    });
}

const server = net.createServer((socket: net.Socket) => {
    server.close();
    socket.on("data", (message) => {
        // "Content-Length: ...\r\n\r\n\" will be included here
        console.log(message.toString());
    });
    initialize(socket);
});

server.listen(3000, () => {
    child_process.spawn("node", [ "out/src/server.js", "--socket=3000" ]);
});

vscode-jsonrpc

The SocketMessageReader and SocketMessageWriter classes from the vscode-jsonrpc module will handle the Content-Length headers for you so you only have to worry about the actual request and response.

import * as net from "net"
import * as child_process from "child_process"
import { SocketMessageReader, SocketMessageWriter } from "vscode-jsonrpc";

let messageId = 1;
let reader: SocketMessageReader = null;
let writer: SocketMessageWriter = null;

function send(method: string, params: object) {
    let message = {
        jsonrpc: "2.0",
        id: messageId++,
        method: method,
        params: params
    };
    writer.write(message);
}

function initialize() {
    send("initialize", {
        rootPath: process.cwd(),
        processId: process.pid,
        capabilities: {
            textDocument: {
                /* ... */
            },
            workspace: {
                /* ... */
            }
        }
    });
}

const server = net.createServer((socket: net.Socket) => {
    server.close();
    reader = new SocketMessageReader(socket);
    reader.listen((data) => {
        console.log(data);
    });
    writer = new SocketMessageWriter(socket);
    initialize();
});

server.listen(3000, () => {
    child_process.spawn("node", [ "out/src/server.js", "--socket=3000" ]);
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].