File: LanguageServerConfig.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 (84 lines) | stat: -rw-r--r-- 2,333 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
#include "LanguageServerConfig.h"
#include <algorithm>
#include <NodeJSLocator.h>

LanguageServerConfig::LanguageServerConfig()
    : clConfigItem("LSPConfig")
{
    NodeJSLocator locator;
    locator.Locate();
}

LanguageServerConfig::~LanguageServerConfig() {}

LanguageServerConfig& LanguageServerConfig::Load()
{
    clConfig conf("LanguageServer.conf");
    conf.ReadItem(this);
    return *this;
}

LanguageServerConfig& LanguageServerConfig::Save()
{
    clConfig conf("LanguageServer.conf");
    conf.WriteItem(this);
    return *this;
}

LanguageServerConfig& LanguageServerConfig::Get()
{
    static LanguageServerConfig config;
    return config;
}

void LanguageServerConfig::FromJSON(const JSONItem& json)
{
    m_servers.clear();
    m_flags = json.namedObject("flags").toSize_t(m_flags);
    if(json.hasNamedObject("servers")) {
        JSONItem servers = json.namedObject("servers");
        size_t count = servers.arraySize();
        for(size_t i = 0; i < count; ++i) {
            JSONItem server = servers.arrayItem(i);
            LanguageServerEntry entry;
            entry.FromJSON(server);
            m_servers.insert({ entry.GetName(), entry });
        }
    }
}

JSONItem LanguageServerConfig::ToJSON() const
{
    JSONItem json = JSONItem::createObject(GetName());
    json.addProperty("flags", m_flags);
    JSONItem servers = JSONItem::createArray("servers");
    std::for_each(m_servers.begin(), m_servers.end(),
                  [&](const LanguageServerEntry::Map_t::value_type& vt) { servers.append(vt.second.ToJSON()); });
    json.append(servers);
    return json;
}

void LanguageServerConfig::AddServer(const LanguageServerEntry& server)
{
    RemoveServer(server.GetName());
    m_servers.insert({ server.GetName(), server });
}

void LanguageServerConfig::RemoveServer(const wxString& name)
{
    if(m_servers.count(name)) { m_servers.erase(name); }
}

const LanguageServerEntry& LanguageServerConfig::GetServer(const wxString& name) const
{
    static LanguageServerEntry NullEntry;
    if(m_servers.count(name) == 0) { return NullEntry; }
    return m_servers.find(name)->second;
}

LanguageServerEntry& LanguageServerConfig::GetServer(const wxString& name)
{
    static LanguageServerEntry NullEntry;
    if(m_servers.count(name) == 0) { return NullEntry; }
    return m_servers[name];
}