1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Merge branch 'master' into FuzzyAutoComplete

This commit is contained in:
Brian Fiete 2021-12-28 17:07:19 +01:00 committed by GitHub
commit 62c3998521
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 2485 additions and 598 deletions

View file

@ -9,7 +9,7 @@ namespace IDE
{
public KeyCode mKeyCode;
public KeyFlags mKeyFlags;
public int GetHashCode()
{
return (int)mKeyCode | (int)mKeyFlags << 16;
@ -121,10 +121,21 @@ namespace IDE
class CommandMap : IDECommandBase
{
public Dictionary<KeyState, IDECommandBase> mMap = new .() ~ delete _;
public List<IDECommandBase> mFailValues ~ delete _;
public List<IDECommandBase> FailValues
{
get
{
if (mFailValues == null)
mFailValues = new .();
return mFailValues;
}
}
public void Clear()
{
for (let val in mMap.Values)
void Release(IDECommandBase val)
{
if (var cmdMap = val as CommandMap)
delete cmdMap;
@ -136,6 +147,15 @@ namespace IDE
ideCommand.mNext = null;
}
}
for (let val in mMap.Values)
Release(val);
if (mFailValues != null)
{
for (var val in mFailValues)
Release(val);
mFailValues.Clear();
}
mMap.Clear();
}
@ -194,7 +214,9 @@ namespace IDE
Add("Close Document", new () => { gApp.[Friend]TryCloseCurrentDocument(); });
Add("Close Panel", new () => { gApp.[Friend]TryCloseCurrentPanel(); });
Add("Close Workspace", new => gApp.[Friend]Cmd_CloseWorkspaceAndSetupNew);
Add("Comment Selection", new => gApp.[Friend]CommentSelection);
Add("Comment Block", new => gApp.[Friend]CommentBlock, .Editor);
Add("Comment Lines", new => gApp.[Friend]CommentLines, .Editor);
Add("Comment Toggle", new => gApp.[Friend]CommentToggle, .Editor);
Add("Compile File", new => gApp.Cmd_CompileFile);
Add("Debug All Tests", new () => { gApp.[Friend]RunTests(true, true); });
Add("Debug Normal Tests", new () => { gApp.[Friend]RunTests(false, true); });
@ -251,6 +273,7 @@ namespace IDE
Add("Run Normal Tests", new () => { gApp.[Friend]RunTests(false, false); });
Add("Run To Cursor", new => gApp.[Friend]RunToCursor);
Add("Run Without Compiling", new => gApp.[Friend]RunWithoutCompiling);
Add("Safe Mode Toggle", new () => { gApp.SafeModeToggle(); });
Add("Save All", new () => { gApp.SaveAll(); });
Add("Save As", new () => { gApp.SaveAs(); });
Add("Save File", new => gApp.SaveFile);

View file

@ -76,6 +76,9 @@ namespace IDE.Compiler
[CallingConvention(.Stdcall), CLink]
static extern int32 BfCompiler_GetCurConstEvalExecuteId(void* bfCompiler);
[CallingConvention(.Stdcall), CLink]
static extern bool BfCompiler_GetLastHadComptimeRebuilds(void* bfCompiler);
[CallingConvention(.Stdcall), CLink]
static extern void BfCompiler_Delete(void* bfCompiler);
@ -834,5 +837,10 @@ namespace IDE.Compiler
}
}
}
public bool GetLastHadComptimeRebuilds()
{
return BfCompiler_GetLastHadComptimeRebuilds(mNativeBfCompiler);
}
}
}

View file

