Skip to content

Commit ac062a5

Browse files
committed
Implementation language server
1 parent 58ff6a3 commit ac062a5

17 files changed

+712
-21
lines changed

app/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@
182182

183183
<!--
184184
<antcall target="download-ant" />
185-
<antcall target="download-flatlaf" />
186185
<antcall target="download-jna" />
186+
<antcall target="download-flatlaf" />
187187
-->
188188
</target>
189189

app/processing4-app.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@
6565
</library>
6666
</orderEntry>
6767
</component>
68-
</module>
68+
</module>

build/build.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@
377377
<include name="theme/**" />
378378
</fileset>
379379
</copy>
380+
<copy todir="${target.path}/modes/java/mode" preservelastmodified="true">
381+
<fileset dir="../java/lib">
382+
<include name="**/*.jar" />
383+
</fileset>
384+
</copy>
380385

381386
<!-- get the examples folder, but don't require it to buid -->
382387
<copy todir="${target.path}/modes/java/examples"

java/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ bin
33
bin-test
44
generated
55
mode/JavaMode.jar
6+
ivy.jar

java/build.xml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<project name="Java Mode" default="build">
2+
<project name="Java Mode" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
33

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

21+
<property name="ivy.version" value="2.5.0" />
22+
<fileset id="ivy.files" dir="lib">
23+
<include name="ivy.jar" />
24+
</fileset>
25+
<property name="ivy.url"
26+
value="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" />
27+
28+
<available file="ivy.jar" property="ivy.present" />
29+
30+
<condition property="ivy.ignorable" value="false" else="true">
31+
<isset property="ivy.present" />
32+
</condition>
33+
34+
<target name="download-ivy" unless="ivy.present">
35+
<get src="${ivy.url}" dest="ivy.jar"
36+
ignoreerrors="${ivy.ignorable}"
37+
usetimestamp="true" />
38+
</target>
39+
40+
<target name="init-ivy" depends="download-ivy">
41+
<taskdef resource="org/apache/ivy/ant/antlib.xml"
42+
uri="antlib:org.apache.ivy.ant" classpath="ivy.jar"/>
43+
</target>
44+
45+
<target name="download-ivy-dependencies" depends="init-ivy">
46+
<ivy:retrieve />
47+
</target>
48+
2149
<target name="clean" description="Clean the build directories">
2250
<delete dir="bin" />
2351
<delete dir="bin-test" />
@@ -32,6 +60,11 @@
3260
<include name="*.properties" />
3361
</fileset>
3462
</delete>
63+
<delete>
64+
<fileset dir="lib">
65+
<include name="*.jar" />
66+
</fileset>
67+
</delete>
3568
</target>
3669

3770
<target name="preproc" description="Compile ANTLR 4 grammar">
@@ -71,6 +104,8 @@
71104
<pathelement location="mode/org.eclipse.jdt.core.jar" />
72105
<pathelement location="mode/org.eclipse.osgi.jar" />
73106
<pathelement location="mode/org.eclipse.text.jar" />
107+
<pathelement location="mode/org.eclipse.ui.workbench.jar" />
108+
<fileset dir="lib" includes="*.jar" />
74109
</path>
75110

76111
<path id="classpath.test">
@@ -123,7 +158,7 @@
123158
</sequential>
124159
</macrodef>
125160

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

@@ -140,7 +175,7 @@
140175
</junit>
141176
</target>
142177

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

java/ivy.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ivy-module version="2.0">
3+
<info organisation="" module="" />
4+
<dependencies>
5+
<dependency org="org.eclipse.lsp4j" name="org.eclipse.lsp4j" rev="0.12.0"/>
6+
</dependencies>
7+
</ivy-module>

java/lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.jar

java/src/processing/mode/java/CompletionGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ public List<CompletionCandidate> preparePredictions(final PreprocSketch ps,
17621762
}
17631763

17641764

