Skip to content

Commit 2f89912

Browse files
gselzerclaude
andcommitted
code-lsp-jedi: follow code-lsp's sessions and environments
Also describes PythonLanguageServer anew. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ad1687b commit 2f89912

6 files changed

Lines changed: 20 additions & 14 deletions

File tree

‎code-lsp-jedi/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Context context = new Context(LanguageServerService.class);
3434
// (a) Start the server: the plugin offering "python", for scripts run by the
3535
// server's own Python (or, e.g., new Environment(python, paths, null)).
3636
LanguageServer server = context.service(LanguageServerService.class)
37-
.launch("python", Environment.NONE);
37+
.launch("python", new Environment());
3838
server.initialize(new InitializeParams()).get();
3939
server.initialized(new InitializedParams());
4040

‎code-lsp-jedi/src/main/java/org/scijava/code/lsp/jedi/JediLauncher.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ public Process start(final Environment env) throws IOException {
129129
public Object initializationOptions(final Environment env) {
130130
final Map<String, Object> workspaceOptions = new LinkedHashMap<>();
131131
// NB: Without an environment, Jedi uses the server's own Python.
132-
if (env.interpreter() != null) {
133-
workspaceOptions.put("environmentPath", env.interpreter());
134-
}
132+
env.interpreter().ifPresent(p -> workspaceOptions.put("environmentPath",
133+
p));
135134
workspaceOptions.put("extraPaths", env.paths());
136135
final Map<String, Object> options = new LinkedHashMap<>();
137136
options.put("workspace", workspaceOptions);

‎code-lsp-jedi/src/main/java/org/scijava/code/lsp/jedi/PythonLanguageServer.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@
6767
import org.scijava.code.lsp.Positions;
6868

6969
/**
70-
* The language server of {@code python} documents (see
71-
* {@link PythonServerPlugin}): jedi-language-server, whose completions are
72-
* made to work well in an editor completing as the user types:
70+
* A {@link LanguageServer} wrapping jedi-language-server, with a few nice
71+
* additions:
7372
* <ul>
7473
* <li>Asks about a word's first character only, and reuses the answer
7574
* (filtered) as the word is typed on, for a while.</li>

‎code-lsp-jedi/src/test/java/org/scijava/code/lsp/jedi/JediLauncherTest.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.net.URI;
3838
import java.util.List;
3939
import java.util.Map;
40+
import java.util.Optional;
4041
import java.util.concurrent.TimeUnit;
4142

4243
import org.apposed.appose.util.Environments;
@@ -77,8 +78,8 @@ public void testLanguageInitializationOptions() {
7778
// For a script running in some environment, the options tell Jedi to
7879
// analyze it with that environment's Python, also searching its extra
7980
// paths (e.g. a dependency overlay)...
80-
final Environment env = new Environment("/env/bin/python", List.of(
81-
"/overlay"));
81+
final Environment env = new Environment().withInterpreter("/env/bin/python")
82+
.withPaths(List.of("/overlay"));
8283
assertEquals(Map.of( //
8384
"workspace", Map.of("environmentPath", "/env/bin/python", //
8485
"extraPaths", List.of("/overlay")), //
@@ -89,7 +90,7 @@ public void testLanguageInitializationOptions() {
8990
assertEquals(Map.of( //
9091
"workspace", Map.of("extraPaths", List.of()), //
9192
"diagnostics", diagnostics), plugin.initializationOptions(
92-
Environment.NONE));
93+
new Environment()));
9394
}
9495

9596
/**
@@ -98,7 +99,7 @@ public void testLanguageInitializationOptions() {
9899
@Test
99100
public void testRootUri() {
100101
final JediLauncher plugin = new JediLauncher();
101-
final String root = plugin.rootUri(Environment.NONE);
102+
final String root = plugin.rootUri(new Environment());
102103
assertTrue(new File(URI.create(root)).isDirectory(), root);
103104
}
104105

‎code-lsp-jedi/src/test/java/org/scijava/code/lsp/jedi/JediLifecycleIntegrationTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void testLifecycle() throws Exception {
6060
try (final Context context = new Context(LanguageServerService.class)){
6161
// Get a LanguageServer Object
6262
final LanguageServerService service = context.service(LanguageServerService.class);
63-
final LanguageServer server = service.launch("python", Environment.NONE);
63+
final LanguageServer server = service.launch("python", new Environment());
6464
// Start it up
6565
server.initialize(new InitializeParams()).get();
6666
server.initialized(new InitializedParams());

‎code-lsp-jedi/src/test/java/org/scijava/code/lsp/jedi/PythonLanguageServerIntegrationTest.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Collections;
3838
import java.util.List;
3939
import java.util.Map;
40+
import java.util.concurrent.CompletableFuture;
4041
import java.util.concurrent.TimeUnit;
4142

4243
import javax.script.ScriptEngine;
@@ -192,9 +193,15 @@ public Header header(final Map<String, Class<?>> parameters) {
192193
}
193194

194195
/** The problems found in a script, in a session of its own. */
195-
private static List<Diagnostic> problems(final String code) {
196+
private static List<Diagnostic> problems(final String code)
197+
throws Exception
198+
{
199+
final CompletableFuture<List<Diagnostic>> found =
200+
new CompletableFuture<>();
196201
try (ScriptSession s = session()) {
197-
return s.update(code).diagnostics(120_000);
202+
s.setDiagnosticsListener(found::complete);
203+
s.update(code);
204+
return found.get(120, TimeUnit.SECONDS);
198205
}
199206
}
200207

0 commit comments

Comments
 (0)