Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation language server #564

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@

<!--
<antcall target="download-ant" />
<antcall target="download-flatlaf" />
<antcall target="download-jna" />
<antcall target="download-flatlaf" />
-->
</target>

Expand Down
2 changes: 1 addition & 1 deletion app/processing4-app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
</library>
</orderEntry>
</component>
</module>
</module>
5 changes: 5 additions & 0 deletions build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@
<include name="theme/**" />
</fileset>
</copy>
<copy todir="${target.path}/modes/java/mode" preservelastmodified="true">
<fileset dir="../java/lib">
<include name="**/*.jar" />
</fileset>
</copy>

<!-- get the examples folder, but don't require it to buid -->
<copy todir="${target.path}/modes/java/examples"
Expand Down
1 change: 1 addition & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin
bin-test
generated
mode/JavaMode.jar
ivy.jar
41 changes: 38 additions & 3 deletions java/build.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<project name="Java Mode" default="build">
<project name="Java Mode" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

<property name="generated"
value="${basedir}/generated/processing/mode/java/preproc" />
Expand All @@ -18,6 +18,34 @@
<classpath path="${antlr_jar}" />
</classloader>

<property name="ivy.version" value="2.5.0" />
<fileset id="ivy.files" dir="lib">
<include name="ivy.jar" />
</fileset>
<property name="ivy.url"
value="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" />

<available file="ivy.jar" property="ivy.present" />

<condition property="ivy.ignorable" value="false" else="true">
<isset property="ivy.present" />
</condition>

<target name="download-ivy" unless="ivy.present">
<get src="${ivy.url}" dest="ivy.jar"
ignoreerrors="${ivy.ignorable}"
usetimestamp="true" />
</target>

<target name="init-ivy" depends="download-ivy">
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpath="ivy.jar"/>
</target>

<target name="download-ivy-dependencies" depends="init-ivy">
<ivy:retrieve />
</target>

<target name="clean" description="Clean the build directories">
<delete dir="bin" />
<delete dir="bin-test" />
Expand All @@ -32,6 +60,11 @@
<include name="*.properties" />
</fileset>
</delete>
<delete>
<fileset dir="lib">
<include name="*.jar" />
</fileset>
</delete>
</target>

<target name="preproc" description="Compile ANTLR 4 grammar">
Expand Down Expand Up @@ -71,6 +104,8 @@
<pathelement location="mode/org.eclipse.jdt.core.jar" />
<pathelement location="mode/org.eclipse.osgi.jar" />
<pathelement location="mode/org.eclipse.text.jar" />
<pathelement location="mode/org.eclipse.ui.workbench.jar" />
<fileset dir="lib" includes="*.jar" />
</path>

<path id="classpath.test">
Expand Down Expand Up @@ -123,7 +158,7 @@
</sequential>
</macrodef>

<target name="test-compile" depends="preproc">
<target name="test-compile" depends="preproc, download-ivy-dependencies">
<compilecommon srcdir="src; test/processing" destdir="bin-test" classpath="classpath.test" />
</target>

Expand All @@ -140,7 +175,7 @@
</junit>
</target>

<target name="compile" description="Compile sources" depends="preproc">
<target name="compile" description="Compile sources" depends="preproc, download-ivy-dependencies">
<compilecommon srcdir="src" destdir="bin" classpath="classpath.base" />
</target>

Expand Down
7 changes: 7 additions & 0 deletions java/ivy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="" module="" />
<dependencies>
<dependency org="org.eclipse.lsp4j" name="org.eclipse.lsp4j" rev="0.12.0"/>
</dependencies>
</ivy-module>
1 change: 1 addition & 0 deletions java/lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.jar
2 changes: 1 addition & 1 deletion java/src/processing/mode/java/CompletionGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ public List<CompletionCandidate> preparePredictions(final PreprocSketch ps,
}


