Skip to content

Commit 906844f

Browse files
gselzerclaude
andcommitted
Take ScriptDialect.environment's file as nullable, not Optional
scijava-code-lsp now passes null for an unsaved script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c955a81 commit 906844f

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

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

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

4140
import net.imglib2.RandomAccessibleInterval;
4241

@@ -80,12 +79,10 @@ public String outputLanguage() {
8079
}
8180

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

9188
@Override

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ public void testHeader() {
134134
@Test
135135
public void testEnvironmentWithoutOne() {
136136
// No script environment has been built: the server's own Python.
137-
final Environment env = dialect.environment("import os\nos.pa", Optional
138-
.empty());
137+
final Environment env = dialect.environment("import os\nos.pa", null);
139138
assertEquals(Optional.empty(), env.interpreter());
140139
assertTrue(env.paths().isEmpty());
141140
}
@@ -147,9 +146,8 @@ public void testScriptWorkersUntouched() {
147146
// has settled (see ApposePythonEnvironmentsTest).
148147
final String script = "# /// script\n# dependencies = [\"appose\"]\n" +
149148
"# ///\nimport os\nos.pa";
150-
dialect.environment(script, Optional.empty());
151-
dialect.environment(script.replace("appose", "appose, numpy"), Optional
152-
.empty());
149+
dialect.environment(script, null);
150+
dialect.environment(script.replace("appose", "appose, numpy"), null);
153151
assertTrue(context.service(ResidentWorkerService.class).workers()
154152
.isEmpty());
155153
}
@@ -174,7 +172,7 @@ public void testEnvironmentFromEarlierSession() throws Exception {
174172
java.nio.file.Files.createFile(python);
175173

176174
final Environment env = dialect.environment(header + "numpy.ze",
177-
Optional.of(script));
175+
script);
178176
// The server analyzes against the environment's Python...
179177
assertEquals(Optional.of(python.toFile().getAbsolutePath()), env
180178
.interpreter());

0 commit comments

Comments
 (0)