Skip to content

Commit

Permalink
Merge pull request #4 from dcermak/vscode-client
Browse files Browse the repository at this point in the history
Add a simple VSCode language client
  • Loading branch information
dcermak authored Nov 6, 2023
2 parents fb1772c + 6f690cc commit 6ac8362
Show file tree
Hide file tree
Showing 9 changed files with 1,758 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/vscode-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
name: build the vscode extension

on:
push:
branches:
- "main"
pull_request:

jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3.6.0
with:
node-version: ${{ matrix.node-version }}

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- uses: actions/cache@v3
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
-node-
- run: npm install
- run: npm run package

- uses: actions/upload-artifact@v3
if: ${{ matrix.node-version == '18.x' }}
with:
name: rpm-spec-language-server.vsix
path: rpm-spec-language-server-*.vsix
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist/
/node_modules/
/clients/vscode/out/
/rpm-spec-language-server-*.vsix
22 changes: 22 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.*
*~
*.lock
*.json
*.xml
*.vsix
**/*.ts
**/*.map
**/*.py
**/*.log
dist/**
clients/emacs/**
htmlcov/**
rpm_spec_language_server*/**
tests/**
pyproject.toml
**/__pycache__/*
.github/**
.vscode/**
.pytest_cache/**
source/**
build/**
133 changes: 133 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@ Requirements

- Python >= 3.11
- `poetry <https://python-poetry.org/>`_


Clients
=======


VSCode
------

A very simple VSCode client is available in ``clients/vscode/``. Building
requires nodejs and the :command:`npm` package manager:

.. code-block:: shell-session
$ npm install
$ npm run package
Install the created :file:`rpm-spec-language-server-$VERSION.vsix` and launch
the language server in tcp mode.
42 changes: 42 additions & 0 deletions clients/vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as net from "net";

import { LanguageClient, ServerOptions } from "vscode-languageclient/node";

function startLangServerTCP(addr: number): LanguageClient {
let clientSocket: net.Socket;

const serverOptions: ServerOptions = () => {
return new Promise((resolve) => {
clientSocket = new net.Socket();

clientSocket.connect(addr, "127.0.0.1", () => {
resolve({
reader: clientSocket,
writer: clientSocket,
});
});

clientSocket.on("close", () => {
setTimeout(() => {
clientSocket.connect(addr, "127.0.0.1");
}, 1000);
});
});
};

return new LanguageClient(`tcp lang server (port ${addr})`, serverOptions, {
documentSelector: [{ scheme: "file", language: "rpmspec" }],
outputChannelName: "[rpmspec_lsp] RPMSpecFileLanguageServer",
});
}

let client: LanguageClient;

export async function activate() {
client = startLangServerTCP(2087);
await client.start();
}

export function deactivate(): Thenable<void> {
return client ? client.stop() : Promise.resolve();
}
Loading

0 comments on commit 6ac8362

Please sign in to comment.