Skip to content

Latest commit

 

History

History

scijava-code-lsp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

SciJava Code LSP

Code intelligence for SciJava scripts (completions, signature help, hover and diagnostics), in the terms of the Language Server Protocol.

lsp4j supplies the protocol: its types, the LanguageServer and LanguageClient interfaces, and JSON-RPC over a pair of streams. This module is the client side that lsp4j leaves to its users (deciding which servers answer for a script, keeping them in sync with it, and starting server processes), plus what is particular to SciJava scripts.

 client (e.g. Script Editor)
   │  ScriptSession: a script's text, and offsets into it;
   │  shows its server the script as plain code (ScriptDocument)
   ▼
 LanguageServerService ──► the LanguageServerPlugin serving the language
   │  a server of the session's own, and its ScriptDialect
   ├──► in-process servers (e.g. Groovy, Jython), built on ScriptLanguageServer
   └──► server processes (e.g. jedi-language-server), via LspServerSpec

It does three things, each in a package of its own.

1. Brokering between scripts and servers (org.scijava.code.lsp)

The core. LanguageServerPlugins offer lsp4j LanguageServers for script languages; each language is served by the highest-priority plugin supporting it. A server combining several sources (e.g. Jython's own analysis and jedi's) combines them itself.

Clients ask about a script through a ScriptSession from the service, with a server of its own: it keeps the server's copy of the script up to date, names it (its file's URI, or an untitled: one), takes offsets into its text (see Positions), and reports the problems found in it. For code typed into a running interpreter, the server learns the interpreter's state through its Environment. Tools that ask once (e.g. to check a script) can call LanguageServerService.diagnose. For code typed into an interpreter whose language no plugin serves, a session completes the interpreter's variables.

Servers need know nothing of SciJava scripts. A SciJava script is not quite plain code of its language: its #@ parameters define variables before it runs. LanguageServerService.scriptParameters parses them; a ScriptDocument is the script as plain code, with them declared with their run-time types, as a ScriptDialect says. Each LanguageServerPlugin names the dialect its servers read; a session shows its server the script in that dialect, and maps positions in the server's answers back.

2. Running server processes (org.scijava.code.lsp.launch)

For servers that are not Java in the SciJava process (e.g. jedi-language-server, for Python). An LspServerPlugin offers an LspServerSpec for an LSP language id (e.g. python), saying how to start a server for an environment and returning its streams (an LspConnection). Plugins get such a server via LanguageServerService.launch: started when first needed, one per environment, restarted if it stops, and stopped when idle.

3. A toolkit for in-process servers (org.scijava.code.lsp.jvm)

For servers of JVM languages, written in Java (e.g. Groovy's and Jython's): ScriptLanguageServer, a base class keeping the open documents and turning requests into questions about a document and an offset; Members, completions for Java classes' members by reflection; Callable, something to call as a completion snippet; Signatures, rating overloads against the arguments typed; and ClassIndex, the classes on the classpath, with their javadoc.

Who uses what

1 2 3
script-editor ✓
scripting-groovy ✓ ✓
scripting-jython ✓ ✓ ✓
scripting-appose-python ✓ ✓

The specialized packages depend only on org.scijava.code.lsp, never on each other. The module exports all three; its implementation (org.scijava.code.lsp.impl) is internal.