Repository navigation
Expand file tree
/
Copy pathPythonLspClient.java
More file actions
48 lines (44 loc) · 1.63 KB
/
Copy pathPythonLspClient.java
File metadata and controls
48 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package org.netbeans.modules.python;
/**
*
*/
import java.io.IOException;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.api.project.Project;
import org.netbeans.modules.lsp.client.spi.LanguageServerProvider;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
@MimeRegistration(mimeType = PythonUtility.PYTHON_MIME_TYPE,
service = LanguageServerProvider.class)
public class PythonLspClient implements LanguageServerProvider {
@Override
public LanguageServerDescription startServer(Lookup lkp) {
try {
Process p = new ProcessBuilder(
PythonUtility.getLspPythonExe(),
"-m",
"pylsp",
"--verbose",
"--log-file",
PythonUtility.PYLSP_VENV_DIR.toPath().resolve("lsp_log_file").toString()
//,
//"-v"
)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start();
LanguageServerDescription description = LanguageServerDescription.create(p.getInputStream(),
p.getOutputStream(), p
);
try {
PythonLspConfiguration.serverStarted(lkp.lookup(Project.class), description);
} catch (RuntimeException | LinkageError ex) {
// The server still works, only without the project's interpreter.
Exceptions.printStackTrace(ex);
}
return description;
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
}