protected static DefaultListModel<CompletionCandidate> filterPredictions(List<CompletionCandidate> candidates) {
public static DefaultListModel<CompletionCandidate> filterPredictions(List<CompletionCandidate> candidates) {
Messages.log("* filterPredictions");
DefaultListModel<CompletionCandidate> defListModel = new DefaultListModel<>();
if (candidates.isEmpty())
Expand Down
10 changes: 5 additions & 5 deletions java/src/processing/mode/java/ErrorChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import processing.app.Problem;


class ErrorChecker {
public class ErrorChecker {
// Delay delivering error check result after last sketch change
// https://github.com/processing/processing/issues/2677
private final static long DELAY_BEFORE_UPDATE = 650;
Expand All @@ -41,11 +41,11 @@ class ErrorChecker {
private final Consumer<PreprocSketch> errorHandlerListener =
this::handleSketchProblems;

final private JavaEditor editor;
final private Consumer<List<Problem>> editor;
final private PreprocService pps;


public ErrorChecker(JavaEditor editor, PreprocService pps) {
public ErrorChecker(Consumer<List<Problem>> editor, PreprocService pps) {
this.editor = editor;
this.pps = pps;

Expand All @@ -69,7 +69,7 @@ public void preferencesChanged() {
pps.registerListener(errorHandlerListener);
} else {
pps.unregisterListener(errorHandlerListener);
editor.setProblemList(Collections.emptyList());
editor.accept(Collections.emptyList());
nextUiUpdate = 0;
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ private void handleSketchProblems(PreprocSketch ps) {
long delay = nextUiUpdate - System.currentTimeMillis();
Runnable uiUpdater = () -> {
if (nextUiUpdate > 0 && System.currentTimeMillis() >= nextUiUpdate) {
EventQueue.invokeLater(() -> editor.setProblemList(problems));
EventQueue.invokeLater(() -> editor.accept(problems));
}
};
scheduledUiUpdate =
Expand Down
4 changes: 2 additions & 2 deletions java/src/processing/mode/java/JavaEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected JavaEditor(Base base, String path, EditorState state,
box.add(textAndError);
*/

preprocService = new PreprocService(this);
preprocService = new PreprocService(this.jmode, this.sketch);

// long t5 = System.currentTimeMillis();

Expand All @@ -141,7 +141,7 @@ protected JavaEditor(Base base, String path, EditorState state,
astViewer = new ASTViewer(this, preprocService);
}

errorChecker = new ErrorChecker(this, preprocService);
errorChecker = new ErrorChecker(this::setProblemList, preprocService);

// long t7 = System.currentTimeMillis();

Expand Down
2 changes: 1 addition & 1 deletion java/src/processing/mode/java/JavaTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ protected void fetchPhrase() {
}


protected static String parsePhrase(final String lineText) {
public static String parsePhrase(final String lineText) {
boolean overloading = false;

{ // Check if we can provide suggestions for this phrase ending
Expand Down
15 changes: 8 additions & 7 deletions java/src/processing/mode/java/PreprocService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public class PreprocService {
private final static int TIMEOUT_MILLIS = 100;
private final static int BLOCKING_TIMEOUT_SECONDS = 3000;

protected final JavaEditor editor;
protected final JavaMode javaMode;
protected final Sketch sketch;

protected final ASTParser parser = ASTParser.newParser(AST.JLS11);

Expand All @@ -104,8 +105,9 @@ public class PreprocService {
* Create a new preprocessing service to support an editor.
* @param editor The editor supported by this service and receives issues.
*/
public PreprocService(JavaEditor editor) {
this.editor = editor;
public PreprocService(JavaMode javaMode, Sketch sketch) {
this.javaMode = javaMode;
this.sketch = sketch;

// Register listeners for first run
whenDone(this::fireListeners);
Expand Down Expand Up @@ -342,8 +344,7 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) {
List<ImportStatement> codeFolderImports = result.codeFolderImports;
List<ImportStatement> programImports = result.programImports;

JavaMode javaMode = (JavaMode) editor.getMode();
Sketch sketch = result.sketch = editor.getSketch();
result.sketch = this.sketch;
String className = sketch.getMainName();

StringBuilder workBuffer = new StringBuilder();
Expand Down Expand Up @@ -385,7 +386,7 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) {

// Core and default imports
PdePreprocessor preProcessor =
editor.createPreprocessor(editor.getSketch().getMainName());
PdePreprocessor.builderFor(this.sketch.getName()).build();
if (coreAndDefaultImports == null) {
coreAndDefaultImports = buildCoreAndDefaultImports(preProcessor);
}
Expand Down Expand Up @@ -421,7 +422,7 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) {
final int endNumLines = numLines;

preprocessorResult.getPreprocessIssues().stream()
.map((x) -> ProblemFactory.build(x, tabLineStarts, endNumLines, editor))
.map((x) -> ProblemFactory.build(x, tabLineStarts))
.forEach(result.otherProblems::add);

result.hasSyntaxErrors = true;
Expand Down
26 changes: 26 additions & 0 deletions java/src/processing/mode/java/languageServer/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package processing.mode.java.languageServer;

import org.eclipse.lsp4j.launch.LSPLauncher;
import java.io.File;
import java.net.ServerSocket;
import java.io.InputStream;
import java.io.OutputStream;

public class App {
public static void main(String[] args) {
var input = System.in;
var output = System.out;
System.setOut(System.err);

var server = new ProcessingLanguageServer();
var launcher =
LSPLauncher.createServerLauncher(
server,
input,
output
);
var client = launcher.getRemoteProxy();
server.connect(client);
launcher.startListening();
}
}
Loading