mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 03:11:08 +01:00
merge App into PdeLanguageServer, more cleaning
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
package processing.mode.java.lsp;
|
||||
|
||||
import org.eclipse.lsp4j.launch.LSPLauncher;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
var input = System.in;
|
||||
var output = System.out;
|
||||
System.setOut(System.err);
|
||||
|
||||
var server = new PdeLanguageServer();
|
||||
var launcher =
|
||||
LSPLauncher.createServerLauncher(
|
||||
server,
|
||||
input,
|
||||
output
|
||||
);
|
||||
var client = launcher.getRemoteProxy();
|
||||
server.connect(client);
|
||||
launcher.startListening();
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class Offset {
|
||||
}
|
||||
}
|
||||
|
||||
class ProcessingAdapter {
|
||||
class PdeAdapter {
|
||||
File rootPath;
|
||||
LanguageClient client;
|
||||
JavaMode javaMode;
|
||||
@@ -66,7 +66,7 @@ class ProcessingAdapter {
|
||||
Set<URI> prevDiagnosticReportUris = new HashSet<URI>();
|
||||
|
||||
|
||||
ProcessingAdapter(File rootPath, LanguageClient client) {
|
||||
PdeAdapter(File rootPath, LanguageClient client) {
|
||||
this.rootPath = rootPath;
|
||||
this.client = client;
|
||||
this.javaMode = (JavaMode) ModeContribution
|
||||
@@ -128,7 +128,7 @@ class ProcessingAdapter {
|
||||
}
|
||||
|
||||
Optional<SketchCode> findCodeByUri(URI uri) {
|
||||
return ProcessingAdapter.uriToPath(uri)
|
||||
return PdeAdapter.uriToPath(uri)
|
||||
.flatMap(path -> Arrays.stream(sketch.getCode())
|
||||
.filter(code -> code.getFile().equals(path))
|
||||
.findFirst()
|
||||
@@ -143,13 +143,13 @@ class ProcessingAdapter {
|
||||
new Range(
|
||||
new Position(
|
||||
prob.getLineNumber(),
|
||||
ProcessingAdapter
|
||||
PdeAdapter
|
||||
.toLineCol(code.getProgram(), prob.getStartOffset())
|
||||
.col - 1
|
||||
),
|
||||
new Position(
|
||||
prob.getLineNumber(),
|
||||
ProcessingAdapter
|
||||
PdeAdapter
|
||||
.toLineCol(code.getProgram(), prob.getStopOffset())
|
||||
.col - 1
|
||||
)
|
||||
@@ -162,7 +162,7 @@ class ProcessingAdapter {
|
||||
: DiagnosticSeverity.Warning
|
||||
);
|
||||
return new AbstractMap.SimpleEntry<URI, Diagnostic>(
|
||||
ProcessingAdapter.pathToUri(code.getFile()),
|
||||
PdeAdapter.pathToUri(code.getFile()),
|
||||
dia
|
||||
);
|
||||
})
|
||||
@@ -317,7 +317,7 @@ class ProcessingAdapter {
|
||||
.map(SketchCode::getProgram)
|
||||
.map(code -> {
|
||||
String newCode = new AutoFormat().format(code);
|
||||
Offset end = ProcessingAdapter.toLineCol(code, code.length());
|
||||
Offset end = PdeAdapter.toLineCol(code, code.length());
|
||||
return new TextEdit(
|
||||
new Range(
|
||||
new Position(0, 0),
|
||||
|
||||
@@ -1,27 +1,51 @@
|
||||
package processing.mode.java.lsp;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.lsp4j.launch.LSPLauncher;
|
||||
import org.eclipse.lsp4j.services.LanguageServer;
|
||||
import org.eclipse.lsp4j.services.TextDocumentService;
|
||||
import org.eclipse.lsp4j.services.WorkspaceService;
|
||||
import org.eclipse.lsp4j.InitializeResult;
|
||||
import org.eclipse.lsp4j.InitializeParams;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.eclipse.lsp4j.ServerCapabilities;
|
||||
import org.eclipse.lsp4j.TextDocumentSyncKind;
|
||||
import org.eclipse.lsp4j.CompletionOptions;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.lsp4j.services.LanguageClientAware;
|
||||
import org.eclipse.lsp4j.services.LanguageClient;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Optional;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
|
||||
class PdeLanguageServer implements LanguageServer, LanguageClientAware {
|
||||
Map<File, PdeAdapter> adapters = new HashMap<>();
|
||||
LanguageClient client = null;
|
||||
PdeTextDocumentService textDocumentService = new PdeTextDocumentService(this);
|
||||
PdeWorkspaceService workspaceService = new PdeWorkspaceService(this);
|
||||
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
System.out.println("exit");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TextDocumentService getTextDocumentService() {
|
||||
return textDocumentService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public WorkspaceService getWorkspaceService() {
|
||||
return workspaceService;
|
||||
}
|
||||
|
||||
|
||||
static Optional<String> lowerExtension(File file) {
|
||||
String s = file.toString();
|
||||
int dot = s.lastIndexOf('.');
|
||||
@@ -29,64 +53,62 @@ class PdeLanguageServer implements LanguageServer, LanguageClientAware {
|
||||
else return Optional.of(s.substring(dot + 1).toLowerCase());
|
||||
}
|
||||
|
||||
HashMap<File, ProcessingAdapter> adapters = new HashMap<>();
|
||||
LanguageClient client = null;
|
||||
PdeTextDocumentService textDocumentService = new PdeTextDocumentService(this);
|
||||
PdeWorkspaceService workspaceService = new PdeWorkspaceService(this);
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
System.out.println("exit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextDocumentService getTextDocumentService() {
|
||||
return textDocumentService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorkspaceService getWorkspaceService() {
|
||||
return workspaceService;
|
||||
}
|
||||
|
||||
Optional<ProcessingAdapter> getAdapter(URI uri) {
|
||||
return ProcessingAdapter.uriToPath(uri).filter(file -> {
|
||||
Optional<PdeAdapter> getAdapter(URI uri) {
|
||||
return PdeAdapter.uriToPath(uri).filter(file -> {
|
||||
String ext = lowerExtension(file).orElse("");
|
||||
return ext.equals("pde") || ext.equals("java");
|
||||
}).map(file -> {
|
||||
File rootDir = file.getParentFile();
|
||||
return adapters.computeIfAbsent(rootDir, _k -> new ProcessingAdapter(rootDir, client));
|
||||
return adapters.computeIfAbsent(rootDir, _k -> new PdeAdapter(rootDir, client));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
|
||||
ProcessingAdapter.init();
|
||||
PdeAdapter.init();
|
||||
System.out.println("initialize");
|
||||
var capabilities = new ServerCapabilities();
|
||||
capabilities.setTextDocumentSync(TextDocumentSyncKind.Full);
|
||||
|
||||
var completionOptions = new CompletionOptions();
|
||||
completionOptions.setResolveProvider(true);
|
||||
completionOptions.setTriggerCharacters(
|
||||
Arrays.asList(
|
||||
"."
|
||||
)
|
||||
);
|
||||
completionOptions.setTriggerCharacters(List.of("."));
|
||||
capabilities.setCompletionProvider(completionOptions);
|
||||
capabilities.setDocumentFormattingProvider(true);
|
||||
var result = new InitializeResult(capabilities);
|
||||
return CompletableFuture.completedFuture(result);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Object> shutdown() {
|
||||
System.out.println("shutdown");
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void connect(LanguageClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
||||
static public void main(String[] args) {
|
||||
var input = System.in;
|
||||
var output = System.out;
|
||||
System.setOut(System.err);
|
||||
|
||||
var server = new PdeLanguageServer();
|
||||
var launcher =
|
||||
LSPLauncher.createServerLauncher(
|
||||
server,
|
||||
input,
|
||||
output
|
||||
);
|
||||
var client = launcher.getRemoteProxy();
|
||||
server.connect(client);
|
||||
launcher.startListening();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class PdeWorkspaceService implements WorkspaceService {
|
||||
pls.getAdapter(uri).ifPresent(adapter -> {
|
||||
switch (change.getType()) {
|
||||
case Created:
|
||||
ProcessingAdapter.uriToPath(uri).ifPresent(path -> {
|
||||
PdeAdapter.uriToPath(uri).ifPresent(path -> {
|
||||
adapter.sketch.loadNewTab(path.getName().toString(), "pde", true);
|
||||
adapter.notifySketchChanged();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user