Skip to content

Commit b9d633e

Browse files
gselzerclaude
andcommitted
Analyze scripts with the packages they declare, as the dialect says
The overlays of packages a script declares, but its environment lacks, move here from scijava-code-lsp-jedi, whose servers now analyze scripts in exactly the environment they are given: ApposePythonDialect includes them in the environment it reports. They are installed with Appose's uv. Also follows scijava-code-lsp: sessions are made with the service. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f47ea10 commit b9d633e

4 files changed

Lines changed: 571 additions & 10 deletions

File tree

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import net.imglib2.RandomAccessibleInterval;
4242

4343
import org.apposed.appose.NDArray;
44+
import org.apposed.appose.util.Environments;
4445
import org.scijava.code.lsp.Environment;
4546
import org.scijava.code.lsp.ScriptDialect;
4647
import org.scijava.plugin.Parameter;
@@ -51,7 +52,8 @@
5152

5253
/**
5354
* Describes how to turn Appose python scripts into plain python code, and
54-
* where they run (see {@link ApposePythonEnvironments}).
55+
* where they run (see {@link ApposePythonEnvironments}), searching the
56+
* packages they declare but that lacks, too (see {@link DependencyOverlays}).
5557
*
5658
* @author Gabriel Selzer
5759
*/
@@ -69,6 +71,14 @@ public class ApposePythonDialect implements ScriptDialect {
6971

7072
private ApposePythonEnvironments environments;
7173

74+
/**
75+
* How long a script's dependencies must stay unchanged before packages
76+
* missing from its environment are installed for completion, in ms.
77+
*/
78+
private static final long OVERLAY_SETTLE = 1500;
79+
80+
private static DependencyOverlays overlays;
81+
7282
@Override
7383
public boolean supports(final ScriptLanguage language) {
7484
return language instanceof ApposePythonScriptLanguage;
@@ -83,9 +93,12 @@ public String languageId() {
8393
public Environment environment(final String text,
8494
final Optional<File> file)
8595
{
86-
// NB: As its #@script line, or its inline metadata, says.
87-
return environments().environment(text, file.map(File::getPath).orElse(
88-
null));
96+
// NB: As its #@script line, or its inline metadata, says; plus the
97+
// packages it declares but that environment lacks (installed for
98+
// completion only, see DependencyOverlays).
99+
final String path = file.map(File::getPath).orElse(null);
100+
return overlays().environment(text, path, environments().environment(
101+
text, path));
89102
}
90103

91104
@Override
@@ -145,6 +158,19 @@ static String parameterType(final Class<?> type) {
145158
return null;
146159
}
147160

161+
/**
162+
* Gets the overlays of packages scripts declare, but their environments
163+
* lack: one set, for all dialect instances (sessions).
164+
*/
165+
private static synchronized DependencyOverlays overlays() {
166+
if (overlays == null) {
167+
overlays = new DependencyOverlays(DependencyOverlays::install, new File(
168+
Environments.apposeEnvsDir(), "appose-python-completion-overlays"),
169+
OVERLAY_SETTLE, System::currentTimeMillis);
170+
}
171+
return overlays;
172+
}
173+
148174
/** Gets where scripts run, creating it on first use. */
149175
private synchronized ApposePythonEnvironments environments() {
150176
if (environments == null) {

0 commit comments

Comments
 (0)