2019-08-23 11:56:54 -07:00
|
|
|
using System;
|
2020-04-29 06:40:03 -07:00
|
|
|
using System.Collections;
|
2019-08-23 11:56:54 -07:00
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using Beefy.widgets;
|
|
|
|
using Beefy.utils;
|
|
|
|
using IDE.ui;
|
|
|
|
using System.IO;
|
|
|
|
using System.Threading;
|
2020-01-31 16:12:42 -08:00
|
|
|
using Beefy;
|
2020-03-23 12:07:05 -07:00
|
|
|
using System.Security.Cryptography;
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
namespace IDE.Compiler
|
|
|
|
{
|
|
|
|
public enum BfSourceElementType : uint8
|
|
|
|
{
|
2020-08-23 05:49:30 -07:00
|
|
|
Normal,
|
|
|
|
Keyword,
|
|
|
|
Literal,
|
|
|
|
Identifier,
|
|
|
|
Comment,
|
|
|
|
Method,
|
|
|
|
Type,
|
|
|
|
RefType,
|
|
|
|
Interface,
|
|
|
|
Namespace
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum ResolveType
|
|
|
|
{
|
2022-04-16 06:27:54 -07:00
|
|
|
case None,
|
|
|
|
Classify,
|
|
|
|
ClassifyFullRefresh,
|
|
|
|
Autocomplete,
|
|
|
|
Autocomplete_HighPri,
|
|
|
|
GoToDefinition,
|
|
|
|
GetSymbolInfo,
|
|
|
|
RenameSymbol,
|
|
|
|
ShowFileSymbolReferences,
|
|
|
|
GetNavigationData,
|
|
|
|
GetCurrentLocation,
|
|
|
|
GetFixits,
|
|
|
|
GetTypeDefList,
|
|
|
|
GetTypeDefInto,
|
|
|
|
GetResultString;
|
|
|
|
|
|
|
|
public bool IsClassify => (this == .Classify) || (this == .ClassifyFullRefresh);
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
2022-04-16 06:27:54 -07:00
|
|
|
public enum SourceEmbedKind
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Type,
|
|
|
|
Method
|
|
|
|
}
|
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public class ResolveParams
|
|
|
|
{
|
2022-04-16 06:27:54 -07:00
|
|
|
public class Embed
|
|
|
|
{
|
|
|
|
public String mTypeName ~ delete _;
|
|
|
|
public int32 mRevision = -1;
|
|
|
|
public int32 mCursorIdx = -1;
|
|
|
|
public EditWidgetContent.CharData[] mCharData ~ delete _;
|
|
|
|
}
|
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public ResolveType mResolveType;
|
|
|
|
public int32 mOverrideCursorPos = -1;
|
|
|
|
public bool mInDeferredList;
|
|
|
|
|
2022-04-16 06:27:54 -07:00
|
|
|
public EditWidgetContent.CharData[] mCharData ~ delete _;
|
|
|
|
public IdSpan mCharIdSpan ~ _.Dispose();
|
|
|
|
public BfParser mParser;
|
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public int32 mLocalId = -1;
|
|
|
|
public String mReplaceStr ~ delete _;
|
|
|
|
public String mTypeDef ~ delete _;
|
2020-05-31 07:12:17 -07:00
|
|
|
public String mNamespace ~ delete _;
|
2019-08-23 11:56:54 -07:00
|
|
|
public int32 mFieldIdx = -1;
|
|
|
|
public int32 mMethodIdx = -1;
|
|
|
|
public int32 mPropertyIdx = -1;
|
|
|
|
public int32 mTypeGenericParamIdx = -1;
|
|
|
|
public int32 mMethodGenericParamIdx = -1;
|
|
|
|
|
|
|
|
public String mOutFileName ~ delete _;
|
|
|
|
public int32 mOutLine;
|
|
|
|
public int32 mOutLineChar;
|
|
|
|
public String mNavigationData ~ delete _;
|
|
|
|
public String mAutocompleteInfo ~ delete _;
|
2019-12-24 13:13:04 -08:00
|
|
|
public String mResultString ~ delete _;
|
2019-08-23 11:56:54 -07:00
|
|
|
public WaitEvent mWaitEvent ~ delete _;
|
|
|
|
|
|
|
|
public BfPassInstance mPassInstance ~ delete _;
|
2022-04-16 06:27:54 -07:00
|
|
|
public List<Embed> mEmitEmbeds = new .() ~ DeleteContainerAndItems!(_);
|
2019-08-23 11:56:54 -07:00
|
|
|
public String mDocumentationName ~ delete _;
|
|
|
|
public bool mCancelled;
|
|
|
|
public int32 mTextVersion = -1;
|
|
|
|
public bool mIsUserRequested;
|
2021-12-25 20:14:23 +01:00
|
|
|
public bool mDoFuzzyAutoComplete;
|
2021-12-27 14:25:34 -05:00
|
|
|
public Stopwatch mStopwatch ~ delete _;
|
2021-12-28 08:30:33 -05:00
|
|
|
public ProfileInstance mProfileInstance ~ _.Dispose();
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public class BfParser : ILeakIdentifiable
|
|
|
|
{
|
|
|
|
static int32 sIdx;
|
|
|
|
public int32 mIdx = sIdx++;
|
|
|
|
public void ToLeakString(String str)
|
|
|
|
{
|
|
|
|
str.AppendF("Idx:{0}", mIdx);
|
|
|
|
}
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern void BfSystem_DeleteParser(void* bfSystem, void* bfParser);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2022-05-26 15:39:32 -07:00
|
|
|
static extern void BfParser_SetSource(void* bfParser, char8* data, int32 length, char8* fileName, int32 textVersion);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern void BfParser_SetCharIdData(void* bfParser, uint8* data, int32 length);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2020-03-23 12:07:05 -07:00
|
|
|
static extern void BfParser_SetHashMD5(void* bfParser, ref MD5Hash md5Hash);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern void BfParser_SetNextRevision(void* bfParser, void* nextParser);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2022-04-16 06:27:54 -07:00
|
|
|
static extern void BfParser_SetCursorIdx(void* bfParser, int32 cursorIdx);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2022-04-16 06:27:54 -07:00
|
|
|
static extern void BfParser_SetAutocomplete(void* bfParser, int32 cursorIdx);
|
|
|
|
|
|
|
|
[CallingConvention(.Stdcall), CLink]
|
|
|
|
static extern void BfParser_SetEmbedKind(void* bfParser, SourceEmbedKind embedKind);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2022-04-16 06:27:54 -07:00
|
|
|
static extern void BfParser_SetIsClassifying(void* bfParser);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern bool BfParser_Parse(void* bfParser, void* bfPassInstance, bool compatMode);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern bool BfParser_Reduce(void* bfParser, void* bfPassInstance);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2022-05-16 11:01:30 -07:00
|
|
|
static extern char8* BfParser_Format(void* bfParser, int32 formatEnd, int32 formatStart, out int32* outCharMapping, int32 maxCol, int32 tabSize, bool wantsTabsAsSpaces,
|
|
|
|
bool indentCaseLabels);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern char8* BfParser_GetDebugExpressionAt(void* bfParser, int32 cursorIdx);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2021-12-25 20:14:23 +01:00
|
|
|
static extern void* BfParser_CreateResolvePassData(void* bfSystem, int32 resolveType, bool doFuzzyAutoComplete);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern bool BfParser_BuildDefs(void* bfParser, void* bfPassInstance, void* bfResolvePassData, bool fullRefresh);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern void BfParser_RemoveDefs(void* bfParser);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern void BfParser_ClassifySource(void* bfParser, void* elementTypeArray, bool preserveFlags);
|
|
|
|
|
2022-04-16 06:27:54 -07:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
|
|
|
static extern void BfParser_CreateClassifier(void* bfParser, void* passInstance, void* resolvePassData, void* elementTypeArray);
|
|
|
|
|
|
|
|
[CallingConvention(.Stdcall), CLink]
|
|
|
|
static extern void BfParser_FinishClassifier(void* bfParser, void* resolvePassData);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern void BfParser_GenerateAutoCompletionFrom(void* bfParser, int32 srcPosition);
|
|
|
|
|
2020-05-25 20:46:28 +08:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
2019-08-23 11:56:54 -07:00
|
|
|
static extern void BfParser_SetCompleteParse(void* bfParser);
|
|
|
|
|
2022-08-23 10:45:57 -07:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
|
|
|
static extern char8* BfSystem_GetParserLocationName(void* bfParser, int32 line, int32 column);
|
|
|
|
|
2022-08-23 19:13:15 +02:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
|
|
|
static extern void BfParser_GetLineCharAtIdx(void* bfParser, int32 idx, int32* line, int32* lineChar);
|
|
|
|
|
2022-08-23 20:00:48 +02:00
|
|
|
[CallingConvention(.Stdcall), CLink]
|
|
|
|
static extern int32 BfParser_GetIndexAtLine(void* bfParser, int32 line);
|
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public BfSystem mSystem;
|
|
|
|
public void* mNativeBfParser;
|
|
|
|
public bool mIsUsed;
|
|
|
|
public String mFileName ~ delete _;
|
|
|
|
public ProjectSource mProjectSource;
|
|
|
|
|
|
|
|
public this(void* nativeBfParser)
|
|
|
|
{
|
|
|
|
mNativeBfParser = nativeBfParser;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ~this()
|
|
|
|
{
|
|
|
|
if (mNativeBfParser != null)
|
|
|
|
BfSystem_DeleteParser(mSystem.mNativeBfSystem, mNativeBfParser);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Detach()
|
|
|
|
{
|
|
|
|
mNativeBfParser = null;
|
|
|
|
}
|
|
|
|
|
2022-05-26 15:39:32 -07:00
|
|
|
public void SetSource(StringView data, String fileName, int textVersion)
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
|
|
|
Debug.Assert(!mIsUsed);
|
|
|
|
mIsUsed = true;
|
2022-05-26 15:39:32 -07:00
|
|
|
BfParser_SetSource(mNativeBfParser, data.Ptr, (int32)data.Length, fileName, (.)textVersion);
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void SetCharIdData(ref IdSpan char8IdData)
|
|
|
|
{
|
|
|
|
char8IdData.Prepare();
|
|
|
|
uint8* data = char8IdData.mData.CArray();
|
|
|
|
BfParser_SetCharIdData(mNativeBfParser, data, char8IdData.mLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetCursorIdx(int cursorIdx)
|
|
|
|
{
|
|
|
|
BfParser_SetCursorIdx(mNativeBfParser, (int32)cursorIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAutocomplete(int cursorIdx)
|
|
|
|
{
|
|
|
|
BfParser_SetAutocomplete(mNativeBfParser, (int32)cursorIdx);
|
|
|
|
}
|
|
|
|
|
2022-04-16 06:27:54 -07:00
|
|
|
public void SetEmbedKind(SourceEmbedKind embedKind)
|
|
|
|
{
|
|
|
|
BfParser_SetEmbedKind(mNativeBfParser, embedKind);
|
|
|
|
}
|
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public void SetIsClassifying()
|
|
|
|
{
|
|
|
|
BfParser_SetIsClassifying(mNativeBfParser);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Parse(BfPassInstance passInstance, bool compatMode)
|
|
|
|
{
|
|
|
|
return BfParser_Parse(mNativeBfParser, passInstance.mNativeBfPassInstance, compatMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Reduce(BfPassInstance passInstance)
|
|
|
|
{
|
|
|
|
return BfParser_Reduce(mNativeBfParser, passInstance.mNativeBfPassInstance);
|
|
|
|
}
|
|
|
|
|
2022-04-16 08:23:43 -07:00
|
|
|
public void Reformat(int formatStart, int formatEnd, out int32[] charMapping, String str)
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
2022-04-16 08:23:43 -07:00
|
|
|
int32* charMappingPtr;
|
2021-12-21 11:12:32 +02:00
|
|
|
var maxCol = gApp.mSettings.mEditorSettings.mWrapCommentsAt;
|
2022-05-16 11:01:30 -07:00
|
|
|
var stringPtr = BfParser_Format(mNativeBfParser, (int32)formatStart, (int32)formatEnd, out charMappingPtr, maxCol,
|
|
|
|
gApp.mSettings.mEditorSettings.mTabSize, gApp.mSettings.mEditorSettings.mTabsOrSpaces == .Spaces, gApp.mSettings.mEditorSettings.mIndentCaseLabels);
|
2021-12-21 11:12:32 +02:00
|
|
|
str.Append(stringPtr);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2022-04-16 08:23:43 -07:00
|
|
|
charMapping = new int32[str.Length];
|
|
|
|
for (int32 i = 0; i < charMapping.Count; i++)
|
|
|
|
charMapping[i] = charMappingPtr[i];
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool GetDebugExpressionAt(int cursorIdx, String outExpr)
|
|
|
|
{
|
|
|
|
var stringPtr = BfParser_GetDebugExpressionAt(mNativeBfParser, (int32)cursorIdx);
|
|
|
|
if (stringPtr == null)
|
|
|
|
return false;
|
|
|
|
outExpr.Append(stringPtr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool BuildDefs(BfPassInstance bfPassInstance, BfResolvePassData resolvePassData, bool fullRefresh)
|
|
|
|
{
|
|
|
|
void* nativeResolvePassData = null;
|
|
|
|
if (resolvePassData != null)
|
|
|
|
nativeResolvePassData = resolvePassData.mNativeResolvePassData;
|
|
|
|
return BfParser_BuildDefs(mNativeBfParser, bfPassInstance.mNativeBfPassInstance, nativeResolvePassData, fullRefresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveDefs()
|
|
|
|
{
|
|
|
|
BfParser_RemoveDefs(mNativeBfParser);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ClassifySource(EditWidgetContent.CharData[] char8Data, bool preserveFlags)
|
|
|
|
{
|
|
|
|
EditWidgetContent.CharData* char8DataPtr = char8Data.CArray();
|
|
|
|
BfParser_ClassifySource(mNativeBfParser, char8DataPtr, preserveFlags);
|
|
|
|
}
|
|
|
|
|
2022-04-16 06:27:54 -07:00
|
|
|
public void CreateClassifier(BfPassInstance passInstance, BfResolvePassData bfResolvePassData, EditWidgetContent.CharData[] charDataArr)
|
|
|
|
{
|
|
|
|
EditWidgetContent.CharData* charDataPtr = charDataArr.CArray();
|
|
|
|
BfParser_CreateClassifier(mNativeBfParser, passInstance.mNativeBfPassInstance, bfResolvePassData.mNativeResolvePassData, charDataPtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void FinishClassifier(BfResolvePassData bfResolvePassData)
|
|
|
|
{
|
|
|
|
BfParser_FinishClassifier(mNativeBfParser, bfResolvePassData.mNativeResolvePassData);
|
|
|
|
}
|
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
public void SetNextRevision(BfParser nextRevision)
|
|
|
|
{
|
|
|
|
BfParser_SetNextRevision(mNativeBfParser, nextRevision.mNativeBfParser);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void GenerateAutoCompletionFrom(int32 srcPosition)
|
|
|
|
{
|
|
|
|
BfParser_GenerateAutoCompletionFrom(mNativeBfParser, srcPosition);
|
|
|
|
}
|
|
|
|
|
2021-12-25 20:14:23 +01:00
|
|
|
public BfResolvePassData CreateResolvePassData(ResolveType resolveType = ResolveType.Autocomplete, bool doFuzzyAutoComplete = false)
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
|
|
|
var resolvePassData = new BfResolvePassData();
|
2021-12-25 20:14:23 +01:00
|
|
|
resolvePassData.mNativeResolvePassData = BfParser_CreateResolvePassData(mNativeBfParser, (int32)resolveType, doFuzzyAutoComplete);
|
2019-08-23 11:56:54 -07:00
|
|
|
return resolvePassData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ReformatInto(SourceEditWidget editWidget, int formatStart, int formatEnd, uint8 orFlags = 0)
|
|
|
|
{
|
|
|
|
var editWidgetContent = (SourceEditWidgetContent)editWidget.Content;
|
|
|
|
|
2022-04-16 08:23:43 -07:00
|
|
|
editWidgetContent.mCollapseNoCheckOpen = true;
|
|
|
|
defer { editWidgetContent.mCollapseNoCheckOpen = false; }
|
|
|
|
|
2020-01-31 16:12:42 -08:00
|
|
|
let oldText = scope String();
|
|
|
|
editWidget.GetText(oldText);
|
|
|
|
/*File.WriteAllText(@"c:\temp\orig.txt", origText);*/
|
2019-08-23 11:56:54 -07:00
|
|
|
|
2022-04-16 08:23:43 -07:00
|
|
|
int32[] charMapping;
|
2019-08-23 11:56:54 -07:00
|
|
|
String newText = scope String();
|
2022-04-16 08:23:43 -07:00
|
|
|
Reformat(formatStart, formatEnd, out charMapping, newText);
|
|
|
|
defer delete charMapping;
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
//File.WriteAllText(@"c:\temp\new.txt", newText);
|
|
|
|
|
|
|
|
SourceEditBatchHelper sourceEditBatchHelper = scope SourceEditBatchHelper(editWidget, "format");
|
|
|
|
|
|
|
|
int32 insertCount = 0;
|
|
|
|
int32 deleteCount = 0;
|
|
|
|
|
|
|
|
int32 insertChars = 0;
|
|
|
|
int32 deleteChars = 0;
|
|
|
|
|
|
|
|
int32 insertStartIdx = -1;
|
|
|
|
int32 expectedOldIdx = 0;
|
2022-04-16 08:23:43 -07:00
|
|
|
for (int32 i = 0; i < charMapping.Count; i++)
|
2019-08-23 11:56:54 -07:00
|
|
|
{
|
2022-04-16 08:23:43 -07:00
|
|
|
int32 oldIdx = (int32)charMapping[i];
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
if ((oldIdx != -1) && (insertStartIdx != -1))
|
|
|
|
{
|
|
|
|
// Finish inserting
|
|
|
|
editWidgetContent.CursorTextPos = insertStartIdx;
|
|
|
|
|
|
|
|
String insertString = scope String();
|
|
|
|
//newText.Substring(insertStartIdx, i - insertStartIdx, insertString);
|
|
|
|
insertString.Append(newText, insertStartIdx, i - insertStartIdx);
|
|
|
|
var insertTextAction = new EditWidgetContent.InsertTextAction(editWidgetContent, insertString, .None);
|
|
|
|
insertTextAction.mMoveCursor = false;
|
|
|
|
editWidgetContent.mData.mUndoManager.Add(insertTextAction);
|
|
|
|
|
|
|
|
editWidgetContent.PhysInsertAtCursor(insertString, false);
|
|
|
|
|
|
|
|
if (orFlags != 0)
|
|
|
|
{
|
|
|
|
for (int32 idx = insertStartIdx; idx < i; idx++)
|
|
|
|
editWidgetContent.mData.mText[idx].mDisplayFlags |= orFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
insertStartIdx = -1;
|
|
|
|
insertCount++;
|
|
|
|
insertChars += (int32)insertString.Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldIdx == expectedOldIdx)
|
|
|
|
{
|
|
|
|
expectedOldIdx++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (oldIdx == -1)
|
|
|
|
{
|
|
|
|
if (insertStartIdx == -1)
|
|
|
|
insertStartIdx = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-01-31 16:12:42 -08:00
|
|
|
// This fails if we have the same ID occur multiple times, or we reorder nodes
|
|
|
|
if (oldIdx <= expectedOldIdx)
|
|
|
|
{
|
|
|
|
#if DEBUG
|
2020-06-17 05:13:53 -07:00
|
|
|
Utils.WriteTextFile(@"c:\temp\old.txt", oldText).IgnoreError();
|
|
|
|
Utils.WriteTextFile(@"c:\temp\new.txt", newText).IgnoreError();
|
2020-01-31 16:12:42 -08:00
|
|
|
Debug.FatalError("Reformat failed");
|
|
|
|
#endif
|
|
|
|
break; // Error - abort
|
|
|
|
}
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
int32 charsToDelete = oldIdx - expectedOldIdx;
|
|
|
|
editWidgetContent.CursorTextPos = i;
|
|
|
|
var deleteCharAction = new EditWidgetContent.DeleteCharAction(editWidgetContent, 0, charsToDelete);
|
|
|
|
deleteCharAction.mMoveCursor = false;
|
|
|
|
editWidgetContent.mData.mUndoManager.Add(deleteCharAction);
|
|
|
|
editWidgetContent.PhysDeleteChars(0, charsToDelete);
|
2022-04-16 08:23:43 -07:00
|
|
|
|
2019-08-23 11:56:54 -07:00
|
|
|
expectedOldIdx = oldIdx + 1;
|
|
|
|
deleteCount++;
|
|
|
|
deleteChars += charsToDelete;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
editWidgetContent.ContentChanged();
|
2022-05-24 06:20:35 -07:00
|
|
|
//Debug.WriteLine("Reformat {0} inserts, total of {1} chars. {2} deletes, total of {3} chars.", insertCount, insertChars, deleteCount, deleteChars);
|
2019-08-23 11:56:54 -07:00
|
|
|
|
|
|
|
sourceEditBatchHelper.Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetCompleteParse()
|
|
|
|
{
|
|
|
|
BfParser_SetCompleteParse(mNativeBfParser);
|
|
|
|
}
|
2020-03-23 12:07:05 -07:00
|
|
|
|
|
|
|
public void SetHashMD5(MD5Hash md5Hash)
|
|
|
|
{
|
|
|
|
var md5Hash;
|
|
|
|
BfParser_SetHashMD5(mNativeBfParser, ref md5Hash);
|
|
|
|
}
|
2022-08-23 19:13:15 +02:00
|
|
|
|
2022-08-23 10:45:57 -07:00
|
|
|
public void GetLocationName(int line, int column, String outBuffer)
|
|
|
|
{
|
|
|
|
var ptr = BfSystem_GetParserLocationName(mNativeBfParser, (.)line, (.)column);
|
|
|
|
if (ptr != null)
|
|
|
|
outBuffer.Append(ptr);
|
|
|
|
}
|
2022-08-23 19:56:42 +02:00
|
|
|
|
|
|
|
public (int, int) GetLineCharAtIdx(int idx)
|
|
|
|
{
|
2022-08-23 19:13:15 +02:00
|
|
|
int32 line = 0;
|
|
|
|
int32 char = 0;
|
|
|
|
|
|
|
|
BfParser_GetLineCharAtIdx(mNativeBfParser, (.) idx, &line, &char);
|
|
|
|
|
|
|
|
return (line, char);
|
|
|
|
}
|
2022-08-23 20:00:48 +02:00
|
|
|
|
|
|
|
public int GetIndexAtLine(int line)
|
|
|
|
{
|
|
|
|
return BfParser_GetIndexAtLine(mNativeBfParser, (.) line);
|
|
|
|
}
|
2019-08-23 11:56:54 -07:00
|
|
|
}
|
|
|
|
}
|