@@ -59,30 +59,32 @@ class PdeAdapter {
5959 PdeAdapter (File rootPath , LanguageClient client ) {
6060 this .rootPath = rootPath ;
6161 this .client = client ;
62- this .javaMode = (JavaMode ) ModeContribution
63- .load (
64- null ,
65- Platform .getContentFile ("modes/java" ),
66- "processing.mode.java.JavaMode"
67- )
68- .getMode ();
69- this .pdeFile = new File (rootPath , rootPath .getName () + ".pde" );
70- this .sketch = new Sketch (pdeFile .toString (), javaMode );
71- this .completionGenerator = new CompletionGenerator (javaMode );
72- this .preprocService = new PreprocService (javaMode , sketch );
73- this .errorChecker = new ErrorChecker (
74- this ::updateProblems ,
75- preprocService
76- );
77- this .cps = CompletableFutures .computeAsync (_x -> {
62+
63+ File location = Platform .getContentFile ("modes/java" );
64+ ModeContribution mc =
65+ ModeContribution .load (null , location , JavaMode .class .getName ());
66+ if (mc == null ) {
67+ // Shouldn't be possible but IntelliJ is complaining about it,
68+ // and we may run into path issues when running externally [fry 221126]
69+ throw new RuntimeException ("Could not load Java Mode from " + location );
70+ }
71+ javaMode = (JavaMode ) mc .getMode ();
72+
73+ pdeFile = new File (rootPath , rootPath .getName () + ".pde" );
74+ sketch = new Sketch (pdeFile .toString (), javaMode );
75+ completionGenerator = new CompletionGenerator (javaMode );
76+ preprocService = new PreprocService (javaMode , sketch );
77+ errorChecker = new ErrorChecker (this ::updateProblems , preprocService );
78+ cps = CompletableFutures .computeAsync (_x -> {
7879 throw new RuntimeException ("unreachable" );
7980 });
80- this . suggestionGenerator = new CompletionGenerator (this . javaMode );
81-
82- this . notifySketchChanged ();
81+ suggestionGenerator = new CompletionGenerator (javaMode );
82+
83+ notifySketchChanged ();
8384 }
8485
85- static Optional <File > uriToPath (URI uri ) {
86+
87+ static Optional <File > uriToPath (URI uri ) {
8688 try {
8789 return Optional .of (new File (uri ));
8890 } catch (Exception e ) {
@@ -124,8 +126,8 @@ Optional<SketchCode> findCodeByUri(URI uri) {
124126 );
125127 }
126128
127- void updateProblems (List <Problem > probs ) {
128- Map <URI , List <Diagnostic >> dias = probs .stream ()
129+ void updateProblems (List <Problem > problems ) {
130+ Map <URI , List <Diagnostic >> dias = problems .stream ()
129131 .map (prob -> {
130132 SketchCode code = sketch .getCode (prob .getTabIndex ());
131133 Diagnostic dia = new Diagnostic (
@@ -191,14 +193,18 @@ CompletionItem convertCompletionCandidate(CompletionCandidate c) {
191193 } else if (insert .contains ("," )) {
192194 int n = 1 ;
193195 char [] chs = insert .replace ("(," , "($1," ).toCharArray ();
194- insert = "" ;
196+ //insert = "";
197+ StringBuilder newInsert = new StringBuilder ();
195198 for (char ch : chs ) {
196199 if (ch == ',' ) {
197200 n += 1 ;
198- insert += ",$" + n ;
201+ //insert += ",$" + n;
202+ newInsert .append (",$" ).append (n );
199203 }
200- insert += ch ;
204+ //insert += ch;
205+ newInsert .append (ch );
201206 }
207+ insert = newInsert .toString ();
202208 }
203209 item .setInsertText (insert );
204210 CompletionItemKind kind = switch (c .getType ()) {
0 commit comments