Skip to content

Commit b618794

Browse files
gselzerclaude
andcommitted
Follow scijava-code-lsp's sessions and environments
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e81fd83 commit b618794

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.io.IOException;
3434
import java.util.ArrayList;
3535
import java.util.Arrays;
36+
import java.util.Collections;
3637
import java.util.HashMap;
3738
import java.util.LinkedHashMap;
3839
import java.util.List;
@@ -152,8 +153,8 @@ org.scijava.code.lsp.Environment environment(final String text,
152153
final String path)
153154
{
154155
final String python = scriptPython(text, path);
155-
return python == null ? org.scijava.code.lsp.Environment.NONE
156-
: new org.scijava.code.lsp.Environment(python, null);
156+
return python == null ? new org.scijava.code.lsp.Environment()
157+
: new org.scijava.code.lsp.Environment().withInterpreter(python);
157158
}
158159

159160
/**

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.HashMap;
4242
import java.util.List;
4343
import java.util.Map;
44+
import java.util.concurrent.CompletableFuture;
4445
import java.util.concurrent.TimeUnit;
4546

4647
import org.eclipse.lsp4j.CompletionItem;
@@ -164,14 +165,23 @@ public void testNewDependency() throws Exception {
164165
/** The session about a script (null path: untitled). */
165166
private static ScriptSession session(final String path) {
166167
return sessions.computeIfAbsent(path == null ? "" : path,
167-
p -> new ScriptSession(servers, language).setFile(() -> path == null
168-
? null : new File(path)));
168+
p -> {
169+
final ScriptSession session = new ScriptSession(servers, language);
170+
session.setFile(() -> path == null ? null : new File(path));
171+
return session;
172+
});
169173
}
170174

171175
/** The problems found in a script, in a session of its own. */
172-
private static List<Diagnostic> problems(final String code) {
176+
private static List<Diagnostic> problems(final String code)
177+
throws Exception
178+
{
179+
final CompletableFuture<List<Diagnostic>> found =
180+
new CompletableFuture<>();
173181
try (ScriptSession session = new ScriptSession(servers, language)) {
174-
return session.update(code).diagnostics(120_000);
182+
session.setDiagnosticsListener(found::complete);
183+
session.update(code);
184+
return found.get(120, TimeUnit.SECONDS);
175185
}
176186
}
177187

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void testEnvironmentWithoutOne() {
134134
// No script environment has been built: the server's own Python.
135135
final Environment env = dialect.environment("import os\nos.pa", Optional
136136
.empty());
137-
assertNull(env.interpreter());
137+
assertEquals(Optional.empty(), env.interpreter());
138138
assertTrue(env.paths().isEmpty());
139139
}
140140

@@ -174,7 +174,8 @@ public void testEnvironmentFromEarlierSession() throws Exception {
174174
final Environment env = dialect.environment(header + "numpy.ze",
175175
Optional.of(script));
176176
// The server analyzes against the environment's Python...
177-
assertEquals(python.toFile().getAbsolutePath(), env.interpreter());
177+
assertEquals(Optional.of(python.toFile().getAbsolutePath()), env
178+
.interpreter());
178179
// ...without anything built or started.
179180
assertTrue(context.service(ResidentWorkerService.class).workers()
180181
.isEmpty());

0 commit comments

Comments
 (0)