Skip to content

Commit a7ca671

Browse files
committed
merge App into PdeLanguageServer, more cleaning
1 parent eb1e88f commit a7ca671

File tree

5 files changed

+56
-55
lines changed

5 files changed

+56
-55
lines changed

java/src/processing/mode/java/lsp/App.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

java/src/processing/mode/java/lsp/PdeAdapter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Offset {
5252
}
5353
}
5454

55-
class ProcessingAdapter {
55+
class PdeAdapter {
5656
File rootPath;
5757
LanguageClient client;
5858
JavaMode javaMode;
@@ -66,7 +66,7 @@ class ProcessingAdapter {
6666
Set<URI> prevDiagnosticReportUris = new HashSet<URI>();
6767

6868

69-
ProcessingAdapter(File rootPath, LanguageClient client) {
69+
PdeAdapter(File rootPath, LanguageClient client) {
7070
this.rootPath = rootPath;
7171
this.client = client;
7272
this.javaMode = (JavaMode) ModeContribution
@@ -128,7 +128,7 @@ void notifySketchChanged() {
128128
}
129129

130130
Optional<SketchCode> findCodeByUri(URI uri) {
131-
return ProcessingAdapter.uriToPath(uri)
131+
return PdeAdapter.uriToPath(uri)
132132
.flatMap(path -> Arrays.stream(sketch.getCode())
133133
.filter(code -> code.getFile().equals(path))
134134
.findFirst()
@@ -143,13 +143,13 @@ void updateProblems(List<Problem> probs) {
143143
new Range(
144144
new Position(
145145
prob.getLineNumber(),
146-
ProcessingAdapter
146+
PdeAdapter
147147
.toLineCol(code.getProgram(), prob.getStartOffset())
148148
.col - 1
149149
),
150150
new Position(
151151
prob.getLineNumber(),
152-
ProcessingAdapter
152+
PdeAdapter
153153
.toLineCol(code.getProgram(), prob.getStopOffset())
154154
.col - 1
155155
)
@@ -162,7 +162,7 @@ void updateProblems(List<Problem> probs) {
162162
: DiagnosticSeverity.Warning
163163
);
164164
return new AbstractMap.SimpleEntry<URI, Diagnostic>(
165-
ProcessingAdapter.pathToUri(code.getFile()),
165+
PdeAdapter.pathToUri(code.getFile()),
166166
dia
167167
);
168168
})
@@ -317,7 +317,7 @@ Optional<TextEdit> format(URI uri) {
317317
.map(SketchCode::getProgram)
318318
.map(code -> {
319319
String newCode = new AutoFormat().format(code);
320-
Offset end = ProcessingAdapter.toLineCol(code, code.length());
320+
Offset end = PdeAdapter.toLineCol(code, code.length());
321321
return new TextEdit(
322322
new Range(
323323
new Position(0, 0),
Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,114 @@
11
package processing.mode.java.lsp;
22

3+
import java.io.File;
4+
import java.net.URI;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.Optional;
8+
import java.util.HashMap;
9+
import java.util.concurrent.CompletableFuture;
310

11+
import org.eclipse.lsp4j.launch.LSPLauncher;
412
import org.eclipse.lsp4j.services.LanguageServer;
513
import org.eclipse.lsp4j.services.TextDocumentService;
614
import org.eclipse.lsp4j.services.WorkspaceService;
715
import org.eclipse.lsp4j.InitializeResult;
816
import org.eclipse.lsp4j.InitializeParams;
9-
import java.util.concurrent.CompletableFuture;
1017
import org.eclipse.lsp4j.ServerCapabilities;
1118
import org.eclipse.lsp4j.TextDocumentSyncKind;
1219
import org.eclipse.lsp4j.CompletionOptions;
13-
14-
import java.io.File;
15-
1620
import org.eclipse.lsp4j.services.LanguageClientAware;
1721
import org.eclipse.lsp4j.services.LanguageClient;
1822

19-
import java.net.URI;
20-
import java.util.Optional;
21-
import java.util.HashMap;
22-
import java.util.Arrays;
2323

2424
class PdeLanguageServer implements LanguageServer, LanguageClientAware {
25-
static Optional<String> lowerExtension(File file) {
26-
String s = file.toString();
27-
int dot = s.lastIndexOf('.');
28-
if (dot == -1) return Optional.empty();
29-
else return Optional.of(s.substring(dot + 1).toLowerCase());
30-
}
31-
32-
HashMap<File, ProcessingAdapter> adapters = new HashMap<>();
25+
Map<File, PdeAdapter> adapters = new HashMap<>();
3326
LanguageClient client = null;
3427
PdeTextDocumentService textDocumentService = new PdeTextDocumentService(this);
3528
PdeWorkspaceService workspaceService = new PdeWorkspaceService(this);
3629

30+
3731
@Override
3832
public void exit() {
3933
System.out.println("exit");
4034
}
4135

36+
4237
@Override
4338
public TextDocumentService getTextDocumentService() {
4439
return textDocumentService;
4540
}
4641

42+
4743
@Override
4844
public WorkspaceService getWorkspaceService() {
4945
return workspaceService;
5046
}
5147

52-
Optional<ProcessingAdapter> getAdapter(URI uri) {
53-
return ProcessingAdapter.uriToPath(uri).filter(file -> {
48+
49+
static Optional<String> lowerExtension(File file) {
50+
String s = file.toString();
51+
int dot = s.lastIndexOf('.');
52+
if (dot == -1) return Optional.empty();
53+
else return Optional.of(s.substring(dot + 1).toLowerCase());
54+
}
55+
56+
57+
Optional<PdeAdapter> getAdapter(URI uri) {
58+
return PdeAdapter.uriToPath(uri).filter(file -> {
5459
String ext = lowerExtension(file).orElse("");
5560
return ext.equals("pde") || ext.equals("java");
5661
}).map(file -> {
5762
File rootDir = file.getParentFile();
58-
return adapters.computeIfAbsent(rootDir, _k -> new ProcessingAdapter(rootDir, client));
63+
return adapters.computeIfAbsent(rootDir, _k -> new PdeAdapter(rootDir, client));
5964
});
6065
}
6166

67+
6268
@Override
6369
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
64-
ProcessingAdapter.init();
70+
PdeAdapter.init();
6571
System.out.println("initialize");
6672
var capabilities = new ServerCapabilities();
6773
capabilities.setTextDocumentSync(TextDocumentSyncKind.Full);
6874

6975
var completionOptions = new CompletionOptions();
7076
completionOptions.setResolveProvider(true);
71-
completionOptions.setTriggerCharacters(
72-
Arrays.asList(
73-
"."
74-
)
75-
);
77+
completionOptions.setTriggerCharacters(List.of("."));
7678
capabilities.setCompletionProvider(completionOptions);
7779
capabilities.setDocumentFormattingProvider(true);
7880
var result = new InitializeResult(capabilities);
7981
return CompletableFuture.completedFuture(result);
8082
}
8183

84+
8285
@Override
8386
public CompletableFuture<Object> shutdown() {
8487
System.out.println("shutdown");
8588
return CompletableFuture.completedFuture(null);
8689
}
8790

91+
8892
@Override
8993
public void connect(LanguageClient client) {
9094
this.client = client;
9195
}
96+
97+
98+
static public void main(String[] args) {
99+
var input = System.in;
100+
var output = System.out;
101+
System.setOut(System.err);
102+
103+
var server = new PdeLanguageServer();
104+
var launcher =
105+
LSPLauncher.createServerLauncher(
106+
server,
107+
input,
108+
output
109+
);
110+
var client = launcher.getRemoteProxy();
111+
server.connect(client);
112+
launcher.startListening();
113+
}
92114
}

java/src/processing/mode/java/lsp/PdeWorkspaceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
2525
pls.getAdapter(uri).ifPresent(adapter -> {
2626
switch (change.getType()) {
2727
case Created:
28-
ProcessingAdapter.uriToPath(uri).ifPresent(path -> {
28+
PdeAdapter.uriToPath(uri).ifPresent(path -> {
2929
adapter.sketch.loadNewTab(path.getName().toString(), "pde", true);
3030
adapter.notifySketchChanged();
3131
});

todo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ _ https://github.com/processing/processing4/issues/524
1818
X look into LSP code contribution
1919
X https://github.com/processing/processing4/pull/564
2020
_ https://github.com/processing/processing4/issues/117
21+
_ App was merged into processing.mode.java.lsp.PdeLanguageServer
2122

2223

2324
_ "Show Sketch Folder" for libraries needs to treat the sketch as Untitled

0 commit comments

Comments
 (0)