Skip to content

Commit

Permalink
Merge branch 'main' into improve/symbols-jump
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaxed authored Jan 20, 2025
2 parents 5dfcd79 + 7ac3627 commit 50164b1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
28 changes: 26 additions & 2 deletions src/helpers/mterm/MTermView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <LayoutBuilder.h>
#include <ScrollView.h>
#include <String.h>
#include <MessageRunner.h>

#include "ConfigManager.h"
#include "KeyTextViewScintilla.h"
Expand All @@ -30,7 +31,9 @@ enum {
kTermViewStop = 'tvst',

kTermViewWrap = 'tvwr',
kTermViewBanner = 'tvba'
kTermViewBanner = 'tvba',

kTermFlushBuffer = 'flux'
};


Expand All @@ -42,6 +45,7 @@ MTermView::MTermView(const BString& name, const BMessenger& target)
, fMTerm(nullptr)
, fWrapEnabled(nullptr)
, fBannerEnabled(nullptr)
, fBufferFlusher(nullptr)
{
SetName(name);
_Init();
Expand Down Expand Up @@ -185,6 +189,9 @@ MTermView::MessageReceived(BMessage* message)
{
break;
}
case kTermFlushBuffer:
_FlushOutput();
break;
default:
BGroupView::MessageReceived(message);
break;
Expand Down Expand Up @@ -294,9 +301,26 @@ MTermView::_Init()
void
MTermView::_HandleOutput(const BString& info)
{
fKeyTextView->Append(info);
if (fBufferFlusher != nullptr) {
delete fBufferFlusher;
fBufferFlusher = nullptr;
}

fOutputBuffer.Append(info);
if (fOutputBuffer.Length() > 1024) {
_FlushOutput();
} else {
static BMessage flush(kTermFlushBuffer);
fBufferFlusher = new BMessageRunner(BMessenger(this), &flush, 1000, 1);
}
}

void
MTermView::_FlushOutput()
{
fKeyTextView->Append(fOutputBuffer);
fOutputBuffer = "";
}

KeyTextViewScintilla*
MTermView::TextView()
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/mterm/MTermView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BCheckBox;
class BTextView;
class MTerm;
class KeyTextViewScintilla;
class BMessageRunner;

#define kTermViewDone 'tvdo'

Expand All @@ -38,6 +39,7 @@ class MTermView : public BGroupView {
void EnableStopButton(bool doIt);
void _Init();
void _HandleOutput(const BString& info);
void _FlushOutput();
void _BannerMessage(BString status);
void _EnsureStopped();

Expand All @@ -49,4 +51,6 @@ class MTermView : public BGroupView {
MTerm* fMTerm;
BCheckBox* fWrapEnabled;
BCheckBox* fBannerEnabled;
BString fOutputBuffer;
BMessageRunner* fBufferFlusher;
};
43 changes: 16 additions & 27 deletions src/lsp-client/LSPEditorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ LSPEditorWrapper::Format()
void
LSPEditorWrapper::GoTo(LSPEditorWrapper::GoToType type)
{
if (!IsInitialized()|| !fEditor || !IsStatusValid())
if (!IsInitialized()|| !fEditor)
return;

flushChanges();

Position position;
GetCurrentLSPPosition(&position);

Expand All @@ -315,9 +317,11 @@ LSPEditorWrapper::GoTo(LSPEditorWrapper::GoToType type)
void
LSPEditorWrapper::Rename(std::string newName)
{
if (!IsInitialized()|| !fEditor || !IsStatusValid())
if (!IsInitialized()|| !fEditor)
return;

flushChanges();

Position position;
GetCurrentLSPPosition(&position);
fLSPProjectWrapper->Rename(this, position, newName);
Expand All @@ -327,22 +331,12 @@ LSPEditorWrapper::Rename(std::string newName)
void
LSPEditorWrapper::StartHover(Sci_Position sci_position)
{
if (!IsInitialized() || sci_position < 0 || !IsStatusValid()) {
if (!IsInitialized() || sci_position < 0) {
return;
}
/*
fEditor->SendMessage(SCI_SETINDICATORCURRENT, IND_OVER);

if (fLastWordEndPosition > -1 && fLastWordStartPosition > -1) {
fEditor->SendMessage(SCI_INDICATORCLEARRANGE, fLastWordStartPosition, fLastWordEndPosition - fLastWordStartPosition);
fLastWordEndPosition = fLastWordStartPosition = -1;
}
fLastWordStartPosition = fEditor->SendMessage(SCI_WORDSTARTPOSITION, sci_position, true);
fLastWordEndPosition = fEditor->SendMessage(SCI_WORDENDPOSITION, sci_position, true);
flushChanges();

fEditor->SendMessage(SCI_INDICATORFILLRANGE, fLastWordStartPosition, fLastWordEndPosition - fLastWordStartPosition);
*/
LSPDiagnostic dia;
if (DiagnosticFromPosition(sci_position, dia) > -1) {
_ShowToolTip(dia.range.info.c_str());
Expand Down Expand Up @@ -433,8 +427,11 @@ LSPEditorWrapper::EndHover()
void
LSPEditorWrapper::SwitchSourceHeader()
{
if (!IsInitialized() || !IsStatusValid())
if (!IsInitialized())
return;

flushChanges();

fLSPProjectWrapper->SwitchSourceHeader(this);
}

Expand Down Expand Up @@ -505,8 +502,11 @@ LSPEditorWrapper::SelectedCompletion(const char* text)
void
LSPEditorWrapper::StartCompletion()
{
if (!IsInitialized() || !fEditor || !IsStatusValid())
if (!IsInitialized() || !fEditor ) {
return;
}

flushChanges();

// let's check if a completion is ongoing
if (fCurrentCompletion.items.size() > 0) {
Expand Down Expand Up @@ -1002,17 +1002,6 @@ LSPEditorWrapper::_DoLinearSymbolInformation(std::vector<SymbolInformation>& vec
}
}

bool
LSPEditorWrapper::IsStatusValid()
{
BString status = GetFileStatus();
bool value = status.IsEmpty() || (status.Compare("idle") == 0);
if (!value)
LogDebugF("Invalid status (%d) for [%s] (%s)", value, GetFilenameURI().String(),
GetFileStatus().String());
return value;
}


void
LSPEditorWrapper::onNotify(std::string id, value& result)
Expand Down
1 change: 0 additions & 1 deletion src/lsp-client/LSPEditorWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class LSPEditorWrapper : public LSPTextDocument {
void OpenFileURI(std::string uri, int32 line = -1, int32 character = -1,
BString edits = "");
std::string GetCurrentLine();
bool IsStatusValid();
std::vector<TextDocumentContentChangeEvent> fChanges;


Expand Down
5 changes: 4 additions & 1 deletion src/ui/ProjectBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ ProjectBrowser::_UpdateNode(BMessage* message)
item->GetSourceItem()->UpdateEntryRef(newRef);
fOutlineListView->SortItemsUnder(fOutlineListView->Superitem(item),
true, ProjectOutlineListView::CompareProjectItems);
if (item->IsSelected())
fOutlineListView->ScrollToSelection();
} else {
LogError("Can't find ref for newPath[%s]", newPath.String());
return;
Expand Down Expand Up @@ -695,8 +697,9 @@ ProjectBrowser::_RenameCurrentSelectedFile(const BString& new_name)
ProjectItem *item = GetSelectedProjectItem();
if (item != nullptr) {
BEntry entry(item->GetSourceItem()->EntryRef());
if (entry.Exists())
if (entry.Exists()) {
status = entry.Rename(new_name, false);
}
}
return status;
}
Expand Down

0 comments on commit 50164b1

Please sign in to comment.