Skip to content

Commit f47ea10

Browse files
gselzerclaude
andcommitted
Follow scijava-code-lsp: an Optional file, and a non-null live state
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9664a7c commit f47ea10

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Collection;
3737
import java.util.List;
3838
import java.util.Map;
39+
import java.util.Optional;
3940

4041
import net.imglib2.RandomAccessibleInterval;
4142

@@ -79,10 +80,12 @@ public String languageId() {
7980
}
8081

8182
@Override
82-
public Environment environment(final String text, final File file) {
83+
public Environment environment(final String text,
84+
final Optional<File> file)
85+
{
8386
// NB: As its #@script line, or its inline metadata, says.
84-
return environments().environment(text, file == null ? null : file
85-
.getPath());
87+
return environments().environment(text, file.map(File::getPath).orElse(
88+
null));
8689
}
8790

8891
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ org.scijava.code.lsp.Environment environment(final String text,
8989
{
9090
final String python = scriptPython(text, path);
9191
return python == null ? org.scijava.code.lsp.Environment.NONE
92-
: new org.scijava.code.lsp.Environment(python, null, null);
92+
: new org.scijava.code.lsp.Environment(python, null);
9393
}
9494

9595
/**

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.LinkedHashMap;
4040
import java.util.List;
4141
import java.util.Map;
42+
import java.util.Optional;
4243

4344
import net.imglib2.img.Img;
4445

@@ -131,7 +132,8 @@ public void testHeader() {
131132
@Test
132133
public void testEnvironmentWithoutOne() {
133134
// No script environment has been built: the server's own Python.
134-
final Environment env = dialect.environment("import os\nos.pa", null);
135+
final Environment env = dialect.environment("import os\nos.pa", Optional
136+
.empty());
135137
assertNull(env.interpreter());
136138
assertTrue(env.paths().isEmpty());
137139
}
@@ -142,8 +144,9 @@ public void testScriptWorkersUntouched() {
142144
// it, even as its metadata is edited.
143145
final String script = "# /// script\n# dependencies = [\"appose\"]\n" +
144146
"# ///\nimport os\nos.pa";
145-
dialect.environment(script, null);
146-
dialect.environment(script.replace("appose", "appose, numpy"), null);
147+
dialect.environment(script, Optional.empty());
148+
dialect.environment(script.replace("appose", "appose, numpy"), Optional
149+
.empty());
147150
assertTrue(context.service(ResidentWorkerService.class).workers()
148151
.isEmpty());
149152
}
@@ -167,7 +170,8 @@ public void testEnvironmentFromEarlierSession() throws Exception {
167170
java.nio.file.Files.createDirectories(python.getParent());
168171
java.nio.file.Files.createFile(python);
169172

170-
final Environment env = dialect.environment(header + "numpy.ze", script);
173+
final Environment env = dialect.environment(header + "numpy.ze",
174+
Optional.of(script));
171175
// The server analyzes against the environment's Python...
172176
assertEquals(python.toFile().getAbsolutePath(), env.interpreter());
173177
// ...without anything built or started.

0 commit comments

Comments
 (0)