Skip to content

Commit

Permalink
Fixed: when LSP tries to place many markers ("diagnostics") on the ed…
Browse files Browse the repository at this point in the history
…itor, it causes an excessive reads from the disk which can cause a noticable lag

Editor navigation bar: remove the "bookmark" button (it causes too much extra work for CodeLite with no real benefit)
  • Loading branch information
eranif committed Apr 12, 2024
1 parent 1bfbe8d commit 13f3e95
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 63 deletions.
16 changes: 6 additions & 10 deletions LiteEditor/cl_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4053,15 +4053,12 @@ void clEditor::SetWarningMarker(int lineno, CompilerMessage&& msg)
wxString display_message = msg.message;
m_compilerMessagesMap.insert({ lineno, std::move(msg) });

BuildTabSettingsData options;
EditorConfigST::Get()->ReadObject(wxT("BuildTabSettings"), &options);

if (options.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_BOOKMARKS) {
if (m_buildOptions.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_BOOKMARKS) {
MarkerAdd(lineno, smt_warning);
NotifyMarkerChanged(lineno);
}

if (options.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_ANNOTATE) {
if (m_buildOptions.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_ANNOTATE) {
// define the warning marker
AnnotationSetText(lineno, display_message);
AnnotationSetStyle(lineno, ANNOTATION_STYLE_WARNING);
Expand All @@ -4082,15 +4079,12 @@ void clEditor::SetErrorMarker(int lineno, CompilerMessage&& msg)
wxString display_message = msg.message;
m_compilerMessagesMap.insert({ lineno, std::move(msg) });

BuildTabSettingsData options;
EditorConfigST::Get()->ReadObject(wxT("BuildTabSettings"), &options);

if (options.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_BOOKMARKS) {
if (m_buildOptions.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_BOOKMARKS) {
MarkerAdd(lineno, smt_error);
NotifyMarkerChanged(lineno);
}

if (options.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_ANNOTATE) {
if (m_buildOptions.GetErrorWarningStyle() == BuildTabSettingsData::MARKER_ANNOTATE) {
AnnotationSetText(lineno, display_message);
AnnotationSetStyle(lineno, ANNOTATION_STYLE_ERROR);
}
Expand Down Expand Up @@ -5218,6 +5212,8 @@ void clEditor::UpdateOptions()
clCxxWorkspaceST::Get()->GetLocalWorkspace()->GetOptions(m_options, GetProject());
}

EditorConfigST::Get()->ReadObject(wxT("BuildTabSettings"), &m_buildOptions);

clEditorConfigEvent event(wxEVT_EDITOR_CONFIG_LOADING);
event.SetFileName(CLRealPath(GetFileName().GetFullPath()));
if (EventNotifier::Get()->ProcessEvent(event)) {
Expand Down
2 changes: 2 additions & 0 deletions LiteEditor/cl_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "SFTPClientData.hpp"
#include "bookmark_manager.h"
#include "browse_record.h"
#include "buildtabsettingsdata.h"
#include "clEditorStateLocker.h"
#include "cl_calltip.h"
#include "cl_defs.h"
Expand Down Expand Up @@ -313,6 +314,7 @@ class clEditor : public wxStyledTextCtrl, public IEditor
// track the position between Idle event calls
long m_lastIdlePosition = wxNOT_FOUND;
uint64_t m_lastIdleEvent = 0;
BuildTabSettingsData m_buildOptions;

public:
static bool m_ccShowPrivateMembers;
Expand Down
80 changes: 28 additions & 52 deletions Plugin/clEditorBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ clEditorBar::clEditorBar(wxWindow* parent)
EventNotifier::Get()->Bind(wxEVT_CMD_PAGE_CHANGED, &clEditorBar::OnEditorChanged, this);
EventNotifier::Get()->Bind(wxEVT_ALL_EDITORS_CLOSED, &clEditorBar::OnEditorChanged, this);
EventNotifier::Get()->Bind(wxEVT_SYS_COLOURS_CHANGED, &clEditorBar::OnThemeChanged, this);
EventNotifier::Get()->Bind(wxEVT_MARKER_CHANGED, &clEditorBar::OnMarkerChanged, this);
EventNotifier::Get()->Bind(wxEVT_CC_UPDATE_NAVBAR, &clEditorBar::OnUpdate, this);
m_buttonScope->SetBitmap(m_functionBmp);
m_buttonScope->SetHasDropDownMenu(true);
Expand All @@ -61,7 +60,6 @@ clEditorBar::~clEditorBar()
EventNotifier::Get()->Unbind(wxEVT_CMD_PAGE_CHANGED, &clEditorBar::OnEditorChanged, this);
EventNotifier::Get()->Unbind(wxEVT_ALL_EDITORS_CLOSED, &clEditorBar::OnEditorChanged, this);
EventNotifier::Get()->Unbind(wxEVT_SYS_COLOURS_CHANGED, &clEditorBar::OnThemeChanged, this);
EventNotifier::Get()->Unbind(wxEVT_MARKER_CHANGED, &clEditorBar::OnMarkerChanged, this);
EventNotifier::Get()->Unbind(wxEVT_CC_UPDATE_NAVBAR, &clEditorBar::OnUpdate, this);
}

Expand All @@ -83,7 +81,7 @@ void clEditorBar::SetScopes(const wxString& filename, const clEditorBar::ScopeEn
void clEditorBar::DoShow(bool s)
{
m_shouldShow = s;
if(Show(s)) {
if (Show(s)) {
GetParent()->GetSizer()->Layout();
}
CallAfter(&clEditorBar::DoRefreshColoursAndFonts);
Expand All @@ -102,7 +100,6 @@ void clEditorBar::DoRefreshColoursAndFonts()
m_projectFile.clear();
m_projectName.clear();
m_filenameRelative.clear();
m_bookmarks.clear();

wxColour bgcolour = clSystemSettings::GetDefaultPanelColour();
wxColour textColour = clSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
Expand All @@ -111,35 +108,21 @@ void clEditorBar::DoRefreshColoursAndFonts()
m_labelText->SetForegroundColour(textColour);
m_labelText->SetBackgroundColour(bgcolour);

if(!m_shouldShow) {
if (!m_shouldShow) {
return;
}

IEditor* editor = clGetManager()->GetActiveEditor();
if(editor) {
if(!IsShown()) {
if (editor) {
if (!IsShown()) {
Show();
}

wxString current_file = editor->GetRemotePathOrLocal();

// Update bookmarks button
LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexer("c++");
editor->GetFindMarkers(m_bookmarks);

if(!m_bookmarks.empty()) {
CreateBookmarksBitmap();
if(!m_buttonBookmarks->IsShown()) {
m_buttonBookmarks->Show();
}
m_buttonBookmarks->SetText(_("Bookmarks"));
m_buttonBookmarks->SetBitmap(m_bookmarksBmp);
} else {
m_buttonBookmarks->Hide();
}
m_buttonBookmarks->Hide();

// Update file path button
if(!m_buttonFilePath->IsShown()) {
if (!m_buttonFilePath->IsShown()) {
m_buttonFilePath->Show();
}

Expand All @@ -148,7 +131,7 @@ void clEditorBar::DoRefreshColoursAndFonts()
wxFileName fn(current_file, editor->IsRemoteFile() ? wxPATH_UNIX : wxPATH_NATIVE);
wxString PATH_SEPARATOR = editor->IsRemoteFile() ? wxString("/") : wxFileName::GetPathSeparator();

if(fn.GetDirCount()) {
if (fn.GetDirCount()) {
filepath << fn.GetDirs().Last() << PATH_SEPARATOR;
}
filepath << fn.GetFullName();
Expand All @@ -157,10 +140,10 @@ void clEditorBar::DoRefreshColoursAndFonts()

// update the scope
bool hide_scope_button = m_scopes.empty() || m_scopesFile != current_file;
if(hide_scope_button) {
if (hide_scope_button) {
m_buttonScope->Hide();
} else {
if(!m_buttonScope->IsShown()) {
if (!m_buttonScope->IsShown()) {
m_buttonScope->Show();
}
UpdateScope();
Expand All @@ -181,14 +164,7 @@ void clEditorBar::DoRefreshColoursAndFonts()

void clEditorBar::DoRefresh() { Refresh(); }

void clEditorBar::OnMarkerChanged(clCommandEvent& event)
{
event.Skip();
if(!IsShown()) {
return;
}
CallAfter(&clEditorBar::DoRefreshColoursAndFonts);
}
void clEditorBar::OnMarkerChanged(clCommandEvent& event) { event.Skip(); }

void clEditorBar::CreateBookmarksBitmap()
{
Expand Down Expand Up @@ -241,24 +217,24 @@ void clEditorBar::OnButtonActions(wxCommandEvent& event)
wxEVT_MENU, [&](wxCommandEvent& evt) { selection = evt.GetId(); }, wxID_ANY);
m_buttonFilePath->ShowMenu(menu);

if(selection == wxID_NONE)
if (selection == wxID_NONE)
return;

text.Clear();
if(selection == idCopyFullPath->GetId()) {
if (selection == idCopyFullPath->GetId()) {
text = m_filename;
} else if(selection == idCopyName->GetId()) {
} else if (selection == idCopyName->GetId()) {
text = wxFileName(m_filename).GetFullName();
} else if(selection == idCopyPath->GetId()) {
} else if (selection == idCopyPath->GetId()) {
text = wxFileName(m_filename).GetPath();
} else if(selection == idOpenExplorer->GetId()) {
} else if (selection == idOpenExplorer->GetId()) {
FileUtils::OpenFileExplorerAndSelect(wxFileName(m_filename).GetFullPath());
} else if(selection == idOpenShell->GetId()) {
} else if (selection == idOpenShell->GetId()) {
FileUtils::OpenTerminal(wxFileName(m_filename).GetPath());
}

// Clipboard action?
if(!text.IsEmpty()) {
if (!text.IsEmpty()) {
::CopyToClipboard(text);
clGetManager()->SetStatusMessage((wxString() << "'" << text << _("' copied!")), 2);
}
Expand All @@ -269,7 +245,7 @@ void clEditorBar::OnButtonBookmarks(wxCommandEvent& event)
wxUnusedVar(event);
IEditor* editor = clGetManager()->GetActiveEditor();
std::vector<std::pair<int, wxString>> V;
if(editor && editor->GetFindMarkers(V)) {
if (editor && editor->GetFindMarkers(V)) {
// Show bookmarks menu
wxMenu menu;
std::unordered_map<int, int> M;
Expand All @@ -285,9 +261,9 @@ void clEditorBar::OnButtonBookmarks(wxCommandEvent& event)
wxEVT_MENU, [&](wxCommandEvent& evt) { selection = evt.GetId(); }, wxID_ANY);
m_buttonBookmarks->ShowMenu(menu);

if(selection == wxID_NONE)
if (selection == wxID_NONE)
return;
if(M.count(selection)) {
if (M.count(selection)) {
int lineNumber = M[selection] - 1;
editor->CenterLine(lineNumber);
editor->GetCtrl()->EnsureVisible(lineNumber);
Expand All @@ -306,7 +282,7 @@ void clEditorBar::OnButtonScope(wxCommandEvent& event)
// build the menu
wxMenu menu;
std::unordered_map<int, ScopeEntry> M;
for(const ScopeEntry& entry : m_scopes) {
for (const ScopeEntry& entry : m_scopes) {
int menu_id = wxXmlResource::GetXRCID(entry.display_string);
M[menu_id] = entry;
menu.Append(menu_id, entry.display_string);
Expand All @@ -319,10 +295,10 @@ void clEditorBar::OnButtonScope(wxCommandEvent& event)
wxEVT_MENU, [&](wxCommandEvent& evt) { selection = evt.GetId(); }, wxID_ANY);
m_buttonScope->ShowMenu(menu);

if(selection == wxID_NONE)
if (selection == wxID_NONE)
return;

if(M.count(selection)) {
if (M.count(selection)) {
// Display the matched entry from the menu
auto stc = editor->GetCtrl();
ScopeEntry entry = M[selection];
Expand All @@ -347,15 +323,15 @@ thread_local clEditorBar::ScopeEntry InvalidScope;
const clEditorBar::ScopeEntry& clEditorBar::FindByLine(int lineNumber) const
{
const ScopeEntry* match = nullptr;
for(const clEditorBar::ScopeEntry& entry : m_scopes) {
if((entry.line_number - 1) >= lineNumber) {
for (const clEditorBar::ScopeEntry& entry : m_scopes) {
if ((entry.line_number - 1) >= lineNumber) {
break;
} else {
match = &entry;
}
}

if(match) {
if (match) {
return *match;
} else {
return InvalidScope;
Expand All @@ -368,14 +344,14 @@ void clEditorBar::UpdateScope()
CHECK_PTR_RET(editor);

wxString fullpath = editor->GetRemotePathOrLocal();
if(fullpath != m_scopesFile) {
if (fullpath != m_scopesFile) {
m_scopes.clear();
m_buttonScope->SetText(wxEmptyString);
return;
}

const auto& scope = FindByLine(editor->GetCurrentLine());
if(scope.is_ok()) {
if (scope.is_ok()) {
m_buttonScope->SetText(scope.display_string);
} else {
m_buttonScope->SetText(wxEmptyString);
Expand Down
1 change: 0 additions & 1 deletion Plugin/clEditorBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class WXDLLIMPEXP_SDK clEditorBar : public clEditorBarBase
// Bookmarks button
wxBitmap m_bookmarksBmp;
wxRect m_bookmarksRect;
std::vector<std::pair<int, wxString>> m_bookmarks;

bool m_shouldShow = false;

Expand Down

0 comments on commit 13f3e95

Please sign in to comment.