| 1 |
#include "LanguageServerEntry.h" |
| 2 |
|
| 3 |
#include "LanguageServerProtocol.h" |
| 4 |
#include "StringUtils.h" |
| 5 |
#include "globals.h" |
| 6 |
|
| 7 |
LanguageServerEntry::LanguageServerEntry() |
| 8 |
: m_connectionString("stdio") |
| 9 |
{ |
| 10 |
} |
| 11 |
|
| 12 |
LanguageServerEntry::~LanguageServerEntry() {} |
| 13 |
|
| 14 |
void LanguageServerEntry::FromJSON(const JSONItem& json) |
| 15 |
{ |
| 16 |
m_name = json.namedObject("name").toString(); |
| 17 |
m_exepath = json.namedObject("exepath").toString(); |
| 18 |
m_args = json.namedObject("args").toString(); |
| 19 |
m_workingDirectory = json.namedObject("workingDirectory").toString(); |
| 20 |
m_languages = json.namedObject("languages").toArrayString(); |
| 21 |
m_enabled = json.namedObject("enabled").toBool(m_enabled); |
| 22 |
m_connectionString = json.namedObject("connectionString").toString("stdio"); |
| 23 |
m_priority = json.namedObject("priority").toInt(m_priority); |
| 24 |
m_disaplayDiagnostics = json.namedObject("displayDiagnostics").toBool(m_disaplayDiagnostics); // defaults to true |
| 25 |
|
| 26 |
// we no longer are using exepath + args, instead a single "command" is used |
| 27 |
wxString commandDefault = m_exepath; |
| 28 |
if(!commandDefault.IsEmpty()) { |
| 29 |
::WrapWithQuotes(commandDefault); |
| 30 |
if(!m_args.empty()) { |
| 31 |
commandDefault << " " << m_args; |
| 32 |
} |
| 33 |
} |
| 34 |
m_command = json.namedObject("command").toString(commandDefault); |
| 35 |
} |
| 36 |
|
| 37 |
JSONItem LanguageServerEntry::ToJSON() const |
| 38 |
{ |
| 39 |
JSONItem json = JSONItem::createObject(); |
| 40 |
json.addProperty("name", m_name); |
| 41 |
json.addProperty("exepath", m_exepath); |
| 42 |
json.addProperty("args", m_args); |
| 43 |
json.addProperty("languages", m_languages); |
| 44 |
json.addProperty("enabled", m_enabled); |
| 45 |
json.addProperty("workingDirectory", m_workingDirectory); |
| 46 |
json.addProperty("connectionString", m_connectionString); |
| 47 |
json.addProperty("priority", m_priority); |
| 48 |
json.addProperty("displayDiagnostics", m_disaplayDiagnostics); |
| 49 |
json.addProperty("command", m_command); |
| 50 |
return json; |
| 51 |
} |
| 52 |
|
| 53 |
eNetworkType LanguageServerEntry::GetNetType() const |
| 54 |
{ |
| 55 |
wxString connectionString = GetConnectionString(); |
| 56 |
connectionString.Trim().Trim(false); |
| 57 |
if(connectionString.CmpNoCase("stdio") == 0) { |
| 58 |
return eNetworkType::kStdio; |
| 59 |
} else { |
| 60 |
return eNetworkType::kTcpIP; |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
bool LanguageServerEntry::IsValid() const |
| 65 |
{ |
| 66 |
if(m_name.IsEmpty()) { |
| 67 |
return false; |
| 68 |
} |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
bool LanguageServerEntry::IsAutoRestart() const |
| 73 |
{ |
| 74 |
wxString command = GetCommand(); |
| 75 |
command.Trim().Trim(false); |
| 76 |
return !command.IsEmpty(); |
| 77 |
} |
| 78 |
|
| 79 |
wxString LanguageServerEntry::GetCommand(bool pretty) const |
| 80 |
{ |
| 81 |
auto cmd_arr = StringUtils::BuildCommandArrayFromString(m_command); |
| 82 |
return StringUtils::BuildCommandStringFromArray(cmd_arr, |
| 83 |
pretty ? StringUtils::WITH_COMMENT_PREFIX : StringUtils::ONE_LINER); |
| 84 |
} |
| 85 |
|
| 86 |
void LanguageServerEntry::SetCommand(const wxString& command) |
| 87 |
{ |
| 88 |
auto cmd_arr = StringUtils::BuildCommandArrayFromString(command); |
| 89 |
m_command = StringUtils::BuildCommandStringFromArray(cmd_arr); |
| 90 |
} |