Skip to content

Commit 54899bc

Browse files
gselzerclaude
andcommitted
Offer jedi-language-server as a ServerProcessPlugin
code-lsp now runs server processes from ServerProcessPlugins, replacing its launch package. JediLanguageServerSpec becomes JediServerProcessPlugin, a plugin that starts jedi-language-server in the tooling environment; ApposePythonLspServerPlugin, which offered the spec, is gone, and ApposePythonEnvironments gives just the tooling Python. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 35543a2 commit 54899bc

7 files changed

Lines changed: 43 additions & 90 deletions

File tree

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import org.scijava.plugins.scripting.appose.python._internal.BuildListener;
5454
import org.scijava.plugins.scripting.appose.python._internal.ResidentWorkerService;
5555
import org.scijava.plugins.scripting.appose.python.completion.DependencyOverlays;
56-
import org.scijava.plugins.scripting.appose.python.completion.JediLanguageServerSpec;
5756

5857
/**
5958
* Where Python scripts run via Appose, as their language servers need to
@@ -356,21 +355,17 @@ private static String findPython(final List<File> dirs) {
356355
}
357356

358357
/**
359-
* How to start jedi-language-server: with the Python of the tooling
360-
* environment, built first if needed (but starting no worker).
358+
* Gets the Python of the tooling environment, in which jedi-language-server
359+
* runs (see {@link JediServerProcessPlugin}): built first if needed (but
360+
* starting no worker).
361361
*/
362-
static JediLanguageServerSpec serverSpec(
363-
final ResidentWorkerService workers)
362+
static String toolingPython(final ResidentWorkerService workers)
363+
throws Exception
364364
{
365-
final File envs = new File(Environments.apposeEnvsDir());
366-
return new JediLanguageServerSpec(() -> {
367-
final String python = pythonExecutable(toolingWorker(workers)
368-
.environment().get());
369-
if (python == null) throw new IOException("No Python in " +
370-
TOOLING_ENV);
371-
return python;
372-
}, new File(envs, TOOLING_ENV + "-workspace"), new File(envs, TOOLING_ENV +
373-
"-server.log"));
365+
final String python = pythonExecutable(toolingWorker(workers).environment()
366+
.get());
367+
if (python == null) throw new IOException("No Python in " + TOOLING_ENV);
368+
return python;
374369
}
375370

376371
/** Gets the tooling environment's worker, building it first if needed. */

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

Lines changed: 0 additions & 60 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
/**
4646
* Offers the language server of Python scripts run via Appose (see
4747
* {@link ApposePythonLanguageServer}): the syntax-only server, and, if offered
48-
* (see {@link ApposePythonLspServerPlugin}), jedi-language-server: members of
48+
* (see {@link JediServerProcessPlugin}), jedi-language-server: members of
4949
* objects and modules, signatures, documentation, hover and syntax errors.
5050
* Once a script's environment is built (by running the script), jedi
5151
* analyzes the script against it, so its packages are known; packages the

src/main/java/org/scijava/plugins/scripting/appose/python/completion/JediLanguageServerSpec.java renamed to src/main/java/org/scijava/plugins/scripting/appose/python/JediServerProcessPlugin.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,32 @@
2727
* #L%
2828
*/
2929

30-
package org.scijava.plugins.scripting.appose.python.completion;
30+
package org.scijava.plugins.scripting.appose.python;
3131

3232
import java.io.File;
3333
import java.io.IOException;
3434
import java.util.LinkedHashMap;
3535
import java.util.Map;
3636
import java.util.concurrent.Callable;
3737

38+
import org.apposed.appose.util.Environments;
3839
import org.scijava.code.lsp.Environment;
39-
import org.scijava.code.lsp.launch.LspConnection;
40-
import org.scijava.code.lsp.launch.LspServerSpec;
40+
import org.scijava.code.lsp.ServerProcessPlugin;
41+
import org.scijava.plugin.Parameter;
42+
import org.scijava.plugin.Plugin;
43+
import org.scijava.plugins.scripting.appose.python._internal.ResidentWorkerService;
4144

