File: LanguageServerEntry.cpp

package info (click to toggle)
codelite 14.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (90 lines) | stat: -rw-r--r-- 3,028 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "LanguageServerEntry.h"
#include "LanguageServerProtocol.h"
#include "globals.h"

LanguageServerEntry::LanguageServerEntry()
    : m_connectionString("stdio")
{
}

LanguageServerEntry::~LanguageServerEntry() {}

void LanguageServerEntry::FromJSON(const JSONItem& json)
{
    m_name = json.namedObject("name").toString();
    m_exepath = json.namedObject("exepath").toString();
    m_args = json.namedObject("args").toString();
    m_workingDirectory = json.namedObject("workingDirectory").toString();
    m_languages = json.namedObject("languages").toArrayString();
    m_enabled = json.namedObject("enabled").toBool(m_enabled);
    m_connectionString = json.namedObject("connectionString").toString("stdio");
    m_priority = json.namedObject("priority").toInt(m_priority);
    m_disaplayDiagnostics = json.namedObject("displayDiagnostics").toBool(m_disaplayDiagnostics); // defaults to true

    // we no longer are using exepath + args, instead a single "command" is used
    wxString commandDefault = m_exepath;
    if(!commandDefault.IsEmpty()) {
        ::WrapWithQuotes(commandDefault);
        if(!m_args.empty()) { commandDefault << " " << m_args; }
    }
    m_command = json.namedObject("command").toString(commandDefault);
    m_unimplementedMethods.clear();
    wxArrayString methods = json.namedObject("unimplementedMethods").toArrayString();
    for(const wxString& methodName : methods) {
        m_unimplementedMethods.insert(methodName);
    }
}

JSONItem LanguageServerEntry::ToJSON() const
{
    JSONItem json = JSONItem::createObject();
    json.addProperty("name", m_name);
    json.addProperty("exepath", m_exepath);
    json.addProperty("args", m_args);
    json.addProperty("languages", m_languages);
    json.addProperty("enabled", m_enabled);
    json.addProperty("workingDirectory", m_workingDirectory);
    json.addProperty("connectionString", m_connectionString);
    json.addProperty("priority", m_priority);
    json.addProperty("displayDiagnostics", m_disaplayDiagnostics);
    json.addProperty("command", m_command);

    wxArrayString methods;
    methods.Alloc(m_unimplementedMethods.size());
    for(const wxString& methodName : m_unimplementedMethods) {
        methods.Add(methodName);
    }

    json.addProperty("unimplementedMethods", methods);
    return json;
}

eNetworkType LanguageServerEntry::GetNetType() const
{
    wxString connectionString = GetConnectionString();
    connectionString.Trim().Trim(false);
    if(connectionString.CmpNoCase("stdio") == 0) {
        return eNetworkType::kStdio;
    } else {
        return eNetworkType::kTcpIP;
    }
}

bool LanguageServerEntry::IsValid() const
{
    bool is_valid = true;
    if(m_name.IsEmpty()) { return false; }
    return true;
}

void LanguageServerEntry::AddUnImplementedMethod(const wxString& methodName)
{
    m_unimplementedMethods.insert(methodName);
}

bool LanguageServerEntry::IsAutoRestart() const
{
    wxString command = GetCommand();
    command.Trim().Trim(false);
    return !command.IsEmpty();
}