@ -78,8 +78,9 @@ namespace IDE.Compiler
public bool mCancelled;
public int32 mTextVersion = -1;
public bool mIsUserRequested;
public bool mDoFuzzyAutoComplete;
public Stopwatch mStopwatch ~ delete _;
public ProfileInstance mProfileInstance ~ _.Dispose();
}
public class BfParser : ILeakIdentifiable
@ -122,7 +123,7 @@ namespace IDE.Compiler
static extern bool BfParser_Reduce(void* bfParser, void* bfPassInstance);
[CallingConvention(.Stdcall), CLink]
static extern char8* BfParser_Format(void* bfParser, int32 formatEnd, int32 formatStart, out int32* outCharMapping);
static extern char8* BfParser_Format(void* bfParser, int32 formatEnd, int32 formatStart, out int32* outCharMapping, int32 maxCol);
[CallingConvention(.Stdcall), CLink]
static extern char8* BfParser_GetDebugExpressionAt(void* bfParser, int32 cursorIdx);
@ -209,8 +210,9 @@ namespace IDE.Compiler
public void Reformat(int formatStart, int formatEnd, out int32[] char8Mapping, String str)
{
int32* char8MappingPtr;
var stringPtr = BfParser_Format(mNativeBfParser, (int32)formatStart, (int32)formatEnd, out char8MappingPtr);
str.Append(stringPtr);
var maxCol = gApp.mSettings.mEditorSettings.mWrapCommentsAt;
var stringPtr = BfParser_Format(mNativeBfParser, (int32)formatStart, (int32)formatEnd, out char8MappingPtr, maxCol);
str.Append(stringPtr);
char8Mapping = new int32[str.Length];
for (int32 i = 0; i < char8Mapping.Count; i++)

View file

@ -51,7 +51,7 @@ namespace IDE.Compiler
static extern char8* BfSystem_GetNamespaceSearch(void* bfSystem, char8* typeName, void* project);
[CallingConvention(.Stdcall), CLink]
static extern void* BfSystem_CreateProject(void* bfSystem, char8* projectName);
static extern void* BfSystem_CreateProject(void* bfSystem, char8* projectName, char8* projectDir);
[CallingConvention(.Stdcall), CLink]
static extern void BfSystem_ClearTypeOptions(void* bfSystem);
@ -142,7 +142,7 @@ namespace IDE.Compiler
{
using (mMonitor.Enter())
{
var bfProject = CreateProject(project.mProjectName);
var bfProject = CreateProject(project.mProjectName, project.mProjectDir);
mProjectMap[project] = bfProject;
}
}
@ -188,10 +188,10 @@ namespace IDE.Compiler
outNamespaceSearch.Append(namespaceSearch);
}
public BfProject CreateProject(String projectName)
public BfProject CreateProject(String projectName, String projectDir)
{
BfProject project = new BfProject();
project.mNativeBfProject = BfSystem_CreateProject(mNativeBfSystem, projectName);
project.mNativeBfProject = BfSystem_CreateProject(mNativeBfSystem, projectName, projectDir);
return project;
}

View file

