Skip to content

Commit

Permalink
LSP plugin: use native notebook to display the existing language servers
Browse files Browse the repository at this point in the history
  • Loading branch information
eranif committed May 31, 2024
1 parent bc0c391 commit 68b85e8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 52 deletions.
22 changes: 10 additions & 12 deletions LanguageServer/LanguageServerPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
#include "ColoursAndFontsManager.h"
#include "JSON.h"
#include "LSP/LanguageServerProtocol.h"
#include "StringUtils.h"
#include "globals.h"

#include <algorithm>
#include <macros.h>
#include <wx/choicdlg.h>
#include <wx/dirdlg.h>
Expand All @@ -15,8 +12,9 @@
LanguageServerPage::LanguageServerPage(wxWindow* parent, const LanguageServerEntry& data)
: LanguageServerPageBase(parent)
{
Hide();
LexerConf::Ptr_t lex = ColoursAndFontsManager::Get().GetLexer("text");
if(lex) {
if (lex) {
lex->ApplySystemColours(m_stcCommand);
lex->ApplySystemColours(m_stcInitOptions);
}
Expand All @@ -39,7 +37,7 @@ LanguageServerPage::LanguageServerPage(wxWindow* parent)
: LanguageServerPageBase(parent)
{
LexerConf::Ptr_t lex = ColoursAndFontsManager::Get().GetLexer("text");
if(lex) {
if (lex) {
lex->ApplySystemColours(m_stcCommand);
lex->ApplySystemColours(m_stcInitOptions);
}
Expand Down Expand Up @@ -74,19 +72,19 @@ void LanguageServerPage::OnSuggestLanguages(wxCommandEvent& event)
{
const std::set<wxString>& langSet = LanguageServerProtocol::GetSupportedLanguages();
wxArrayString arrLang;
for(const wxString& lang : langSet) {
for (const wxString& lang : langSet) {
arrLang.Add(lang);
}

wxArrayInt selections;
int count = ::wxGetSelectedChoices(selections, _("Select the supported languages by this server:"), _("CodeLite"),
arrLang, GetParent());
if(count == wxNOT_FOUND) {
if (count == wxNOT_FOUND) {
return;
}

wxString newText;
for(int sel : selections) {
for (int sel : selections) {
newText << arrLang.Item(sel) << ";";
}
m_textCtrlLanguages->ChangeValue(newText);
Expand All @@ -98,7 +96,7 @@ void LanguageServerPage::OnBrowseWD(wxCommandEvent& event)
wxString path(m_textCtrlWD->GetValue());
wxString new_path =
wxDirSelector(_("Select a working directory:"), path, wxDD_DEFAULT_STYLE, wxDefaultPosition, this);
if(new_path.IsEmpty() == false) {
if (new_path.IsEmpty() == false) {
m_textCtrlWD->SetValue(new_path);
}
}
Expand All @@ -109,17 +107,17 @@ bool LanguageServerPage::ValidateData(wxString* message) const
wxString init_options = m_stcInitOptions->GetText();
init_options.Trim().Trim(false);

if(init_options.empty()) {
if (init_options.empty()) {
return true;
}

JSON root{ init_options };
if(!root.isOk()) {
if (!root.isOk()) {
(*message) << m_textCtrlName->GetValue() << ": invalid JSON input in `initializationOptions`";
return false;
}

if(!root.toElement().isObject()) {
if (!root.toElement().isObject()) {
(*message) << m_textCtrlName->GetValue() << ": `initializationOptions` must be a JSON object";
return false;
}
Expand Down
31 changes: 16 additions & 15 deletions LanguageServer/LanguageServerSettingsDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LanguageServerSettingsDlg::LanguageServerSettingsDlg(wxWindow* parent, bool trig
{
DoInitialize();
::clSetDialogBestSizeAndPosition(this);
if(m_scanOnStartup) {
if (m_scanOnStartup) {
CallAfter(&LanguageServerSettingsDlg::DoScan);
}
}
Expand All @@ -29,7 +29,8 @@ LanguageServerSettingsDlg::~LanguageServerSettingsDlg() {}
void LanguageServerSettingsDlg::OnAddServer(wxCommandEvent& event)
{
NewLanguageServerDlg dlg(this);
if(dlg.ShowModal() == wxID_OK) {
if (dlg.ShowModal() == wxID_OK) {
wxWindowUpdateLocker lk{ m_notebook };
LanguageServerEntry server = dlg.GetData();
// Update the configuration
LanguageServerConfig::Get().AddServer(server);
Expand All @@ -40,7 +41,7 @@ void LanguageServerSettingsDlg::OnAddServer(wxCommandEvent& event)
void LanguageServerSettingsDlg::Save()
{
LanguageServerConfig& conf = LanguageServerConfig::Get();
for(size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
LanguageServerPage* page = dynamic_cast<LanguageServerPage*>(m_notebook->GetPage(i));
conf.AddServer(page->GetData());
}
Expand All @@ -51,13 +52,13 @@ void LanguageServerSettingsDlg::Save()
void LanguageServerSettingsDlg::OnDeleteLSP(wxCommandEvent& event)
{
int sel = m_notebook->GetSelection();
if(sel == wxNOT_FOUND) {
if (sel == wxNOT_FOUND) {
return;
}
wxString serverName = m_notebook->GetPageText(sel);

if(::wxMessageBox(wxString() << _("Are you sure you want to delete '") << serverName << "' ?", "CodeLite",
wxICON_QUESTION | wxCENTRE | wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT, this) != wxYES) {
if (::wxMessageBox(wxString() << _("Are you sure you want to delete '") << serverName << "' ?", "CodeLite",
wxICON_QUESTION | wxCENTRE | wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT, this) != wxYES) {
return;
}
LanguageServerConfig::Get().RemoveServer(serverName);
Expand All @@ -70,19 +71,19 @@ void LanguageServerSettingsDlg::OnOKUI(wxUpdateUIEvent& event) { event.Enable(tr
void LanguageServerSettingsDlg::OnScan(wxCommandEvent& event)
{
event.Skip();
if(::wxMessageBox(_("This will reconfigure your language servers\nContinue?"), "CodeLite",
wxICON_QUESTION | wxYES_NO | wxCANCEL | wxYES_DEFAULT) != wxYES) {
if (::wxMessageBox(_("This will reconfigure your language servers\nContinue?"), "CodeLite",
wxICON_QUESTION | wxYES_NO | wxCANCEL | wxYES_DEFAULT) != wxYES) {
return;
}
DoScan();
}

void LanguageServerSettingsDlg::DoInitialize()
{
wxWindowUpdateLocker locker{ this };
wxWindowUpdateLocker locker{ m_notebook };
m_notebook->DeleteAllPages();
const auto& servers = LanguageServerConfig::Get().GetServers();
for(const auto& [name, server] : servers) {
for (const auto& [name, server] : servers) {
m_notebook->AddPage(new LanguageServerPage(m_notebook, server), server.GetName());
}
m_checkBoxEnable->SetValue(LanguageServerConfig::Get().IsEnabled());
Expand All @@ -94,29 +95,29 @@ void LanguageServerSettingsDlg::DoScan()
wxBusyCursor bc;
std::vector<LSPDetector::Ptr_t> matches;
LSPDetectorManager detector;
if(detector.Scan(matches)) {
if (detector.Scan(matches)) {
LanguageServerConfig& conf = LanguageServerConfig::Get();
LanguageServerEntry::Map_t servers;
for(const auto& match : matches) {
for (const auto& match : matches) {
LanguageServerEntry entry;
match->GetLanguageServerEntry(entry);
servers.insert({ entry.GetName(), entry });
}
conf.SetServers(servers);
conf.Save();
DoInitialize();
if(m_scanOnStartup) {
if (m_scanOnStartup) {
m_checkBoxEnable->SetValue(true);
}
}
}
void LanguageServerSettingsDlg::OnButtonOK(wxCommandEvent& event)
{
// validate the data
for(size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
for (size_t i = 0; i < m_notebook->GetPageCount(); ++i) {
LanguageServerPage* page = dynamic_cast<LanguageServerPage*>(m_notebook->GetPage(i));
wxString message;
if(!page->ValidateData(&message)) {
if (!page->ValidateData(&message)) {
::wxMessageBox(message, "CodeLite", wxOK | wxCENTRE | wxICON_WARNING, this);
event.Skip(false);
return;
Expand Down
34 changes: 16 additions & 18 deletions LanguageServer/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LanguageServerSettingsDlgBase::LanguageServerSettingsDlgBase(wxWindow* parent, w
const wxPoint& pos, const wxSize& size, long style)
: wxDialog(parent, id, title, pos, size, style)
{
if(!bBitmapLoaded) {
if (!bBitmapLoaded) {
// We need to initialise the default bitmap handler
wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
wxCrafterCbL3wsInitBitmapResources();
Expand Down Expand Up @@ -58,8 +58,7 @@ LanguageServerSettingsDlgBase::LanguageServerSettingsDlgBase(wxWindow* parent, w

boxSizer2->Add(boxSizer106, 1, wxEXPAND, WXC_FROM_DIP(5));

m_notebook =
new Notebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), kNotebook_FixedWidth);
m_notebook = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), wxBK_DEFAULT);
m_notebook->SetName(wxT("m_notebook"));

boxSizer106->Add(m_notebook, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5));
Expand Down Expand Up @@ -97,10 +96,10 @@ LanguageServerSettingsDlgBase::LanguageServerSettingsDlgBase(wxWindow* parent, w

SetName(wxT("LanguageServerSettingsDlgBase"));
SetSize(wxDLG_UNIT(this, wxSize(-1, -1)));
if(GetSizer()) {
if (GetSizer()) {
GetSizer()->Fit(this);
}
if(GetParent()) {
if (GetParent()) {
CentreOnParent(wxBOTH);
} else {
CentreOnScreen(wxBOTH);
Expand Down Expand Up @@ -128,7 +127,7 @@ LanguageServerPageBase::LanguageServerPageBase(wxWindow* parent, wxWindowID id,
long style)
: wxPanel(parent, id, pos, size, style)
{
if(!bBitmapLoaded) {
if (!bBitmapLoaded) {
// We need to initialise the default bitmap handler
wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
wxCrafterCbL3wsInitBitmapResources();
Expand Down Expand Up @@ -178,8 +177,7 @@ LanguageServerPageBase::LanguageServerPageBase(wxWindow* parent, wxWindowID id,

flexGridSizer432->Add(boxSizer200, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5));

m_notebook201 = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)),
wxNB_FIXEDWIDTH | wxBK_DEFAULT);
m_notebook201 = new wxNotebook(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), wxBK_DEFAULT);
m_notebook201->SetName(wxT("m_notebook201"));

boxSizer200->Add(m_notebook201, 1, wxALL | wxEXPAND, WXC_FROM_DIP(5));
Expand Down Expand Up @@ -353,7 +351,7 @@ LanguageServerPageBase::LanguageServerPageBase(wxWindow* parent, wxWindowID id,

SetName(wxT("LanguageServerPageBase"));
SetSize(wxDLG_UNIT(this, wxSize(-1, -1)));
if(GetSizer()) {
if (GetSizer()) {
GetSizer()->Fit(this);
}
// Connect events
Expand All @@ -373,7 +371,7 @@ NewLanguageServerDlgBase::NewLanguageServerDlgBase(wxWindow* parent, wxWindowID
const wxPoint& pos, const wxSize& size, long style)
: wxDialog(parent, id, title, pos, size, style)
{
if(!bBitmapLoaded) {
if (!bBitmapLoaded) {
// We need to initialise the default bitmap handler
wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
wxCrafterCbL3wsInitBitmapResources();
Expand All @@ -397,10 +395,10 @@ NewLanguageServerDlgBase::NewLanguageServerDlgBase(wxWindow* parent, wxWindowID

SetName(wxT("NewLanguageServerDlgBase"));
SetSize(wxDLG_UNIT(this, wxSize(-1, -1)));
if(GetSizer()) {
if (GetSizer()) {
GetSizer()->Fit(this);
}
if(GetParent()) {
if (GetParent()) {
CentreOnParent(wxBOTH);
} else {
CentreOnScreen(wxBOTH);
Expand All @@ -418,7 +416,7 @@ LSPOutlineViewDlgBase::LSPOutlineViewDlgBase(wxWindow* parent, wxWindowID id, co
const wxSize& size, long style)
: wxDialog(parent, id, title, pos, size, style)
{
if(!bBitmapLoaded) {
if (!bBitmapLoaded) {
// We need to initialise the default bitmap handler
wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
wxCrafterCbL3wsInitBitmapResources();
Expand Down Expand Up @@ -451,15 +449,15 @@ LSPOutlineViewDlgBase::LSPOutlineViewDlgBase(wxWindow* parent, wxWindowID id, co

SetName(wxT("LSPOutlineViewDlgBase"));
SetSize(wxDLG_UNIT(this, wxSize(500, 300)));
if(GetSizer()) {
if (GetSizer()) {
GetSizer()->Fit(this);
}
if(GetParent()) {
if (GetParent()) {
CentreOnParent(wxBOTH);
} else {
CentreOnScreen(wxBOTH);
}
if(!wxPersistenceManager::Get().Find(this)) {
if (!wxPersistenceManager::Get().Find(this)) {
wxPersistenceManager::Get().RegisterAndRestore(this);
} else {
wxPersistenceManager::Get().Restore(this);
Expand All @@ -485,7 +483,7 @@ LanguageServerLogViewBase::LanguageServerLogViewBase(wxWindow* parent, wxWindowI
const wxSize& size, long style)
: wxPanel(parent, id, pos, size, style)
{
if(!bBitmapLoaded) {
if (!bBitmapLoaded) {
// We need to initialise the default bitmap handler
wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
wxCrafterCbL3wsInitBitmapResources();
Expand Down Expand Up @@ -516,7 +514,7 @@ LanguageServerLogViewBase::LanguageServerLogViewBase(wxWindow* parent, wxWindowI

SetName(wxT("LanguageServerLogViewBase"));
SetSize(wxDLG_UNIT(this, wxSize(500, 300)));
if(GetSizer()) {
if (GetSizer()) {
GetSizer()->Fit(this);
}
}
Expand Down
6 changes: 3 additions & 3 deletions LanguageServer/UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <wx/checkbox.h>
#include <wx/statline.h>
#include <wx/notebook.h>
#include "Notebook.h"
#include <wx/button.h>
#include <wx/panel.h>
#include <wx/stattext.h>
Expand All @@ -31,6 +30,7 @@
#include "clThemedTextCtrl.hpp"
#include <wx/dataview.h>
#include "clTerminalViewCtrl.hpp"
#include "Notebook.h"
#if wxVERSION_NUMBER >= 2900
#include <wx/persist.h>
#include <wx/persist/toplevel.h>
Expand All @@ -54,7 +54,7 @@ class LanguageServerSettingsDlgBase : public wxDialog
protected:
wxCheckBox* m_checkBoxEnable;
wxStaticLine* m_staticLine102;
Notebook* m_notebook;
wxNotebook* m_notebook;
wxButton* m_buttonScan;
wxButton* m_buttonNew;
wxButton* m_buttonDelete;
Expand All @@ -73,7 +73,7 @@ class LanguageServerSettingsDlgBase : public wxDialog
public:
wxCheckBox* GetCheckBoxEnable() { return m_checkBoxEnable; }
wxStaticLine* GetStaticLine102() { return m_staticLine102; }
Notebook* GetNotebook() { return m_notebook; }
wxNotebook* GetNotebook() { return m_notebook; }
wxButton* GetButtonScan() { return m_buttonScan; }
wxButton* GetButtonNew() { return m_buttonNew; }
wxButton* GetButtonDelete() { return m_buttonDelete; }
Expand Down
8 changes: 4 additions & 4 deletions LanguageServer/UI.wxcp
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,15 @@
}, {
"type": "string",
"m_label": "Class Name:",
"m_value": "Notebook"
"m_value": ""
}, {
"type": "string",
"m_label": "Include File:",
"m_value": "Notebook.h"
"m_value": ""
}, {
"type": "string",
"m_label": "Style:",
"m_value": "kNotebook_FixedWidth"
"m_value": ""
}],
"m_events": [],
"m_children": []
Expand Down Expand Up @@ -1444,7 +1444,7 @@
"border": 5,
"gbSpan": "1,1",
"gbPosition": "0,0",
"m_styles": ["wxNB_FIXEDWIDTH", "wxBK_DEFAULT"],
"m_styles": ["wxBK_DEFAULT"],
"m_sizerFlags": ["wxALL", "wxLEFT", "wxRIGHT", "wxTOP", "wxBOTTOM", "wxEXPAND"],
"m_properties": [{
"type": "winid",
Expand Down

0 comments on commit 68b85e8

Please sign in to comment.