Debian Codegraph @

LanguageServer/LSPPythonDetector.cpp

raw
1 #include "LSPPythonDetector.hpp"
2
3 #include "Platform.hpp"
4 #include "asyncprocess.h"
5 #include "file_logger.h"
6 #include "globals.h"
7 #include "procutils.h"
8 #include "wx/filename.h"
9
10 #include <cstdlib>
11
12 LSPPythonDetector::LSPPythonDetector()
13 : LSPDetector("python")
14 {
15 }
16
17 LSPPythonDetector::~LSPPythonDetector() {}
18
19 bool LSPPythonDetector::DoLocate()
20 {
21 wxString python;
22
23 // locate python3
24 if(!ThePlatform->Which("python", &python) && !ThePlatform->Which("python3", &python)) {
25 return false;
26 }
27
28 // Check if python-language-server is installed
29 wxString output = ProcUtils::GrepCommandOutput({ python, "-m", "pip", "list" }, "python-lsp-server");
30 if(output.empty()) {
31 // Not installed
32 return false;
33 }
34
35 // We have it installed
36 wxString command;
37 ::WrapWithQuotes(python);
38
39 command << python << " -m pylsp";
40 SetCommand(command);
41 // Add support for the languages
42 GetLangugaes().Add("python");
43 SetConnectionString("stdio");
44 SetPriority(50);
45 return true;
46 }