Skip to content

Commit 0fc15fc

Browse files
gselzerclaude
andcommitted
Combine jedi and the syntax-only server in one server
code-lsp no longer merges several plugins' servers, nor moves scripts between them. ApposePythonServerPlugin now offers one server, ApposePythonLanguageServer: jedi's completions first, then the syntax server's for other names; jedi's signatures, hover and problems, else the syntax server's. It moves each script to a jedi of where it runs as that changes (as its metadata is edited, or its environment is built). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c1be7b6 commit 0fc15fc

10 files changed

Lines changed: 958 additions & 111 deletions

‎README.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,20 @@ script's own line numbers.
137137

138138
## Code completion
139139

140-
The Script Editor completes code in these scripts with two language servers,
141-
which `scijava-code-lsp`'s `LanguageServerService` merges into one (so any
142-
other LSP client of it gets the same):
140+
The Script Editor completes code in these scripts with one language server
141+
(`ApposePythonLanguageServer`, offered to `scijava-code-lsp`'s
142+
`LanguageServerService` by `ApposePythonServerPlugin`, so any other LSP client
143+
of it gets the same), combining two sources: jedi's answers first, then the
144+
syntax-only ones for names jedi has not completed.
143145

144146
* **Instantly, with no Python needed:** names in scope (variables,
145147
functions, classes, imports, parameters of the enclosing function), the
146148
script's `#@` parameters, `task`, builtins and keywords. This comes from
147149
parsing the script with [tree-sitter](https://tree-sitter.github.io/)
148-
(`PythonSyntaxServerPlugin`).
150+
(`PythonSyntaxLanguageServer`).
149151
* **With a language server,
150152
[jedi-language-server](https://github.com/pappasam/jedi-language-server)
151-
(built on [Jedi](https://jedi.readthedocs.io/)), via `JediServerPlugin`:**
153+
(built on [Jedi](https://jedi.readthedocs.io/)):**
152154
members of objects and modules, function signatures (with parameter names
153155
and types), documentation, hover and syntax errors. The server runs in a small environment of its own
154156
(`appose-python-completion`: Python, jedi-language-server, Appose and uv),

‎src/main/java/org/scijava/plugins/scripting/appose/python/ApposePythonEnvironments.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.List;
4343
import java.util.Map;
4444
import java.util.WeakHashMap;
45+
import java.util.concurrent.CopyOnWriteArrayList;
4546

4647
import org.apposed.appose.Appose;
4748
import org.apposed.appose.Environment;
@@ -100,7 +101,7 @@ protected boolean removeEldestEntry(
100101
private DependencyOverlays overlays;
101102

102103
/** Told when where scripts run may have changed. */
103-
private volatile Runnable onChange = () -> {};
104+
private final List<Runnable> listeners = new CopyOnWriteArrayList<>();
104105

105106
private ApposePythonEnvironments(final ResidentWorkerService workers) {
106107
this.workers = workers;
@@ -140,15 +141,19 @@ org.scijava.code.lsp.Environment environment(final String text,
140141
}
141142

142143
/**
143-
* Sets what to do when where scripts run may have changed without them
144+
* Adds what to do when where scripts run may have changed without them
144145
* changing: when an environment is built, or an overlay is ready.
145146
*/
146-
void onChange(final Runnable onChange) {
147-
this.onChange = onChange == null ? () -> {} : onChange;
147+
void addListener(final Runnable listener) {
148+
listeners.add(listener);
149+
}
150+
151+
void removeListener(final Runnable listener) {
152+
listeners.remove(listener);
148153
}
149154

150155
private void changed() {
151-
onChange.run();
156+
for (final Runnable listener : listeners) listener.run();
152157
}
153158

154159
/** Sets the dependency overlays, e.g. to use fake ones in tests. */

0 commit comments

Comments
 (0)