4245
/**
43-
* Starts jedi-language-server, with the Python of a tooling environment, to
44-
* analyze scripts against their environment's Python (if known) and extra
45-
* search paths (e.g. a dependency overlay).
46+
* Offers jedi-language-server, for {@code python}: run with the Python of a
47+
* tooling environment (see {@link ApposePythonEnvironments}), to analyze
48+
* scripts against their environment's Python (if known) and extra search
49+
* paths (e.g. a dependency overlay). Python scripts run via Appose use it,
50+
* and so do Jython's.
4651
*
4752
* @author Gabriel Selzer
4853
*/
49-
public class JediLanguageServerSpec implements LspServerSpec {
54+
@Plugin(type = ServerProcessPlugin.class, name = "jedi-language-server")
55+
public class JediServerProcessPlugin implements ServerProcessPlugin {
5056

5157
/**
5258
* Runs jedi-language-server, exiting once the given process (this JVM) is
@@ -72,18 +78,30 @@ public class JediLanguageServerSpec implements LspServerSpec {
7278
/** How large the error log may grow before it is started anew, in bytes. */
7379
private static final long MAX_LOG = 5 * 1024 * 1024;
7480

81+
@Parameter
82+
private ResidentWorkerService workers;
83+
7584
private final Callable<String> python;
7685
private final File workspace;
7786
private final File log;
7887

88+
/** Runs the server in the tooling environment, building it if needed. */
89+
public JediServerProcessPlugin() {
90+
final File envs = new File(Environments.apposeEnvsDir());
91+
python = () -> ApposePythonEnvironments.toolingPython(workers);
92+
workspace = new File(envs, ApposePythonEnvironments.TOOLING_ENV +
93+
"-workspace");
94+
log = new File(envs, ApposePythonEnvironments.TOOLING_ENV + "-server.log");
95+
}
96+
7997
/**
8098
* @param python Gets the Python executable of the environment
8199
* jedi-language-server is installed in (building it, if needed).
82100
* @param workspace An (empty) directory to serve as workspace root.
83101
* @param log Where to append the server's error output.
84102
*/
85-
public JediLanguageServerSpec(final Callable<String> python,
86-
final File workspace, final File log)
103+
JediServerProcessPlugin(final Callable<String> python, final File workspace,
104+
final File log)
87105
{
88106
this.python = python;
89107
this.workspace = workspace;
@@ -96,7 +114,7 @@ public String languageId() {
96114
}
97115

98116
@Override
99-
public LspConnection start(final Environment env)
117+
public Process start(final Environment env)
100118
throws IOException
101119
{
102120
final String exe;
@@ -116,7 +134,7 @@ public LspConnection start(final Environment env)
116134
final ProcessBuilder pb = new ProcessBuilder(exe, "-c", LAUNCHER, String
117135
.valueOf(ProcessHandle.current().pid()));
118136
pb.redirectError(ProcessBuilder.Redirect.appendTo(log));
119-
return LspConnection.of(pb.start());
137+
return pb.start();
120138
}
121139

122140
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
* <p>
5454
* This needs no Python, so it works instantly, before (or without) any Appose
5555
* environment. It knows nothing of types, though: members of objects come
56-
* from the language server (see {@link org.scijava.code.lsp.PythonLspClient}).
56+
* from jedi-language-server (see
57+
* {@link org.scijava.plugins.scripting.appose.python.ApposePythonLanguageServer}).
5758
* </p>
5859
*
5960
* @author Gabriel Selzer

‎src/test/java/org/scijava/plugins/scripting/appose/python/ApposePythonCompletionIntegrationTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void testServerOutlivesNoParent() throws Exception {
212212
final Process gone = new ProcessBuilder(python, "-c", "pass").start();
213213
gone.waitFor();
214214
final Process process = new ProcessBuilder(python, "-c",
215-
org.scijava.plugins.scripting.appose.python.completion.JediLanguageServerSpec.LAUNCHER,
215+
JediServerProcessPlugin.LAUNCHER,
216216
String.valueOf(gone.pid())).redirectErrorStream(true).start();
217217
final boolean exited = process.waitFor(30, TimeUnit.SECONDS);
218218
if (!exited) process.destroyForcibly();

‎src/test/java/org/scijava/plugins/scripting/appose/python/ApposePythonServersTest.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import org.scijava.plugins.scripting.appose.python._internal.ResidentWorkerService;
5959
import org.scijava.plugins.scripting.appose.python.completion.ApposePythonDialect;
6060
import org.scijava.plugins.scripting.appose.python.completion.DependencyOverlays;
61-
import org.scijava.plugins.scripting.appose.python.completion.JediLanguageServerSpec;
6261
import org.scijava.script.ScriptLanguage;
6362
import org.scijava.script.ScriptService;
6463

@@ -293,7 +292,7 @@ public void testPythonTypes() {
293292

294293
@Test
295294
public void testServerOptions() {
296-
final JediLanguageServerSpec spec = new JediLanguageServerSpec(() -> null,
295+
final JediServerProcessPlugin spec = new JediServerProcessPlugin(() -> null,
297296
new File("workspace"), new File("server.log"));
298297
assertEquals("python", spec.languageId());
299298
final String diagnostics = "diagnostics={enable=true, didOpen=true, " +

0 commit comments

Comments
 (0)