Skip to content

Commit 1e12764

Browse files
gselzerclaude
andcommitted
code-lsp: drop script session accessors nobody calls
ScriptSession.server, language, text and uri, and setFile(File), had no callers outside tests; nor had LanguageServerService.session(File). Clients set a file supplier, as editors follow Save As. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3fbdd12 commit 1e12764

4 files changed

Lines changed: 10 additions & 56 deletions

File tree

‎code-lsp/src/main/java/org/scijava/code/lsp/LanguageServerService.java‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
package org.scijava.code.lsp;
3131

32-
import java.io.File;
33-
import java.io.IOException;
3432
import java.util.List;
3533
import java.util.Map;
3634

@@ -65,13 +63,6 @@ public interface LanguageServerService extends SciJavaService {
6563
*/
6664
ScriptSession session(ScriptLanguage language, ScriptContext live);
6765

68-
/**
69-
* Starts a session about a script file, as it is on disk: of its file
70-
* extension's language. Returns null if no language of that extension is
71-
* served.
72-
*/
73-
ScriptSession session(File file) throws IOException;
74-
7566
/**
7667
* Tells the servers that where scripts run may have changed without the
7768
* scripts changing, e.g. as an environment finished building, or packages
@@ -97,7 +88,7 @@ public interface LanguageServerService extends SciJavaService {
9788
/**
9889
* Finds the problems in a script, waiting for them: for tools that ask
9990
* once, rather than editors. (For a script file, whose servers may depend
100-
* on where it is, use a {@link #session(File)}.)
91+
* on where it is, use a {@link #session session} with its file set.)
10192
*
10293
* @param language The script's language.
10394
* @param text The script.

‎code-lsp/src/main/java/org/scijava/code/lsp/ScriptSession.java‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,6 @@ ScriptSession connect() {
162162
return this;
163163
}
164164

165-
/** The server this session asks. */
166-
public LanguageServer server() {
167-
return server;
168-
}
169-
170-
/** The script's language, or null if unknown. */
171-
public ScriptLanguage language() {
172-
return language;
173-
}
174-
175-
/** Sets the script's file (null if it has none). */
176-
public ScriptSession setFile(final File file) {
177-
return setFile(() -> file);
178-
}
179-
180165
/**
181166
* Sets a supplier of the script's file, asked each time the script is
182167
* updated, e.g. so that Save As is followed.
@@ -229,16 +214,6 @@ else if (!newText.equals(text)) {
229214
return this;
230215
}
231216

232-
/** The text last sent, or null if the script is not open. */
233-
public synchronized String text() {
234-
return text;
235-
}
236-
237-
/** The script's URI, or null if it is not open. */
238-
public synchronized String uri() {
239-
return uri;
240-
}
241-
242217
// -- Requests: about the given text (sent first, if new), at an offset --
243218

244219
/**

‎code-lsp/src/main/java/org/scijava/code/lsp/impl/DefaultLanguageServerService.java‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929

3030
package org.scijava.code.lsp.impl;
3131

32-
import java.io.File;
33-
import java.io.IOException;
34-
import java.nio.charset.StandardCharsets;
35-
import java.nio.file.Files;
3632
import java.util.ArrayList;
3733
import java.util.Collections;
3834
import java.util.HashMap;
@@ -131,18 +127,6 @@ public ScriptSession session(final ScriptLanguage language,
131127
return session.setLogger(log);
132128
}
133129

134-
@Override
135-
public ScriptSession session(final File file) throws IOException {
136-
final String name = file.getName();
137-
final int dot = name.lastIndexOf('.');
138-
final ScriptLanguage language = scriptService == null || dot < 0 ? null
139-
: scriptService.getLanguageByExtension(name.substring(dot + 1));
140-
if (language == null || !supports(language)) return null;
141-
final String text = new String(Files.readAllBytes(file.toPath()),
142-
StandardCharsets.UTF_8);
143-
return session(language).setFile(file).update(text);
144-
}
145-
146130
@Override
147131
public void environmentsChanged() {
148132
for (final MergedLanguageServer server : new HashSet<>(owners.values())) {

‎code-lsp/src/test/java/org/scijava/code/lsp/impl/LanguageServersTest.java‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,14 @@ public void testSession() throws Exception {
264264
.setDiagnosticsListener(heard::add);
265265
// Opened with its first text; untitled, with its language's extension.
266266
session.update("x = 1");
267-
assertTrue(session.uri().startsWith("untitled:/script-"));
268-
assertTrue(session.uri().endsWith(".merge"));
269267
// The same text again: nothing sent; another: the next version.
270268
session.update("x = 1").update("x.ma");
271269
awaitEvents("fast", 2);
272270
final List<String> events = SERVERS.get("fast").events;
273271
assertEquals(Arrays.asList("open 1 x = 1", "change 2 x.ma"), events);
272+
final List<String> opened = SERVERS.get("fast").opened;
273+
assertTrue(opened.get(0).startsWith("untitled:/script-"));
274+
assertTrue(opened.get(0).endsWith(".merge"));
274275

275276
// Asked about a text (the current one: nothing sent), at an offset.
276277
final CompletionList list = session.completion("x.ma", 4).get(10,
@@ -287,13 +288,13 @@ public void testSession() throws Exception {
287288

288289
// Saved as a file: closed, and opened anew as the file.
289290
final File file = new File("scripts", "a.merge");
290-
session.setFile(file).update("x.ma");
291+
session.setFile(() -> file).update("x.ma");
291292
awaitEvents("fast", 4);
292293
assertEquals(Arrays.asList("close", "open 1 x.ma"), events.subList(2, 4));
293-
assertEquals(file.getAbsoluteFile().toURI().toString(), session.uri());
294+
assertEquals(file.getAbsoluteFile().toURI().toString(), opened.get(1));
294295
session.close();
295296
awaitEvents("fast", 5);
296-
assertNull(session.uri());
297+
assertEquals("close", events.get(4));
297298
}
298299

299300
@Test
@@ -586,6 +587,8 @@ static class FakeServer implements LanguageServer, TextDocumentService,
586587
final boolean slow;
587588
boolean silent;
588589
final List<String> events = new CopyOnWriteArrayList<>();
590+
/** The URIs of the documents opened, in order. */
591+
final List<String> opened = new CopyOnWriteArrayList<>();
589592
final List<Position> asked = new CopyOnWriteArrayList<>();
590593
LanguageClient client;
591594

@@ -631,6 +634,7 @@ public WorkspaceService getWorkspaceService() {
631634
@Override
632635
public void didOpen(final DidOpenTextDocumentParams p) {
633636
final TextDocumentItem d = p.getTextDocument();
637+
opened.add(d.getUri());
634638
events.add("open " + d.getVersion() + " " + d.getText());
635639
diagnose(d.getUri(), d.getVersion(), d.getText());
636640
}

0 commit comments

Comments
 (0)