Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
39891ea
Rework editor completion onto the neutral CodeCompleter SPI
gselzer Oct 4, 2026
fefd8a5
Add built-in Python (Jython) syntax highlighter
ctrueden Jun 22, 2026
7856a23
Update copyright headers for 2026
ctrueden Sep 13, 2026
092b7f2
WIP
ctrueden Sep 29, 2026
14bf70b
Show callable parameters in autocomplete
gselzer Oct 4, 2026
68ad53e
WIP: AI-generated overloaded params
gselzer Oct 4, 2026
fb96908
Show signature help, lazy docs and live updates
gselzer Oct 6, 2026
19b5db1
Tell completers when a script's editor closes
gselzer Oct 6, 2026
fe3ed2a
Show hover docs, problems and signatures as typed
gselzer Oct 6, 2026
b842236
Talk to language servers
gselzer Oct 7, 2026
bba9c03
Move off scijava-code-api, now removed
gselzer Oct 7, 2026
262c6c7
Ask language servers through script sessions
gselzer Oct 7, 2026
7b4ab38
Minor cleanup
gselzer Oct 7, 2026
2ea0c9e
Follow code-lsp's packages by purpose
gselzer Oct 8, 2026
7b99213
Use ClassIndex directly, not the deprecated ClassUtil
gselzer Oct 8, 2026
5d708bb
Ask for completions asynchronously
gselzer Oct 8, 2026
6ccfefa
Follow AbstractLanguageServer, as code-lsp renamed it
gselzer Oct 15, 2026
56dfdf3
Follow scijava-code-lsp's ScriptSession constructor and NO_STATE
gselzer Oct 19, 2026
0530536
Follow scijava-code-lsp: sessions are made with the service
gselzer Oct 20, 2026
7e6a4af
Make test sessions with a fake LanguageServerService
gselzer Oct 20, 2026
fd5c884
Follow scijava-code-lsp's sessions and environments
gselzer Oct 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
</ciManagement>

<properties>
<scijava.jvm.version>11</scijava.jvm.version>
<!-- TEMP: in-development versions providing code intelligence.
Remove once releases are pinned by pom-scijava. -->
<scijava-common.version>2.100.2-SNAPSHOT</scijava-common.version>
<scijava-code-lsp.version>0.1.0-SNAPSHOT</scijava-code-lsp.version>
<main-class>org.scijava.ui.swing.script.Main</main-class>
<package-name>org.scijava.ui.swing.script</package-name>
<license.licenseName>bsd_2</license.licenseName>
Expand All @@ -155,6 +160,11 @@
<groupId>org.scijava</groupId>
<artifactId>scijava-common</artifactId>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-code-lsp</artifactId>
<version>${scijava-code-lsp.version}</version>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-search</artifactId>
Expand Down
81 changes: 71 additions & 10 deletions src/main/java/org/scijava/ui/swing/script/EditorPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
import org.scijava.script.ScriptLanguage;
import org.scijava.script.ScriptService;
import org.scijava.ui.swing.script.vim.VimHandler;
import org.scijava.code.lsp.LanguageServerService;
import org.scijava.code.lsp.ScriptSession;
import org.scijava.ui.swing.script.autocompletion.LanguageServerLanguageSupport;
import org.scijava.util.FileUtils;

