1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Added support for autocomplete inserting property overrides

This commit is contained in:
Brian Fiete 2019-09-29 09:21:51 -07:00
parent ce66b658c4
commit c931f92632
4 changed files with 148 additions and 28 deletions

View file

@ -152,6 +152,33 @@ class Norg
{
return a + b + c + bl.mA;
}
public virtual int Zorf
{
set
{
}
}
public virtual int GetVal()
{
return 99;
}
}
class Norg2 : Norg
{
public override void Zorf
{
set
{
base.Zorf = 123;
}
}
}
struct Blurg

View file

@ -2198,7 +2198,7 @@ namespace IDE.ui
}*/
}
public void InsertSelection(char32 keyChar, String insertType = null)
public void InsertSelection(char32 keyChar, String insertType = null, String insertStr = null)
{
//Debug.WriteLine("InsertSelection");
@ -2223,6 +2223,9 @@ namespace IDE.ui
}
}
if (insertStr != null)
insertStr.Append(entry.mEntryInsert ?? entry.mEntryDisplay);
if (entry.mEntryType == "fixit")
{
if (insertType != null)
@ -2240,7 +2243,7 @@ namespace IDE.ui
if (tabIdx != -1)
{
implText = scope:: String();
implText.Append(insertText, tabIdx + 1);
implText.Append(insertText, tabIdx);
insertText.RemoveToEnd(tabIdx);
}
String prevText = scope String();
@ -2294,13 +2297,52 @@ namespace IDE.ui
UpdateAsyncInfo();*/
if (implText != null)
{
String implSect = scope .();
int startIdx = 0;
for (int i < implText.Length)
{
char8 c = implText[i];
if ((c == '\t') || (c == '\b') || (c == '\r'))
{
implSect.Clear();
implSect.Append(implText, startIdx, i - startIdx);
if (!implSect.IsEmpty)
{
sourceEditWidgetContent.InsertAtCursor(implSect);
}
if (c == '\t')
{
sourceEditWidgetContent.InsertAtCursor("\n");
sourceEditWidgetContent.CursorToLineEnd();
sourceEditWidgetContent.OpenCodeBlock();
var lineAndColumn = sourceEditWidgetContent.CursorLineAndColumn;
sourceEditWidgetContent.InsertAtCursor(implText);
sourceEditWidgetContent.CursorLineAndColumn = lineAndColumn;
}
else if (c == '\r')
{
sourceEditWidgetContent.InsertAtCursor("\n");
sourceEditWidgetContent.CursorToLineEnd();
}
else
{
let lc = sourceEditWidgetContent.CursorLineAndColumn;
sourceEditWidgetContent.CursorLineAndColumn = .(lc.mLine + 1, 0);
sourceEditWidgetContent.CursorToLineEnd();
sourceEditWidgetContent.InsertAtCursor("\n");
sourceEditWidgetContent.CursorToLineEnd();
}
startIdx = i + 1;
}
}
implSect.Clear();
implSect.Append(implText, startIdx, implText.Length - startIdx);
if (!implSect.IsEmpty)
{
sourceEditWidgetContent.InsertAtCursor(implSect);
}
}
if (persistentInvokeSrcPositons != null)

View file

@ -2184,12 +2184,14 @@ namespace IDE.ui
bool allowChar = true;
mIsInKeyChar = true;
String insertType = scope String();
mAutoComplete.InsertSelection(theChar, insertType);
String insertStr = scope String();
mAutoComplete.InsertSelection(theChar, insertType, insertStr);
mIsInKeyChar = false;
if (insertType != null)
{
//mGenerateAutocompleteHandler(false, false);
if ((insertType == "method") && (theChar == '('))
if (((insertType == "method") && (theChar == '(')) ||
((insertType == "token") && (insertStr == "override")))
{
if (IsCursorVisible(false))
mOnGenerateAutocomplete('\0', default);

View file

@ -1863,8 +1863,6 @@ void BfAutoComplete::AddOverrides(const StringImpl& filter)
continue;
}
if (methodDef->mMethodType == BfMethodType_Normal)
{
auto& methodGroup = curType->mMethodInstanceGroups[methodDef->mIdx];
if (methodGroup.mDefault == NULL)
{
@ -1873,20 +1871,22 @@ void BfAutoComplete::AddOverrides(const StringImpl& filter)
auto methodInst = methodGroup.mDefault;
if ((methodDef->mIsVirtual) && (!methodDef->mIsOverride))
{
if (methodDef->mMethodType == BfMethodType_Normal)
{
String methodPrefix;
String methodName;
String impString;
if (!methodInst->mReturnType->IsVoid())
impString = "return ";
bool isAbstract = methodDef->mIsAbstract;
if (!isAbstract)
{
if (!methodInst->mReturnType->IsVoid())
impString = "return ";
impString += "base.";
impString += methodDef->mName;;
impString += methodDef->mName;
impString += "(";
}
@ -1918,7 +1918,56 @@ void BfAutoComplete::AddOverrides(const StringImpl& filter)
if (!isAbstract)
impString += ");";
AddEntry(AutoCompleteEntry("override", methodName + "\t" + methodPrefix + methodName + "\t" + impString, methodDeclaration->mDocumentation), filter);
AddEntry(AutoCompleteEntry("override", methodName + "\t" + methodPrefix + methodName + "\t" + impString, NULL), filter);
}
else if ((methodDef->mMethodType == BfMethodType_PropertyGetter) || (methodDef->mMethodType == BfMethodType_PropertySetter))
{
auto propDeclaration = methodDef->GetPropertyDeclaration();
bool hasGet = propDeclaration->GetMethod("get") != NULL;
bool hasSet = propDeclaration->GetMethod("set") != NULL;
if ((methodDef->mMethodType == BfMethodType_PropertyGetter) || (!hasGet))
{
String propName;
String impl;
propDeclaration->mNameNode->ToString(propName);
bool isAbstract = methodDef->mIsAbstract;
if (propDeclaration->mProtectionSpecifier != NULL)
impl += propDeclaration->mProtectionSpecifier->ToString() + " ";
impl += "override ";
impl += mModule->TypeToString(methodInst->mReturnType, BfTypeNameFlag_ReduceName);
impl += " ";
impl += propName;
impl += "\t";
if (hasGet)
{
impl += "get\t";
if (!isAbstract)
{
impl += "return base.";
impl += propName;
impl += ";";
}
}
if (hasSet)
{
if (hasGet)
impl += "\b\r";
impl += "set\t";
if (!isAbstract)
{
impl += "base.";
impl += propName;
impl += " = value;";
}
}
AddEntry(AutoCompleteEntry("override", propName + "\t" + impl, NULL), filter);
}
}
}
}