1765-
protected static DefaultListModel<CompletionCandidate> filterPredictions(List<CompletionCandidate> candidates) {
1765+
public static DefaultListModel<CompletionCandidate> filterPredictions(List<CompletionCandidate> candidates) {
17661766
Messages.log("* filterPredictions");
17671767
DefaultListModel<CompletionCandidate> defListModel = new DefaultListModel<>();
17681768
if (candidates.isEmpty())

java/src/processing/mode/java/ErrorChecker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import processing.app.Problem;
2929

3030

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

44-
final private JavaEditor editor;
44+
final private Consumer<List<Problem>> editor;
4545
final private PreprocService pps;
4646

4747

48-
public ErrorChecker(JavaEditor editor, PreprocService pps) {
48+
public ErrorChecker(Consumer<List<Problem>> editor, PreprocService pps) {
4949
this.editor = editor;
5050
this.pps = pps;
5151

@@ -69,7 +69,7 @@ public void preferencesChanged() {
6969
pps.registerListener(errorHandlerListener);
7070
} else {
7171
pps.unregisterListener(errorHandlerListener);
72-
editor.setProblemList(Collections.emptyList());
72+
editor.accept(Collections.emptyList());
7373
nextUiUpdate = 0;
7474
}
7575
}
@@ -136,7 +136,7 @@ private void handleSketchProblems(PreprocSketch ps) {
136136
long delay = nextUiUpdate - System.currentTimeMillis();
137137
Runnable uiUpdater = () -> {
138138
if (nextUiUpdate > 0 && System.currentTimeMillis() >= nextUiUpdate) {
139-
EventQueue.invokeLater(() -> editor.setProblemList(problems));
139+
EventQueue.invokeLater(() -> editor.accept(problems));
140140
}
141141
};
142142
scheduledUiUpdate =

java/src/processing/mode/java/JavaEditor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected JavaEditor(Base base, String path, EditorState state,
129129
box.add(textAndError);
130130
*/
131131

132-
preprocService = new PreprocService(this);
132+
preprocService = new PreprocService(this.jmode, this.sketch);
133133

134134
// long t5 = System.currentTimeMillis();
135135

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

144-
errorChecker = new ErrorChecker(this, preprocService);
144+
errorChecker = new ErrorChecker(this::setProblemList, preprocService);
145145

146146
// long t7 = System.currentTimeMillis();
147147

java/src/processing/mode/java/JavaTextArea.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ protected void fetchPhrase() {
341341
}
342342

343343

344-
protected static String parsePhrase(final String lineText) {
344+
public static String parsePhrase(final String lineText) {
345345
boolean overloading = false;
346346

347347
{ // Check if we can provide suggestions for this phrase ending

java/src/processing/mode/java/PreprocService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public class PreprocService {
7878
private final static int TIMEOUT_MILLIS = 100;
7979
private final static int BLOCKING_TIMEOUT_SECONDS = 3000;
8080

81-
protected final JavaEditor editor;
81+
protected final JavaMode javaMode;
82+
protected final Sketch sketch;
8283

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

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

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

345-
JavaMode javaMode = (JavaMode) editor.getMode();
346-
Sketch sketch = result.sketch = editor.getSketch();
347+
result.sketch = this.sketch;
347348
String className = sketch.getMainName();
348349

349350
StringBuilder workBuffer = new StringBuilder();
@@ -385,7 +386,7 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) {
385386

386387
// Core and default imports
387388
PdePreprocessor preProcessor =
388-
editor.createPreprocessor(editor.getSketch().getMainName());
389+
PdePreprocessor.builderFor(this.sketch.getName()).build();
389390
if (coreAndDefaultImports == null) {
390391
coreAndDefaultImports = buildCoreAndDefaultImports(preProcessor);
391392
}
@@ -421,7 +422,7 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) {
421422
final int endNumLines = numLines;
422423

423424
preprocessorResult.getPreprocessIssues().stream()
424-
.map((x) -> ProblemFactory.build(x, tabLineStarts, endNumLines, editor))
425+
.map((x) -> ProblemFactory.build(x, tabLineStarts))
425426
.forEach(result.otherProblems::add);
426427

427428
result.hasSyntaxErrors = true;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package processing.mode.java.languageServer;
2+
3+
import org.eclipse.lsp4j.launch.LSPLauncher;
4+
import java.io.File;
5+
import java.net.ServerSocket;
6+
import java.io.InputStream;
7+
import java.io.OutputStream;
8+
9+
public class App {
10+
public static void main(String[] args) {
11+
var input = System.in;
12+
var output = System.out;
13+
System.setOut(System.err);
14+
15+
var server = new ProcessingLanguageServer();
16+
var launcher =
17+
LSPLauncher.createServerLauncher(
18+
server,
19+
input,
20+
output
21+
);
22+
var client = launcher.getRemoteProxy();
23+
server.connect(client);
24+
launcher.startListening();
25+
}
26+
}

0 commit comments

Comments
 (0)