Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/sc-language-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: sc_language_server

on:
push:
branches: [ main, develop ]
paths:
- 'sc_language_server/**'
pull_request:
branches: [ main, develop ]
paths:
- 'sc_language_server/**'

jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: sc_language_server

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.dev.txt
- name: Run pytest
run: pytest
21 changes: 13 additions & 8 deletions LSP.sc
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,16 @@ LSPConnection {
prHandleResponse {
|id, result|

var response = (
id: id,
result: result ?? { NilResponse() }
);

this.prSendMessage(response);
// Don't sent empty messages as this produces response
// validation errors in some LSP clients (neovim).
if (id.notNil or: { result.notNil } ) {
var response = (
id: id,
result: result ?? { NilResponse() }
);

this.prSendMessage(response);
}
}

prHandleRequest {
Expand Down Expand Up @@ -347,7 +351,8 @@ LSPConnection {

prSendMessage {
|dict|
var maxSize = 6000;
// Reccomended max UDP packet size (probably doesn't matter so much if its localhost)
var maxSize = 508;
var offset = 0;
var packetSize;
var message = this.prEncodeMessage(dict);
Expand All @@ -359,7 +364,7 @@ LSPConnection {
socket.sendRaw(message);
} {
while { offset < messageSize } {
packetSize = min(messageSize, maxSize);
packetSize = min(messageSize - offset, maxSize);
socket.sendRaw(message[offset..(offset + packetSize - 1)]);
offset = offset + packetSize;
}
Expand Down
2 changes: 1 addition & 1 deletion LSPDatabase.sc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ LSPDatabase {
detail: LSPDatabase.methodArgString(method),
description: method.ownerClass.name.asString
),
kind: 1, // CompletionItemKind.Method
kind: 2, // CompletionItemKind.Method
// deprecated: false, // mark this as deprecated - no way to use this?
// detail: // @TODO: additional detail
// documentation: // @TODO: method documentation
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SuperCollider LanguageServer.Quark

A SuperCollider Language Server following the [LSP specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/).

## Setup

### vscode

For use with vscode please see the [vscode extension](https://github.com/scztt/vscode-supercollider).

### neovim / stdio

For use with neovim (or another editor that communicates with language servers over stdio), please see
[sc_language_server](sc_language_server/README.md).
160 changes: 160 additions & 0 deletions sc_language_server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
114 changes: 114 additions & 0 deletions sc_language_server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# sc-language-server

This python script is a stdio wrapper for the SuperCollider Language Server. Since the LSP Quark currently communicates
over UDP, this program exists to support LSP clients that support stdio, such as neovim.

See this github [issue](https://github.com/scztt/LanguageServer.quark/issues/9) for background info.

## Development

Create a new venv and install dependencies

python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.dev.txt

## User Installation

Download the Quark from within SuperCollider:

Quarks.install("https://github.com/scztt/LanguageServer.quark");
thisProcess.recompile;

After downloading/installing the LanguageServer Quark, locate the directory.

e.g. on MacOs this might be:

~/Library/Application\ Support/SuperCollider/downloaded-quarks/LanguageServer

Navigate to the sc_language_server directory within that:

cd sc_language_server


### Global installation

Install the python program to give your system the `sc-language-server` command. This allows you to simply specify
the `sc-language-server` command itself (plus any arguments) in your editor's LSP configuration rather than a full path to this directory.

Two options for this are:

#### Pip Install

Run:

python -m pip install .

This might not work with an externally managed installation (e.g. managed by homebrew). If that is the case, please try installing with [pipx](#using-pipx).

#### Using pipx

Follow the instructions to install [pipx](https://github.com/pypa/pipx), and then run:

`pipx install .`

### Post installation

Once installed, the command will be available globally, but you will need to set this up to be executed by your editor.

As an example see the setup for [Neovim](#neovim-lsp-configuration)

## Command-line Arguments

The script accepts the following command-line arguments:

- `--sclang-path`: Path to the SuperCollider language executable (sclang).
- Default: default value currently only provided for MacOS.

- `--config-path`: Path to the configuration file.
- Default: default value currently only provided for MacOS.
- Depending on how many Quarks your regular sclang config contains, it may be beneficial to point sc-language-server
to a minimal sclang config which only loads LanguageServer (and its dependencies).

- `--send-port`: Port number for sending data.
- Optional
- If not set (along with an unset --receive-port), a free port will be found.

- `--receive-port`: Port number for receiving data.
- Optional
- If not set (along with an unset --send-port), a free port will be found.

- `--ide-name`: Name of the IDE.
- NOTE: currently this must be set to 'vscode' (the default)

- `-v, --verbose`: Enable verbose output.

- `-l, --log-file`: Specify a log file to write output.
- Optional

## Neovim LSP Configuration

An example neovim lsp configuration:

```lua
local configs = require('lspconfig.configs')

configs.supercollider = {
default_config = {
cmd = {
"sc-language-server",
"--log-file",
"/tmp/sc_lsp_output.log",
"--verbose",
"--", -- indicates the args that follow are to be passed to sclang
"-u", "57300", -- e.g. custom UDP listening port for sclang
"-l", "/Users/me/sclang_conf_lsp.yaml", -- e.g. full path to config file
},
filetypes = {'supercollider'},
root_dir = function(fname)
return "/"
end,
settings = {},
},
}
```
14 changes: 14 additions & 0 deletions sc_language_server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "sc-language-server"
version = "0.1.0"
description = "A sdtio wrapper for the LanguageServer.quark LSP server for SuperCollider"
requires-python = ">= 3.9"

[project.scripts]
sc-language-server = "sc_language_server:main"

[tool.isort]
profile = 'black'

[tool.black]
line-length = 110
6 changes: 6 additions & 0 deletions sc_language_server/requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
black==23.9.1
mypy==1.5.1
flake8==6.1.0
isort==5.12.0
pytest==8.3.2
pytest-asyncio==0.24.0
Loading