Skip to content

Commit 155cf32

Browse files
committed
Update the language servers specs documentation
1 parent 557e67d commit 155cf32

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

CONTRIBUTING.md

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,44 +322,53 @@ python scripts/lint.py
322322

323323
### Specs
324324

325-
It is convenient to collect common patterns for connecting to installed language
326-
servers as `pip`-installable packages that Just Work with `jupyter-lsp`.
325+
While language servers can be configured by the user using a simple JSON or Python [configuration file](./Configuring.ipynb#language_servers),
326+
it is preferable to provide users with an option that does not require manual configuration. The language server specifications (specs)
327+
wrap the configuration (as would be defined by the user) into a Python class or function that can be either:
327328

328-
If an advanced user installs, locates, and configures, their own language
329-
server it will always win vs an auto-configured one.
329+
- distributed using PyPI/conda-forge and made conveniently available to users for `pip install` and/or `conda install`
330+
- contributed to the collection of built-in specs of jupyter-lsp by opening a PR (preferable for popular language servers, say >100 users)
330331

331-
#### Writing a spec
332-
333-
> See the built-in [specs][] for implementations and some [helpers][].
332+
> If an advanced user installs, locates, and configures, their own language server it will always win vs an auto-configured one.
334333
335-
[specs]: https://github.com/krassowski/jupyterlab-lsp/tree/master/python_packages/jupyter_lsp/jupyter_lsp/specs
336-
[helpers]: https://github.com/krassowski/jupyterlab-lsp/blob/master/python_packages/jupyter_lsp/jupyter_lsp/specs/utils.py
334+
#### Writing a spec
337335

338-
A spec is a python function that accepts a single argument, the
339-
`LanguageServerManager`, and returns a dictionary of the form:
336+
A spec is a Python callable (a function or class with `__call__` method) that accepts a single argument, the
337+
`LanguageServerManager` instance, and returns a dictionary of the form:
340338

341339
```python
342340
{
343341
"python-language-server": { # the name of the implementation
344-
"version": 1, # the version of the spec schema
342+
"version": SPEC_VERSION, # the version of the spec schema (an integer)
345343
"argv": ["python", "-m", "pyls"], # a list of command line arguments
346344
"languages": ["python"] # a list of languages it supports
347345
}
348346
}
349347
```
350348

351-
The absolute minimum listing requires `argv` (a list of shell tokens to launch
352-
the server) and `languages` (which languages to respond to), but many number of
353-
other options to enrich the user experience are available in the
354-
[schema][] and are exercised by the current `entry_points`-based [specs][].
349+
The above example is only intended as an illustration and not as an up-to-date guide.
350+
For details on the dictionary contents, see the [schema][] definition and [built-in specs][].
351+
Basic concepts (meaning of the `argv` and `languages` arguments) are also explained in the [configuration files](./Configuring.ipynb#language_servers) documentation.
355352

356-
[schema]: https://github.com/krassowski/jupyterlab-lsp/blob/master/python_packages/jupyter_lsp/jupyter_lsp/schema/schema.json
353+
When contributing a specification we recommend to make use of the helper classes and other [utilities][] that take care of the common use-cases:
354+
355+
- `ShellSpec` helps to create specs for servers that can be started from command-line
356+
- `PythonModuleSpec` is useful for servers which are Python modules
357+
- `NodeModuleSpec` will take care of finding Node.js modules
358+
359+
See the built-in [specs][] for example implementations.
357360

358361
The spec should only be advertised if the command _could actually_ be run:
359362

360-
- its runtime (e.g. `julia`, `nodejs`, `python`, `r`, `ruby`) is installed
363+
- its runtime/interpreter (e.g. `julia`, `nodejs`, `python`, `r`, `ruby`) is installed
361364
- the language server itself is installed (e.g. `python-language-server`)
362365

366+
otherwise an empty dictionary (`{}`) should be returned.
367+
368+
[built-in specs]: https://github.com/krassowski/jupyterlab-lsp/tree/master/python_packages/jupyter_lsp/jupyter_lsp/specs
369+
[schema]: https://github.com/krassowski/jupyterlab-lsp/blob/master/python_packages/jupyter_lsp/jupyter_lsp/schema/schema.json
370+
[utilities]: https://github.com/krassowski/jupyterlab-lsp/blob/master/python_packages/jupyter_lsp/jupyter_lsp/specs/utils.py
371+
363372
##### Common Concerns
364373

365374
- some language servers need to have their connection mode specified
@@ -369,8 +378,8 @@ The spec should only be advertised if the command _could actually_ be run:
369378
- `LanguageServerManager.nodejs` will provide the location of our best
370379
guess at where a user's `nodejs` might be found
371380
- some language servers are hard to start purely from the command line
372-
- use a helper script to encapsulate some complexity.
373-
- See the [r spec][] for an example
381+
- use a helper script to encapsulate some complexity, or
382+
- use a command argument of the interpreter is available (see the [r spec][] and julia spec for examples)
374383

375384
[r spec]: https://github.com/krassowski/jupyterlab-lsp/blob/master/python_packages/jupyter_lsp/jupyter_lsp/specs/r_languageserver.py
376385

docs/Language Servers.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"You can add another language server for languages that are not listed on this\n",
1717
"page:\n",
1818
"\n",
19-
"- using a minimal JSON-based\n",
19+
"- using a minimal JSON or Python\n",
2020
" [configuration file](./Configuring.ipynb#language_servers) (good for\n",
2121
" experimenting or configuring a niche server), or\n",
2222
"- contributing a [full specification](./Contributing.ipynb#Specs) (to enable\n",

0 commit comments

Comments
 (0)