@ -169,6 +169,8 @@ namespace IDE
public bool mLastCompileHadMessages;
public bool mPauseOnExit;
public bool mDbgDelayedAutocomplete;
public bool mDbgTimeAutocomplete;
public bool mDbgPerfAutocomplete;
public BeefConfig mBeefConfig = new BeefConfig() ~ delete _;
public List<String> mDeferredFails = new .() ~ DeleteContainerAndItems!(_);
public String mInitialCWD = new .() ~ delete _;
@ -2314,6 +2316,11 @@ namespace IDE
widget.RemoveSelf();
}
WithSourceViewPanels(scope (sourceViewPanel) =>
{
sourceViewPanel.Dispose();
});
if (!mRunningTestScript)
{
mActiveDocumentsTabbedView = null;
@ -2425,11 +2432,27 @@ namespace IDE
}
[IDECommand]
void CommentSelection()
void CommentBlock()
{
var sewc = GetActiveSourceEditWidgetContent();
if (sewc != null)
sewc.ToggleComment(true);
sewc.CommentBlock();
}
[IDECommand]
void CommentLines()
{
var sewc = GetActiveSourceEditWidgetContent();
if (sewc != null)
sewc.CommentLines();
}
[IDECommand]
void CommentToggle()
{
var sewc = GetActiveSourceEditWidgetContent();
if (sewc != null)
sewc.ToggleComment();
}
[IDECommand]
@ -3936,7 +3959,7 @@ namespace IDE
if (sourceViewPanel != null)
{
if (sourceViewPanel.mEditWidget.mEditWidgetContent.GetCursorLineChar(var line, var lineChar))
sourceViewPanel.UpdateMouseover(true, true, line, lineChar);
sourceViewPanel.UpdateMouseover(true, true, line, lineChar, true);
}
}
@ -4874,6 +4897,14 @@ namespace IDE
CreateDefaultLayout(false);
}
[IDECommand]
public void SafeModeToggle()
{
mSafeMode = !mSafeMode;
mNoResolve = mSafeMode;
mWantsBeefClean = true;
}
[IDECommand]
public void ShowKeyboardShortcuts()
{
@ -5240,6 +5271,11 @@ namespace IDE
menu.SetDisabled(!mDebugger.mIsRunning);
}
public void UpdateMenuItem_DebugOrTestRunning(IMenu menu)
{
menu.SetDisabled(!mDebugger.mIsRunning && (mTestManager == null));
}
public void UpdateMenuItem_DebugStopped_HasWorkspace(IMenu menu)
{
menu.SetDisabled(mDebugger.mIsRunning || !mWorkspace.IsInitialized);
@ -5310,6 +5346,7 @@ namespace IDE
AddMenuItem(prefMenu, "&Settings", "Settings");
AddMenuItem(prefMenu, "Reload Settings", "Reload Settings");
AddMenuItem(prefMenu, "Reset UI", "Reset UI");
AddMenuItem(prefMenu, "Safe Mode", "Safe Mode Toggle", new (menu) => { menu.SetCheckState(mSafeMode ? 1 : 0); }, null, true, mSafeMode ? 1 : 0);
AddMenuItem(subMenu, "Close Workspace", "Close Workspace", new => UpdateMenuItem_HasWorkspace);
AddMenuItem(subMenu, "E&xit", "Exit");
@ -5386,7 +5423,9 @@ namespace IDE
advancedEditMenu.AddMenuItem(null);
AddMenuItem(advancedEditMenu, "Make Uppercase", "Make Uppercase");
AddMenuItem(advancedEditMenu, "Make Lowercase", "Make Lowercase");
AddMenuItem(advancedEditMenu, "Comment Selection", "Comment Selection");
AddMenuItem(advancedEditMenu, "Comment Block", "Comment Block");
AddMenuItem(advancedEditMenu, "Comment Lines", "Comment Lines");
AddMenuItem(advancedEditMenu, "Comment Toggle", "Comment Toggle");
AddMenuItem(advancedEditMenu, "Uncomment Selection", "Uncomment Selection");
AddMenuItem(advancedEditMenu, "Reformat Document", "Reformat Document");
mViewWhiteSpace.mMenu = AddMenuItem(advancedEditMenu, "View White Space", "View White Space", null, null, true, mViewWhiteSpace.Bool ? 1 : 0);
@ -5397,6 +5436,8 @@ namespace IDE
var internalEditMenu = subMenu.AddMenuItem("Internal");
internalEditMenu.AddMenuItem("Hilight Cursor References", null, new (menu) => { ToggleCheck(menu, ref gApp.mSettings.mEditorSettings.mHiliteCursorReferences); }, null, null, true, gApp.mSettings.mEditorSettings.mHiliteCursorReferences ? 1 : 0);
internalEditMenu.AddMenuItem("Delayed Autocomplete", null, new (menu) => { ToggleCheck(menu, ref gApp.mDbgDelayedAutocomplete); }, null, null, true, gApp.mDbgDelayedAutocomplete ? 1 : 0);
internalEditMenu.AddMenuItem("Time Autocomplete", null, new (menu) => { ToggleCheck(menu, ref gApp.mDbgTimeAutocomplete); }, null, null, true, gApp.mDbgTimeAutocomplete ? 1 : 0);
internalEditMenu.AddMenuItem("Perf Autocomplete", null, new (menu) => { ToggleCheck(menu, ref gApp.mDbgPerfAutocomplete); }, null, null, true, gApp.mDbgPerfAutocomplete ? 1 : 0);
}
//////////
@ -5456,7 +5497,7 @@ namespace IDE
AddMenuItem(subMenu, "Start With&out Compiling", "Start Without Compiling", new => UpdateMenuItem_DebugStopped_HasWorkspace);
AddMenuItem(subMenu, "&Launch Process...", "Launch Process", new => UpdateMenuItem_DebugStopped);
AddMenuItem(subMenu, "&Attach to Process...", "Attach to Process", new => UpdateMenuItem_DebugStopped);
AddMenuItem(subMenu, "&Stop Debugging", "Stop Debugging", new => UpdateMenuItem_DebugRunning);
AddMenuItem(subMenu, "&Stop Debugging", "Stop Debugging", new => UpdateMenuItem_DebugOrTestRunning);
AddMenuItem(subMenu, "Break All", "Break All", new => UpdateMenuItem_DebugNotPaused);
AddMenuItem(subMenu, "Remove All Breakpoints", "Remove All Breakpoints");
AddMenuItem(subMenu, "Show &Disassembly", "Show Disassembly");
@ -5712,14 +5753,20 @@ namespace IDE
{
let sewc = editWidget.mEditWidgetContent as SourceEditWidgetContent;
if (sewc != null)
return sewc;
{
if (sewc.mEditWidget.mHasFocus)
return sewc;
return null;
}
}
}
var activeTextPanel = GetActivePanel() as TextPanel;
if (activeTextPanel != null)
{
return activeTextPanel.EditWidget.mEditWidgetContent as SourceEditWidgetContent;
let sewc = activeTextPanel.EditWidget.mEditWidgetContent as SourceEditWidgetContent;
if ((sewc != null) && (sewc.mEditWidget.mHasFocus))
return sewc;
}
return null;
@ -9167,6 +9214,9 @@ namespace IDE
bool doCompile = false;
if (lastCompileHadMessages)
doCompile = true;
bool needsComptime = bfCompiler.GetLastHadComptimeRebuilds();
if ((!workspaceOptions.mIncrementalBuild) && (!lastCompileHadMessages))
{
tryQueueFiles = false;
@ -9177,6 +9227,9 @@ namespace IDE
}
}
if (needsComptime)
tryQueueFiles = true;
if (hotProject != null)
{
mWorkspace.mHadHotCompileSinceLastFullCompile = true;
@ -9210,6 +9263,9 @@ namespace IDE
}
}
if (needsComptime)
doCompile = true;
if (!success)
{
bfCompiler.QueueDeletePassInstance(passInstance);
@ -10748,7 +10804,7 @@ namespace IDE
Beef requires the Microsoft C++ build tools for Visual Studio 2013 or later, but they don't seem to be installed.
Install just Microsoft Visual C++ Build Tools or the entire Visual Studio suite from:
https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022
""";
#if CLI
@ -10759,7 +10815,7 @@ namespace IDE
dlg.AddOkCancelButtons(new (dlg) =>
{
ProcessStartInfo psi = scope ProcessStartInfo();
psi.SetFileName("https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019");
psi.SetFileName("https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022");
psi.UseShellExecute = true;
psi.SetVerb("Open");
var process = scope SpawnedProcess();
@ -12040,11 +12096,11 @@ namespace IDE
if (mErrorsPanel != null)
mErrorsPanel.ClearParserErrors(null);
delete mBfResolveCompiler;
delete mBfResolveSystem;
delete mBfResolveHelper;
delete mBfBuildCompiler;
delete mBfBuildSystem;
DeleteAndNullify!(mBfResolveCompiler);
DeleteAndNullify!(mBfResolveSystem);
DeleteAndNullify!(mBfResolveHelper);
DeleteAndNullify!(mBfBuildCompiler);
DeleteAndNullify!(mBfBuildSystem);
///
mDebugger.FullReportMemory();
@ -13698,7 +13754,6 @@ namespace IDE
[Import("user32.lib"), CLink, CallingConvention(.Stdcall)]
public static extern bool MessageBeep(MessageBeepType type);
#endif
}
static

View file

@ -626,6 +626,7 @@ namespace IDE
public FileRecoveryKind mEnableFileRecovery = .Yes;
public bool mFormatOnSave = false;
public bool mSyncWithWorkspacePanel = false;
public int32 mWrapCommentsAt = 0;
public void Serialize(StructuredData sd)
{
@ -652,6 +653,7 @@ namespace IDE
sd.Add("EnableFileRecovery", mEnableFileRecovery);
sd.Add("FormatOnSave", mFormatOnSave);
sd.Add("SyncWithWorkspacePanel", mSyncWithWorkspacePanel);
sd.Add("WrapCommentsAt", mWrapCommentsAt);
}
public void Deserialize(StructuredData sd)
@ -682,6 +684,7 @@ namespace IDE
sd.GetEnum<FileRecoveryKind>("EnableFileRecovery", ref mEnableFileRecovery);
sd.Get("FormatOnSave", ref mFormatOnSave);
sd.Get("SyncWithWorkspacePanel", ref mSyncWithWorkspacePanel);
sd.Get("WrapCommentsAt", ref mWrapCommentsAt);
}
public void SetDefaults()
@ -756,7 +759,9 @@ namespace IDE
Add("Cancel Build", "Ctrl+Break");
Add("Close Document", "Ctrl+W");
Add("Compile File", "Ctrl+F7");
Add("Comment Selection", "Ctrl+K, Ctrl+C");
Add("Comment Block", "Ctrl+K, Ctrl+C");
Add("Comment Lines", "Ctrl+K, Ctrl+/");
Add("Comment Toggle", "Ctrl+K, Ctrl+T");
Add("Duplicate Line", "Ctrl+D");
Add("Find Class", "Alt+Shift+L");
Add("Find in Document", "Ctrl+F");
@ -892,7 +897,10 @@ namespace IDE
{
curCmdMap = (*valuePtr) as CommandMap;
if (curCmdMap == null)
{
curCmdMap.FailValues.Add(ideCommand);
break;
}
}
else
{
@ -905,7 +913,10 @@ namespace IDE
if (checkPrevCmd.mContextFlags == ideCommand.mContextFlags)
gApp.OutputLineSmart("ERROR: The same key is bound for '{0}' and '{1}'", checkPrevCmd.mName, entry.mCommand);
if (checkPrevCmd.mNext == null)
{
curCmdMap.FailValues.Add(ideCommand);
break;
}
checkPrevCmd = checkPrevCmd.mNext;
}
checkPrevCmd.mNext = ideCommand;

View file

@ -1165,6 +1165,7 @@ namespace IDE.ui
}
}
public Stopwatch mStopwatch ~ delete _;
public EditWidget mTargetEditWidget;
public Event<Action> mOnAutoCompleteInserted ~ _.Dispose();
public Event<Action> mOnClosed ~ _.Dispose();

View file

@ -136,17 +136,15 @@ namespace IDE.ui
ClearAndDeleteItems(mResolveErrors);
mResolveErrors.Capacity = mResolveErrors.Count;
}
var bfl = scope:: List<BfPassInstance.BfError>();
for (int32 errorIdx = 0; errorIdx < errorCount; errorIdx++)
{
BfPassInstance.BfError bfError = new BfPassInstance.BfError();
passInstance.GetErrorData(errorIdx, bfError, true);
if (bfError.mFilePath == null)
bfError.mFilePath = new String(""); //for sort below
if (bfError.mIsWarning)
mWarningCount++;
else
mErrorCount++;
bfl.Add(bfError);
for (int32 moreInfoIdx < bfError.mMoreInfoCount)
{
BfPassInstance.BfError moreInfo = new BfPassInstance.BfError();
@ -155,12 +153,26 @@ namespace IDE.ui
bfError.mMoreInfo = new List<BfPassInstance.BfError>();
bfError.mMoreInfo.Add(moreInfo);
}
}
function int(int lhs, int rhs) ascLambda = (lhs, rhs) => lhs <=> rhs;
bfl.Sort(scope (lhs, rhs) => ascLambda(lhs.mFilePath.GetHashCode()+lhs.mSrcStart, rhs.mFilePath.GetHashCode()+rhs.mSrcStart));
for (int32 errorIdx = 0; errorIdx < bfl.Count; errorIdx++)
{
var bfError = bfl[errorIdx];
if (bfError.mIsWarning)
{
mWarningCount++;
}
else
mErrorCount++;
if (passKind == .Parse)
{
if (bfError.mFilePath == null)
bfError.mFilePath = new String("");
bool added = mParseErrors.TryAdd(bfError.mFilePath, var keyPtr, var valuePtr);
if (added)
{
@ -170,7 +182,7 @@ namespace IDE.ui
(*valuePtr).Add(bfError);
}
else
mResolveErrors.Add(bfError);
mResolveErrors.Add(bfError);
mDataId++;
}
@ -354,7 +366,7 @@ namespace IDE.ui
public override void Update()
{
base.Update();
if (!mVisible)
{
// Very dirty
@ -369,7 +381,8 @@ namespace IDE.ui
else
mDirtyTicks++;
ProcessErrors();
if(mDirtyTicks==0)
ProcessErrors();
}
public void SetNeedsResolveAll()
@ -379,7 +392,8 @@ namespace IDE.ui
public void ShowErrorNext()
{
ProcessErrors();
if(mDirtyTicks==0)
ProcessErrors();
bool foundFocused = false;
let root = mErrorLV.GetRoot();

View file

@ -139,7 +139,8 @@ namespace IDE.ui
mOutputWidget.SetText("");
for (var widgetEntry in mInlineWidgets)
{
widgetEntry.mWidget.RemoveSelf();
if (widgetEntry.mWidget.mParent != null)
widgetEntry.mWidget.RemoveSelf();
delete widgetEntry.mWidget;
}
mInlineWidgets.Clear();

View file

@ -293,6 +293,10 @@ namespace IDE.ui
}
}
struct ThreadEntry : this(int32 mThreadId, int32 mCPUUsage, StringView mName)
{
}
void PopulateThreadList(Menu menu)
{
if (mProfiler == null)
@ -307,6 +311,7 @@ namespace IDE.ui
var threadListStr = scope String();
mProfiler.GetThreadList(threadListStr);
List<ThreadEntry> entries = scope .();
for (var entry in threadListStr.Split('\n'))
{
if (entry.Length == 0)
@ -314,20 +319,35 @@ namespace IDE.ui
var dataItr = entry.Split('\t');
int32 threadId = int32.Parse(dataItr.GetNext());
StringView threadName = dataItr.GetNext();
ThreadEntry threadEntry = default;
threadEntry.mThreadId = int32.Parse(dataItr.GetNext());
threadEntry.mCPUUsage = int32.Parse(dataItr.GetNext());
threadEntry.mName = dataItr.GetNext();
entries.Add(threadEntry);
}
entries.Sort(scope (lhs, rhs) =>
{
int cmp = rhs.mCPUUsage <=> lhs.mCPUUsage;
if (cmp == 0)
cmp = lhs.mThreadId <=> rhs.mThreadId;
return cmp;
});
for (var entry in entries)
{
String threadStr = null;
var str = scope String();
str.AppendF("{0}", threadId);
if (!threadName.IsEmpty)
str.AppendF("{0}", entry.mThreadId);
str.AppendF($" ({entry.mCPUUsage}%)");
if (!entry.mName.IsEmpty)
{
threadStr = new String(threadName);
str.AppendF(" - {0}", threadName);
threadStr = new String(entry.mName);
str.AppendF($" - {entry.mName}");
}
subItem = menu.AddItem(str);
subItem.mOnMenuItemSelected.Add(new (item) => { Show(threadId, threadStr); } ~ delete threadStr);
subItem.mOnMenuItemSelected.Add(new (item) => { Show(entry.mThreadId, threadStr); } ~ delete threadStr);
}
}

View file

@ -127,7 +127,8 @@ namespace IDE.ui
AddPropertiesItem(category, "Enable File Recovery", "mEnableFileRecovery");
AddPropertiesItem(category, "Format on Save", "mFormatOnSave");
AddPropertiesItem(category, "Sync with Workspace Panel", "mSyncWithWorkspacePanel");
AddPropertiesItem(category, "Wrap Comments at Column", "mWrapCommentsAt");
category.Open(true, true);
}

View file

@ -2160,11 +2160,18 @@ namespace IDE.ui
return true;
}
public bool ToggleComment(bool? doComment = null)
public bool CommentBlock()
{
bool? doComment = true;
if (CheckReadOnly())
return false;
var startLineAndCol = CursorLineAndColumn;
int startTextPos = CursorTextPos;
var prevSelection = mSelection;
bool hadSelection = HasSelection();
if ((!HasSelection()) && (doComment != null))
{
CursorToLineEnd();
@ -2173,14 +2180,15 @@ namespace IDE.ui
mSelection = .(CursorTextPos, cursorEndPos);
}
if ((HasSelection()) && (mSelection.Value.Length > 1))
{
var startLineAndCol = CursorLineAndColumn;
UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedToggleComment");
if ((HasSelection()) && (mSelection.Value.Length > 1))
{
UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedCommentBlock");
mData.mUndoManager.Add(undoBatchStart);
mData.mUndoManager.Add(new SetCursorAction(this));
var setCursorAction = new SetCursorAction(this);
setCursorAction.mSelection = prevSelection;
setCursorAction.mCursorTextPos = (.)startTextPos;
mData.mUndoManager.Add(setCursorAction);
int minPos = mSelection.GetValueOrDefault().MinPos;
int maxPos = mSelection.GetValueOrDefault().MaxPos;
@ -2200,20 +2208,7 @@ namespace IDE.ui
int firstCharPos = minPos + (startLen - afterTrimStart);
int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd);
if ((doComment != true) && (trimmedStr.StartsWith("/*")))
{
if (trimmedStr.EndsWith("*/"))
{
mSelection = EditSelection(firstCharPos, firstCharPos + 2);
DeleteChar();
mSelection = EditSelection(lastCharPos - 4, lastCharPos - 2);
DeleteChar();
if (doComment != null)
mSelection = EditSelection(firstCharPos, lastCharPos - 4);
}
}
else if (doComment != false)
if (doComment != false)
{
CursorTextPos = firstCharPos;
InsertAtCursor("/*");
@ -2227,13 +2222,320 @@ namespace IDE.ui
if (undoBatchStart != null)
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
CursorLineAndColumn = startLineAndCol;
if (startTextPos <= minPos)
CursorLineAndColumn = startLineAndCol;
else if (startTextPos < maxPos)
CursorTextPos = startTextPos + 2;
if (doComment == null)
if ((doComment == null) || (!hadSelection))
mSelection = null;
return true;
}
return true;
}
return false;
}
public bool CommentLines()
{
if (CheckReadOnly())
return false;
int startTextPos = CursorTextPos;
var prevSelection = mSelection;
bool hadSelection = HasSelection();
var startLineAndCol = CursorLineAndColumn;
if (!HasSelection())
{
CursorToLineEnd();
int cursorEndPos = CursorTextPos;
CursorToLineStart(false);
mSelection = .(CursorTextPos, cursorEndPos);
}
UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedCommentLines");
mData.mUndoManager.Add(undoBatchStart);
var setCursorAction = new SetCursorAction(this);
setCursorAction.mSelection = prevSelection;
setCursorAction.mCursorTextPos = (.)startTextPos;
mData.mUndoManager.Add(setCursorAction);
int minPos = mSelection.GetValueOrDefault().MinPos;
int maxPos = mSelection.GetValueOrDefault().MaxPos;
mSelection = null;
while (minPos > 0)
{
var c = mData.mText[minPos - 1].mChar;
if (c == '\n')
break;
minPos--;
}
bool hadMaxChar = false;
int checkMaxPos = maxPos;
while (checkMaxPos > 0)
{
var c = mData.mText[checkMaxPos - 1].mChar;
if (c == '\n')
break;
if ((c != '\t') && (c != ' '))
{
hadMaxChar = true;
break;
}
checkMaxPos--;
}
if (!hadMaxChar)
{
checkMaxPos = maxPos;
while (checkMaxPos < mData.mTextLength)
{
var c = mData.mText[checkMaxPos].mChar;
if (c == '\n')
break;
if ((c != '\t') && (c != ' '))
{
maxPos = checkMaxPos + 1;
break;
}
checkMaxPos++;
}
}
int wantLineCol = -1;
int lineStartCol = 0;
bool didLineComment = false;
for (int i = minPos; i < maxPos; i++)
{
var c = mData.mText[i].mChar;
if (didLineComment)
{
if (c == '\n')
{
didLineComment = false;
lineStartCol = 0;
}
continue;
}
if (c == '\t')
lineStartCol += 4;
else if (c == ' ')
lineStartCol++;
else
{
if (wantLineCol == -1)
wantLineCol = lineStartCol;
else
wantLineCol = Math.Min(wantLineCol, lineStartCol);
didLineComment = true;
}
}
wantLineCol = Math.Max(0, wantLineCol);
didLineComment = false;
lineStartCol = 0;
for (int i = minPos; i < maxPos; i++)
{
var c = mData.mText[i].mChar;
if (didLineComment)
{
if (c == '\n')
{
didLineComment = false;
lineStartCol = 0;
}
continue;
}
bool commentNow = false;
if ((wantLineCol != -1) && (lineStartCol >= wantLineCol))
commentNow = true;
if (c == '\t')
lineStartCol += 4;
else if (c == ' ')
lineStartCol++;
else
commentNow = true;
if (commentNow)
{
CursorTextPos = i;
String str = scope .();
while (lineStartCol + 4 <= wantLineCol)
{
lineStartCol += 4;
str.Append("\t");
}
str.Append("//");
InsertAtCursor(str);
didLineComment = true;
maxPos += str.Length;
}
}
mSelection = EditSelection(minPos, maxPos);
if (undoBatchStart != null)
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
CursorLineAndColumn = startLineAndCol;
if (!hadSelection)
mSelection = null;
return true;
}
void FixSelection()
{
if (!HasSelection())
return;
if (CursorTextPos >= mSelection.Value.MaxPos)
CursorTextPos = mSelection.Value.MaxPos;
if (mSelection.Value.MaxPos - mSelection.Value.MinPos <= 1)
{
mSelection = null;
return;
}
}
public bool ToggleComment(bool? doComment = null)
{
if (CheckReadOnly())
return false;
int startTextPos = CursorTextPos;
bool doLineComment = false;
var prevSelection = mSelection;
LineAndColumn? startLineAndCol = CursorLineAndColumn;
if (!HasSelection())
{
CursorToLineEnd();
int cursorEndPos = CursorTextPos;
CursorToLineStart(false);
mSelection = .(CursorTextPos, cursorEndPos);
doLineComment = true;
}
if ((HasSelection()) && (mSelection.Value.Length > 0))
{
UndoBatchStart undoBatchStart = new UndoBatchStart("embeddedToggleComment");
mData.mUndoManager.Add(undoBatchStart);
var setCursorAction = new SetCursorAction(this);
setCursorAction.mSelection = prevSelection;
setCursorAction.mCursorTextPos = (.)startTextPos;
mData.mUndoManager.Add(setCursorAction);
int minPos = mSelection.GetValueOrDefault().MinPos;
int maxPos = mSelection.GetValueOrDefault().MaxPos;
mSelection = null;
var str = scope String();
ExtractString(minPos, maxPos - minPos, str);
var trimmedStr = scope String();
trimmedStr.Append(str);
int32 startLen = (int32)trimmedStr.Length;
trimmedStr.TrimStart();
int32 afterTrimStart = (int32)trimmedStr.Length;
trimmedStr.TrimEnd();
int32 afterTrimEnd = (int32)trimmedStr.Length;
trimmedStr.Append('\n');
int firstCharPos = minPos + (startLen - afterTrimStart);
int lastCharPos = maxPos - (afterTrimStart - afterTrimEnd);
if (afterTrimEnd == 0)
{
if (undoBatchStart != null)
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
CursorLineAndColumn = startLineAndCol.Value;
if (doComment == null)
mSelection = null;
return false; // not sure if this should be false in blank/only whitespace selection case
}
else if ((doComment != true) && (trimmedStr.StartsWith("//")))
{
for (int i = firstCharPos; i <= lastCharPos; i++)
{
if ((minPos == 0 && i == 0) || (minPos>=0 && SafeGetChar(i - 1) == '\n' || SafeGetChar(i - 1) == '\t'))
if (SafeGetChar(i - 0) == '/' && SafeGetChar(i + 1) == '/')
{
mSelection = EditSelection(i - 0, i + 2);
DeleteSelection();
lastCharPos -= 2;
while (i < maxPos && SafeGetChar(i) != '\n')
{
i++;
}
}
}
CursorToLineEnd();
int cursorEndPos = CursorTextPos;
mSelection = .(minPos, cursorEndPos);
}
else if ((doComment != true) && (trimmedStr.StartsWith("/*")))
{
if (trimmedStr.EndsWith("*/\n"))
{
mSelection = EditSelection(firstCharPos, firstCharPos + 2);
DeleteChar();
mSelection = EditSelection(lastCharPos - 4, lastCharPos - 2);
DeleteChar();
if (prevSelection != null)
mSelection = EditSelection(firstCharPos, lastCharPos - 4);
}
}
else if (doComment != false)
{ //if selection is from beginning of the line then we want to use // comment, that's why the check for line count and ' ' and tab
if (doLineComment)
{
CursorTextPos = minPos;
InsertAtCursor("//"); //goes here if no selection
}
else
{
CursorTextPos = firstCharPos;
InsertAtCursor("/*");
CursorTextPos = lastCharPos + 2;
InsertAtCursor("*/");
}
mSelection = EditSelection(firstCharPos, lastCharPos + 4);
if (startTextPos <= minPos)
CursorLineAndColumn = startLineAndCol.Value;
else
CursorTextPos = startTextPos + 2;
startLineAndCol = null;
}
else
{
mSelection = prevSelection;
}
if (undoBatchStart != null)
mData.mUndoManager.Add(undoBatchStart.mBatchEnd);
if (startLineAndCol != null)
CursorLineAndColumn = startLineAndCol.Value;
if (prevSelection == null)
mSelection = null;
FixSelection();
return true;
}
return false;
}
@ -2275,6 +2577,9 @@ namespace IDE.ui
public void DuplicateLine()
{
if ((CheckReadOnly()) || (!mAllowVirtualCursor))
return;
UndoBatchStart undoBatchStart = new UndoBatchStart("duplicateLine");
mData.mUndoManager.Add(undoBatchStart);
@ -3103,7 +3408,7 @@ namespace IDE.ui
return;
}
if ((keyChar == '/') && (ToggleComment()))
if ((keyChar == '/') && (HasSelection()) && (ToggleComment()))
{
return;
}

View file

@ -160,6 +160,8 @@ namespace IDE.ui
{
public int32 mCursorPos;
public String mResult ~ delete _;
public int32? mLine;
public int32? mLineChar;
public ~this()
{
@ -621,6 +623,10 @@ namespace IDE.ui
//Classify(options.HasFlag(.HighPriority) ? ResolveType.Autocomplete_HighPri : ResolveType.Autocomplete);
ResolveParams resolveParams = new ResolveParams();
if (gApp.mDbgTimeAutocomplete)
resolveParams.mStopwatch = new .()..Start();
if (gApp.mDbgPerfAutocomplete)
resolveParams.mProfileInstance = Profiler.StartSampling("Autocomplete").GetValueOrDefault();
resolveParams.mIsUserRequested = options.HasFlag(.UserRequested);
resolveParams.mDoFuzzyAutoComplete = gApp.mSettings.mEditorSettings.mFuzzyAutoComplete;
Classify(.Autocomplete, resolveParams);
@ -1186,7 +1192,7 @@ namespace IDE.ui
//if (mCurParser != null)
{
if (gApp.mWorkspace.mProjectLoadState != .Loaded)
return false;
return true;
if (!isHi)
Debug.Assert(!mIsPerformingBackgroundClassify);
@ -2336,6 +2342,11 @@ namespace IDE.ui
if (mDisposed)
return;
if (mProjectSource?.mEditData?.HasTextChanged() == true)
{
mProjectSource.ClearEditData();
}
ProcessDeferredResolveResults(-1);
if (IDEApp.sApp.mLastActiveSourceViewPanel == this)
@ -4725,7 +4736,7 @@ namespace IDE.ui
delete parser;
}
public void UpdateMouseover(bool mouseoverFired, bool mouseInbounds, int line, int lineChar)
public void UpdateMouseover(bool mouseoverFired, bool mouseInbounds, int line, int lineChar, bool isManual = false)
{
@ -5011,6 +5022,11 @@ namespace IDE.ui
mHoverResolveTask = new HoverResolveTask();
mHoverResolveTask.mCursorPos = (int32)textIdx;
if (isManual)
{
mHoverResolveTask.mLine = (.)line;
mHoverResolveTask.mLineChar = (.)lineChar;
}
}
}
@ -5204,6 +5220,16 @@ namespace IDE.ui
#if IDE_C_SUPPORT
hasClangHoverErrorData = mClangHoverErrorData != null;
#endif
if (mHoverResolveTask != null)
{
if (mHoverResolveTask.mLine != null)
{
UpdateMouseover(true, true, mHoverResolveTask.mLine.Value, mHoverResolveTask.mLineChar.Value, true);
return;
}
}
if (((mouseoverFired) || (mHoverWatch != null) || (hasClangHoverErrorData) || (mHoverResolveTask?.mResult != null)) &&
(mousePos.x >= 0))
{
@ -5526,6 +5552,13 @@ namespace IDE.ui
HandleResolveResult(resolveResult.mResolveType, resolveResult.mAutocompleteInfo, resolveResult);
if (resolveResult.mStopwatch != null)
{
resolveResult.mStopwatch.Stop();
if (var autoComplete = GetAutoComplete())
Debug.WriteLine($"Autocomplete {resolveResult.mStopwatch.ElapsedMilliseconds}ms entries: {autoComplete.mAutoCompleteListWidget.mEntryList.Count}");
}
//Debug.WriteLine("ProcessDeferredResolveResults finished {0}", resolveResult.mResolveType);
//bool checkIt = (mFilePath.Contains("Program.bf")) && (mEditWidget.mEditWidgetContent.mData.mCurTextVersionId > 3);

View file

@ -2765,7 +2765,10 @@ namespace IDE.ui
{
String evalStr = scope String();
CompactChildExpression(listViewItem, evalStr);
evalStr.Insert(0, "&");
if (evalStr.StartsWith("*"))
evalStr.Remove(0, 1);
else
evalStr.Insert(0, "&");
gApp.mBreakpointPanel.CreateMemoryBreakpoint(evalStr);
gApp.MarkDirty();
});