Skip to content

Commit d011a25

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 dcd5ebd commit d011a25

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
@@ -148,18 +148,20 @@ script's own line numbers.
148148

149149
## Code completion
150150

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

155157
* **Instantly, with no Python needed:** names in scope (variables,
156158
functions, classes, imports, parameters of the enclosing function), the
157159
script's `#@` parameters, `task`, builtins and keywords. This comes from
158160
parsing the script with [tree-sitter](https://tree-sitter.github.io/)
159-
(`PythonSyntaxServerPlugin`).
161+
(`PythonSyntaxLanguageServer`).
160162
* **With a language server,
161163
[jedi-language-server](https://github.com/pappasam/jedi-language-server)
162-
(built on [Jedi](https://jedi.readthedocs.io/)), via `JediServerPlugin`:**
164+
(built on [Jedi](https://jedi.readthedocs.io/)):**
163165
members of objects and modules, function signatures (with parameter names
164166
and types), documentation, hover and syntax errors. The server runs in a small environment of its own
165167
(`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)