/**
Expand All @@ -117,9 +120,13 @@ public class EditorPane extends RSyntaxTextArea implements DocumentListener {
private boolean undoInProgress;
private boolean redoInProgress;
private boolean autoCompletionEnabled;
private boolean hoverEnabled = true;
private boolean diagnosticsEnabled = true;
private boolean autoCompletionJavaFallback;
private boolean autoCompletionWithoutKey;
private String supportStatus;
/** The completion support currently installed on this pane, if any. */
private LanguageSupport installedSupport;
private final ErrorParser errorHighlighter;
private final JMenu noneLangSyntaxMenu;
private final EditorPaneActions actions;
Expand All @@ -131,6 +138,8 @@ public class EditorPane extends RSyntaxTextArea implements DocumentListener {
@Parameter
private LanguageSupportService languageSupportService;
@Parameter
private LanguageServerService languageServerService;
@Parameter
private ScriptService scriptService;
@Parameter
private ScriptHeaderService scriptHeaderService;
Expand Down Expand Up @@ -718,6 +727,17 @@ protected void setLanguage(final ScriptLanguage language) {
setLanguage(language, false);
}

/**
* Uninstalls the language support (e.g. code completion), as the editor
* is closed.
*/
void releaseLanguageSupport() {
if (installedSupport != null) {
installedSupport.uninstall(this);
installedSupport = null;
}
}

/**
* Set the language of this {@link EditorPane}, optionally adding a header.
* TODO: What is this header?
Expand All @@ -731,11 +751,8 @@ protected void setLanguage(final ScriptLanguage language,
final boolean addHeader)
{
// uninstall existing language support.
LanguageSupport support =
languageSupportService.getLanguageSupport(currentLanguage);
if (support != null) {
support.uninstall(this);
}
releaseLanguageSupport();
LanguageSupport support;

String languageName;
String defaultExtension;
Expand Down Expand Up @@ -791,15 +808,26 @@ protected void setLanguage(final ScriptLanguage language,
return; // no need to update console any further
}
String supportLevel = "SciJava supported";
// try to get language support for current language, may be null.
// Tier 1: a heavy RSTA LanguageSupportPlugin (e.g. the Java parser).
support = languageSupportService.getLanguageSupport(currentLanguage);

// that did not work. See if there is internal support for it.
// Tier 2: language servers for this language.
if (support == null && languageServerService.supports(currentLanguage)) {
final ScriptLanguage served = currentLanguage;
final LanguageServerLanguageSupport serverSupport =
new LanguageServerLanguageSupport(() -> new ScriptSession(
languageServerService, served), log, this::getFile);
serverSupport.setHoverEnabled(hoverEnabled);
serverSupport.setDiagnosticsEnabled(diagnosticsEnabled);
support = serverSupport;
}

// Tier 3: RSTA's own built-in support for the syntax style.
if (support == null) {
support = LanguageSupportFactory.get().getSupportFor(styleName);
supportLevel = "Legacy supported";
}
// that did not work, Fallback to Java
// Tier 4: fall back to Java completion, if requested.
if (support == null && autoCompletionJavaFallback) {
support = languageSupportService.getLanguageSupport(scriptService.getLanguageByName("Java"));
supportLevel = "N/A. Using Java as fallback";
Expand All @@ -808,6 +836,7 @@ protected void setLanguage(final ScriptLanguage language,
support.setAutoCompleteEnabled(autoCompletionEnabled);
support.setAutoActivationEnabled(autoCompletionWithoutKey);
support.install(this);
installedSupport = support;
if (!autoCompletionEnabled)
supportLevel += " but currently disabled\n";
else {
Expand Down Expand Up @@ -840,8 +869,8 @@ public void setAutoCompletion(final boolean enabled) {
* @param enabled Whether Java should be enabled as fallback language for
* auto-completion
*/
void setFallbackAutoCompletion(final boolean value) {
autoCompletionJavaFallback = value;
void setFallbackAutoCompletion(final boolean enabled) {
autoCompletionJavaFallback = enabled;
if (autoCompletionEnabled && currentLanguage != null)
setLanguage(currentLanguage);
}
Expand All @@ -862,6 +891,32 @@ public boolean isAutoCompletionEnabled() {
return autoCompletionEnabled;
}

/**
* Toggles whether what is known about the code under the mouse (e.g. a
* function's documentation) is shown, for languages whose completer knows.
*/
public void setHoverEnabled(final boolean enabled) {
hoverEnabled = enabled;
if (currentLanguage != null) setLanguage(currentLanguage);
}

public boolean isHoverEnabled() {
return hoverEnabled;
}

/**
* Toggles whether problems in the code (e.g. syntax errors) are shown as
* the code is edited, for languages whose completer finds them.
*/
public void setDiagnosticsEnabled(final boolean enabled) {
diagnosticsEnabled = enabled;
if (currentLanguage != null) setLanguage(currentLanguage);
}

public boolean isDiagnosticsEnabled() {
return diagnosticsEnabled;
}

public boolean isAutoCompletionKeyless() {
return autoCompletionWithoutKey;
}
Expand Down Expand Up @@ -1069,6 +1124,8 @@ public void convertSpacesToTabs() {
public static final String AUTOCOMPLETE_PREFS = "script.editor.AC";
public static final String AUTOCOMPLETE_KEYLESS_PREFS = "script.editor.ACNoKey";
public static final String AUTOCOMPLETE_FALLBACK_PREFS = "script.editor.ACFallback";
public static final String HOVER_PREFS = "script.editor.Hover";
public static final String DIAGNOSTICS_PREFS = "script.editor.Diagnostics";
public static final String MARK_OCCURRENCES_PREFS = "script.editor.Occurrences";
public static final String VIM_PREFS = "script.editor.Vim";
public static final String FOLDERS_PREFS = "script.editor.folders";
Expand Down Expand Up @@ -1100,6 +1157,8 @@ public void loadPreferences() {
setKeylessAutoCompletion(prefService.getBoolean(getClass(), AUTOCOMPLETE_KEYLESS_PREFS, true)); // true for backwards compatibility with ImageJ macro
setFallbackAutoCompletion(prefService.getBoolean(getClass(), AUTOCOMPLETE_FALLBACK_PREFS, false));
setMarkOccurrences(prefService.getBoolean(getClass(), MARK_OCCURRENCES_PREFS, false));
setHoverEnabled(prefService.getBoolean(getClass(), HOVER_PREFS, true));
setDiagnosticsEnabled(prefService.getBoolean(getClass(), DIAGNOSTICS_PREFS, true));
setMarginLineEnabled(prefService.getBoolean(getClass(), MARGIN_VISIBLE_PREFS, false));
setVimEnabled(prefService.getBoolean(getClass(), VIM_PREFS, false));
applyTheme(themeName());
Expand Down Expand Up @@ -1156,6 +1215,8 @@ public void savePreferences(final String top_folders, final String theme) {
prefService.put(getClass(), AUTOCOMPLETE_PREFS, isAutoCompletionEnabled());
prefService.put(getClass(), AUTOCOMPLETE_KEYLESS_PREFS, isAutoCompletionKeyless());
prefService.put(getClass(), AUTOCOMPLETE_FALLBACK_PREFS, isAutoCompletionFallbackEnabled());
prefService.put(getClass(), HOVER_PREFS, isHoverEnabled());
prefService.put(getClass(), DIAGNOSTICS_PREFS, isDiagnosticsEnabled());
prefService.put(getClass(), MARGIN_VISIBLE_PREFS, isMarginLineEnabled());
prefService.put(getClass(), MARK_OCCURRENCES_PREFS, getMarkOccurrences());
prefService.put(getClass(), VIM_PREFS, isVimEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public void print(final String string) {

public void dispose() {
output.close();
prompt.dispose();
}

// -- UIComponent methods --
Expand Down
Loading
Loading