2727 * #L%
2828 */
2929
30- package org .scijava .plugins .scripting .appose .python . completion ;
30+ package org .scijava .plugins .scripting .appose .python ;
3131
3232import java .io .File ;
3333import java .io .IOException ;
3434import java .util .LinkedHashMap ;
3535import java .util .Map ;
3636import java .util .concurrent .Callable ;
3737
38+ import org .apposed .appose .util .Environments ;
3839import org .scijava .code .lsp .Environment ;
39- import org .scijava .code .lsp .launch .LspConnection ;
40- import org .scijava .code .lsp .launch .LspServerSpec ;
40+ import org .scijava .code .lsp .ServerProcessPlugin ;
41+ import org .scijava .plugin .Parameter ;
42+ import org .scijava .plugin .Plugin ;
43+ import org .scijava .plugins .scripting .appose .python ._internal .ResidentWorkerService ;
4144
4245/**
43- * Starts jedi-language-server, with the Python of a tooling environment, to
44- * analyze scripts against their environment's Python (if known) and extra
45- * search paths (e.g. a dependency overlay).
46+ * Offers jedi-language-server, for {@code python}: run with the Python of a
47+ * tooling environment (see {@link ApposePythonEnvironments}), to analyze
48+ * scripts against their environment's Python (if known) and extra search
49+ * paths (e.g. a dependency overlay). Python scripts run via Appose use it,
50+ * and so do Jython's.
4651 *
4752 * @author Gabriel Selzer
4853 */
49- public class JediLanguageServerSpec implements LspServerSpec {
54+ @ Plugin (type = ServerProcessPlugin .class , name = "jedi-language-server" )
55+ public class JediServerProcessPlugin implements ServerProcessPlugin {
5056
5157 /**
5258 * Runs jedi-language-server, exiting once the given process (this JVM) is
@@ -72,18 +78,30 @@ public class JediLanguageServerSpec implements LspServerSpec {
7278 /** How large the error log may grow before it is started anew, in bytes. */
7379 private static final long MAX_LOG = 5 * 1024 * 1024 ;
7480
81+ @ Parameter
82+ private ResidentWorkerService workers ;
83+
7584 private final Callable <String > python ;
7685 private final File workspace ;
7786 private final File log ;
7887
88+ /** Runs the server in the tooling environment, building it if needed. */
89+ public JediServerProcessPlugin () {
90+ final File envs = new File (Environments .apposeEnvsDir ());
91+ python = () -> ApposePythonEnvironments .toolingPython (workers );
92+ workspace = new File (envs , ApposePythonEnvironments .TOOLING_ENV +
93+ "-workspace" );
94+ log = new File (envs , ApposePythonEnvironments .TOOLING_ENV + "-server.log" );
95+ }
96+
7997 /**
8098 * @param python Gets the Python executable of the environment
8199 * jedi-language-server is installed in (building it, if needed).
82100 * @param workspace An (empty) directory to serve as workspace root.
83101 * @param log Where to append the server's error output.
84102 */
85- public JediLanguageServerSpec (final Callable <String > python ,
86- final File workspace , final File log )
103+ JediServerProcessPlugin (final Callable <String > python , final File workspace ,
104+ final File log )
87105 {
88106 this .python = python ;
89107 this .workspace = workspace ;
@@ -96,7 +114,7 @@ public String languageId() {
96114 }
97115
98116 @ Override
99- public LspConnection start (final Environment env )
117+ public Process start (final Environment env )
100118 throws IOException
101119 {
102120 final String exe ;
@@ -116,7 +134,7 @@ public LspConnection start(final Environment env)
116134 final ProcessBuilder pb = new ProcessBuilder (exe , "-c" , LAUNCHER , String
117135 .valueOf (ProcessHandle .current ().pid ()));
118136 pb .redirectError (ProcessBuilder .Redirect .appendTo (log ));
119- return LspConnection . of ( pb .start () );
137+ return pb .start ();
120138 }
121139
122140 @ Override
0 commit comments