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

Debugger mouseover improvements

This commit is contained in:
Brian Fiete 2024-12-31 07:48:03 -08:00
parent 4f0ad540a7
commit 4f2c28862d
8 changed files with 161 additions and 61 deletions

View file

@ -5645,8 +5645,22 @@ namespace IDE.ui
if ((mHoverResolveTask == null) && if ((mHoverResolveTask == null) &&
((debugExpr == null) || (!debugExpr.StartsWith(':')))) ((debugExpr == null) || (!debugExpr.StartsWith(':'))))
{ {
bool wantDebugEval = false;
if ((gApp.mDebugger.mIsRunning) && (!String.IsNullOrEmpty(debugExpr)))
{
wantDebugEval = true;
if (FilteredProjectSource != null)
{
// This is active Beef source
if ((debugExpr[0].IsNumber) || (debugExpr.StartsWith('\'')) || (debugExpr.StartsWith('"')))
{
// Literal, don't debug eval
wantDebugEval = false;
}
}
}
if (((!gApp.mDebugger.mIsRunning) || (!mHoverWatch.HasDisplay)) && // Don't show extended information for debug watches if (((!wantDebugEval) || (!mHoverWatch.HasDisplay)) && // Don't show extended information for debug watches
(!handlingHoverResolveTask) && (ResolveCompiler != null) && (!ResolveCompiler.mThreadWorkerHi.mThreadRunning) && (gApp.mSettings.mEditorSettings.mHiliteCursorReferences) && (!gApp.mDeterministic)) (!handlingHoverResolveTask) && (ResolveCompiler != null) && (!ResolveCompiler.mThreadWorkerHi.mThreadRunning) && (gApp.mSettings.mEditorSettings.mHiliteCursorReferences) && (!gApp.mDeterministic))
{ {
ResolveParams resolveParams = new .(); ResolveParams resolveParams = new .();

View file

@ -2635,9 +2635,9 @@ namespace IDE.ui
} }
var dispStr = scope String(); var dispStr = scope String();
dispStr.AppendF(mWatchSeriesInfo.mDisplayTemplate, params formatParams); dispStr.AppendF(mWatchSeriesInfo.mDisplayTemplate, params formatParams).IgnoreError();
var evalStr = scope String(); var evalStr = scope String();
evalStr.AppendF(mWatchSeriesInfo.mEvalTemplate, params formatParams); evalStr.AppendF(mWatchSeriesInfo.mEvalTemplate, params formatParams).IgnoreError();
watchListView.mWatchOwner.SetupListViewItem(curWatchListViewItem, dispStr, evalStr); watchListView.mWatchOwner.SetupListViewItem(curWatchListViewItem, dispStr, evalStr);
curWatchListViewItem.mWatchEntry.mSeriesFirstVersion = mWatchSeriesInfo.mSeriesFirstVersion; curWatchListViewItem.mWatchEntry.mSeriesFirstVersion = mWatchSeriesInfo.mSeriesFirstVersion;

View file

@ -2957,6 +2957,55 @@ void BfAutoComplete::CheckVarResolution(BfAstNode* varTypeRef, BfType* resolvedT
} }
} }
class BfAutocompleteNodeChecker : public BfStructuralVisitor
{
public:
BfAutoComplete* mAutoComplete;
bool mSelected;
public:
BfAutocompleteNodeChecker(BfAutoComplete* autoComplete)
{
mAutoComplete = autoComplete;
mSelected = false;
}
virtual void Visit(BfAstNode* bfAstNode) override
{
mSelected = mAutoComplete->IsAutocompleteNode(bfAstNode);
}
virtual void Visit(BfBinaryOperatorExpression* binOpExpr) override
{
mSelected = mAutoComplete->IsAutocompleteNode(binOpExpr->mOpToken);
}
virtual void Visit(BfUnaryOperatorExpression* unaryOpExpr) override
{
VisitChild(unaryOpExpr->mExpression);
}
virtual void Visit(BfCastExpression* castExpr) override
{
VisitChild(castExpr->mExpression);
}
virtual void Visit(BfLiteralExpression* literalExpr) override
{
mSelected = mAutoComplete->IsAutocompleteNode(literalExpr);
}
virtual void Visit(BfIdentifierNode* identifierNode) override
{
mSelected = mAutoComplete->IsAutocompleteNode(identifierNode);
}
virtual void Visit(BfMemberReferenceExpression* memberRefExpr) override
{
mSelected = mAutoComplete->IsAutocompleteNode(memberRefExpr->mMemberName);
}
};
void BfAutoComplete::CheckResult(BfAstNode* node, const BfTypedValue& typedValue) void BfAutoComplete::CheckResult(BfAstNode* node, const BfTypedValue& typedValue)
{ {
if (mResolveType != BfResolveType_GetResultString) if (mResolveType != BfResolveType_GetResultString)
@ -2967,20 +3016,26 @@ void BfAutoComplete::CheckResult(BfAstNode* node, const BfTypedValue& typedValue
if (!typedValue.mValue.IsConst()) if (!typedValue.mValue.IsConst())
return; return;
if (typedValue.mType->IsPointer()) if (typedValue.mType->IsPointer())
return; return;
if (typedValue.mType->IsObject()) if (typedValue.mType->IsObject())
return; return;
auto constant = mModule->mBfIRBuilder->GetConstant(typedValue.mValue); BfAutocompleteNodeChecker autocompleteNodeChecker(this);
if (BfIRConstHolder::IsInt(constant->mTypeCode)) autocompleteNodeChecker.VisitChildNoRef(node);
if (!autocompleteNodeChecker.mSelected)
return;
String constStr = ConstantToString(mModule->mBfIRBuilder, typedValue);
if (!constStr.IsEmpty())
{ {
mResultString = StrFormat(":%lld", constant->mInt64); mResultString = ":";
mResultString += constStr;
AddResultTypeKind(typedValue.mType);
} }
else if (BfIRConstHolder::IsFloat(constant->mTypeCode)) else
{ {
mResultString = StrFormat(":%f", constant->mDouble); SetResultStringType(typedValue.mType);
} }
} }
@ -3041,7 +3096,7 @@ void BfAutoComplete::CheckLocalRef(BfAstNode* identifierNode, BfLocalVariable* v
{ {
String constStr; String constStr;
if (varDecl->mConstValue.IsConst()) if (varDecl->mConstValue.IsConst())
constStr = ConstantToString(mModule->mBfIRBuilder, varDecl->mConstValue); constStr = ConstantToString(mModule->mBfIRBuilder, BfTypedValue(varDecl->mConstValue, varDecl->mResolvedType));
if (!constStr.IsEmpty()) if (!constStr.IsEmpty())
{ {
mResultString = constStr; mResultString = constStr;
@ -3699,11 +3754,21 @@ String BfAutoComplete::FixitGetLocation(BfParserData* parser, int insertPos)
return StrFormat("%s|%d:%d", parser->mFileName.c_str(), line, lineChar); return StrFormat("%s|%d:%d", parser->mFileName.c_str(), line, lineChar);
} }
String BfAutoComplete::ConstantToString(BfIRConstHolder* constHolder, BfIRValue id) String BfAutoComplete::ConstantToString(BfIRConstHolder* constHolder, BfTypedValue typedValue)
{ {
SetAndRestoreValue<BfTypeInstance*> prevTypeInst(mModule->mCurTypeInstance, typedValue.mType->ToTypeInstance());
SetAndRestoreValue<BfMethodInstance*> prevMethodInst(mModule->mCurMethodInstance, NULL);
BF_ASSERT(typedValue.mValue.IsConst());
String result;
result = "(";
result += mModule->TypeToString(typedValue.mType);
result += ")";
char str[32]; char str[32];
int stringId = mModule->GetStringPoolIdx(id, constHolder); int stringId = mModule->GetStringPoolIdx(typedValue.mValue, constHolder);
if (stringId != -1) if (stringId != -1)
{ {
BfStringPoolEntry* entry; BfStringPoolEntry* entry;
@ -3716,49 +3781,52 @@ String BfAutoComplete::ConstantToString(BfIRConstHolder* constHolder, BfIRValue
} }
} }
auto constant = constHolder->GetConstant(id); auto constant = constHolder->GetConstant(typedValue.mValue);
switch (constant->mTypeCode) switch (constant->mTypeCode)
{ {
case BfTypeCode_Boolean: case BfTypeCode_Boolean:
return StrFormat(":(bool) %s", constant->mBool ? "true" : "false"); result += StrFormat(" %s", constant->mBool ? "true" : "false");
break;
case BfTypeCode_UInt8: case BfTypeCode_UInt8:
return StrFormat(":(uint8) %llu", constant->mUInt64); result += StrFormat(" %llu", constant->mUInt64);
break;
case BfTypeCode_UInt16: case BfTypeCode_UInt16:
return StrFormat(":(uint16) %llu", constant->mUInt64); result += StrFormat(" %llu", constant->mUInt64);
break;
case BfTypeCode_UInt32: case BfTypeCode_UInt32:
return StrFormat(":(uint32) %llu", constant->mUInt64); result += StrFormat(" %llu", constant->mUInt64);
break;
case BfTypeCode_UInt64: case BfTypeCode_UInt64:
return StrFormat(":(uint64) %llu", constant->mUInt64); result += StrFormat(" %llu", constant->mUInt64);
break;
case BfTypeCode_Int8: case BfTypeCode_Int8:
return StrFormat(":(int8) %lld", constant->mInt64); result += StrFormat(" %lld", constant->mInt64);
break;
case BfTypeCode_Int16: case BfTypeCode_Int16:
return StrFormat(":(int16) %lld", constant->mInt64); result += StrFormat(" %lld", constant->mInt64);
break;
case BfTypeCode_Int32: case BfTypeCode_Int32:
return StrFormat(":(int32) %lld", constant->mInt64); result += StrFormat(" %lld", constant->mInt64);
break;
case BfTypeCode_Int64: case BfTypeCode_Int64:
return StrFormat(":(int64) %lld", constant->mInt64); result += StrFormat(" %lld", constant->mInt64);
break;
case BfTypeCode_Float: case BfTypeCode_Float:
{
ExactMinimalFloatToStr((float)constant->mDouble, str); ExactMinimalFloatToStr((float)constant->mDouble, str);
String result; result += " ";
result += str; result += str;
result += "f"; result += "f";
return result;
}
case BfTypeCode_Double:
{
ExactMinimalDoubleToStr(constant->mDouble, str);
String result;
result += str;
return result;
}
default:
break; break;
case BfTypeCode_Double:
ExactMinimalDoubleToStr(constant->mDouble, str);
result += " ";
result += str;
break;
default:
return "";
} }
return ""; return result;
} }
void BfAutoComplete::FixitAddMethod(BfTypeInstance* typeInst, const StringImpl& methodName, BfType* returnType, const BfTypeVector& paramTypes, bool wantStatic) void BfAutoComplete::FixitAddMethod(BfTypeInstance* typeInst, const StringImpl& methodName, BfType* returnType, const BfTypeVector& paramTypes, bool wantStatic)
@ -3946,13 +4014,8 @@ void BfAutoComplete::FixitAddConstructor(BfTypeInstance *typeInstance)
} }
} }
void BfAutoComplete::SetResultStringType(BfType * type) void BfAutoComplete::AddResultTypeKind(BfType* type)
{ {
SetAndRestoreValue<BfTypeInstance*> prevTypeInst(mModule->mCurTypeInstance, type->ToTypeInstance());
SetAndRestoreValue<BfMethodInstance*> prevMethodInst(mModule->mCurMethodInstance, NULL);
mResultString = ":";
mResultString += mModule->TypeToString(type);
if (type->IsObject()) if (type->IsObject())
mResultString += "\n:type\tclass"; mResultString += "\n:type\tclass";
else if (type->IsInterface()) else if (type->IsInterface())
@ -3963,6 +4026,16 @@ void BfAutoComplete::SetResultStringType(BfType * type)
mResultString += "\n:type\tvaluetype"; mResultString += "\n:type\tvaluetype";
} }
void BfAutoComplete::SetResultStringType(BfType* type)
{
SetAndRestoreValue<BfTypeInstance*> prevTypeInst(mModule->mCurTypeInstance, type->ToTypeInstance());
SetAndRestoreValue<BfMethodInstance*> prevMethodInst(mModule->mCurMethodInstance, NULL);
mResultString = ":";
mResultString += mModule->TypeToString(type);
AddResultTypeKind(type);
}
void BfAutoComplete::FixitAddFullyQualify(BfAstNode* refNode, const StringImpl& findName, const SizedArrayImpl<BfUsingFieldData::MemberRef>& foundList) void BfAutoComplete::FixitAddFullyQualify(BfAstNode* refNode, const StringImpl& findName, const SizedArrayImpl<BfUsingFieldData::MemberRef>& foundList)
{ {
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None; BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;

View file

@ -244,7 +244,7 @@ public:
void FixitGetParamString(const BfTypeVector& paramTypes, StringImpl& outStr); void FixitGetParamString(const BfTypeVector& paramTypes, StringImpl& outStr);
int FixitGetMemberInsertPos(BfTypeDef* typeDef); int FixitGetMemberInsertPos(BfTypeDef* typeDef);
String FixitGetLocation(BfParserData* parserData, int insertPos); String FixitGetLocation(BfParserData* parserData, int insertPos);
String ConstantToString(BfIRConstHolder* constHolder, BfIRValue id); String ConstantToString(BfIRConstHolder* constHolder, BfTypedValue typedValue);
public: public:
BfAutoComplete(BfResolveType resolveType = BfResolveType_Autocomplete, bool doFuzzyAutoComplete = false); BfAutoComplete(BfResolveType resolveType = BfResolveType_Autocomplete, bool doFuzzyAutoComplete = false);
@ -283,6 +283,7 @@ public:
void FixitAddConstructor(BfTypeInstance* typeInstance); void FixitAddConstructor(BfTypeInstance* typeInstance);
void FixitAddFullyQualify(BfAstNode* refNode, const StringImpl& findName, const SizedArrayImpl<BfUsingFieldData::MemberRef>& foundList); void FixitAddFullyQualify(BfAstNode* refNode, const StringImpl& findName, const SizedArrayImpl<BfUsingFieldData::MemberRef>& foundList);
void AddResultTypeKind(BfType* type);
void SetResultStringType(BfType* type); void SetResultStringType(BfType* type);
}; };

View file

@ -167,7 +167,7 @@ BfTypedValue BfConstResolver::Resolve(BfExpression* expr, BfType* wantType, BfCo
} }
else else
{ {
mResult = mModule->Cast(expr, mResult, wantType, (BfCastFlags)(BfCastFlags_WantsConst | BfCastFlags_NoConversionOperator | (explicitCast ? BfCastFlags_Explicit : BfCastFlags_None))); mResult = mModule->Cast(expr, mResult, wantType, (BfCastFlags)(BfCastFlags_WantsConst | (explicitCast ? BfCastFlags_Explicit : BfCastFlags_None)));
} }
} }
@ -399,7 +399,7 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch
if (argExpr != NULL) if (argExpr != NULL)
{ {
argValue = mModule->Cast(argExpr, argValue, wantType, (BfCastFlags)(BfCastFlags_WantsConst | BfCastFlags_NoConversionOperator)); argValue = mModule->Cast(argExpr, argValue, wantType, (BfCastFlags)(BfCastFlags_WantsConst));
if (!argValue) if (!argValue)
return false; return false;
} }

View file

@ -5172,7 +5172,7 @@ BfTypedValue BfExprEvaluator::LoadField(BfAstNode* targetSrc, BfTypedValue targe
if (fieldInstance->mConstIdx != -1) if (fieldInstance->mConstIdx != -1)
{ {
String constStr = autoComplete->ConstantToString(typeInstance->mConstHolder, BfIRValue(BfIRValueFlags_Const, fieldInstance->mConstIdx)); String constStr = autoComplete->ConstantToString(typeInstance->mConstHolder, BfTypedValue(BfIRValue(BfIRValueFlags_Const, fieldInstance->mConstIdx), fieldInstance->mResolvedType));
if (!constStr.IsEmpty()) if (!constStr.IsEmpty())
{ {
autoComplete->mResultString += " = "; autoComplete->mResultString += " = ";

View file

@ -4670,6 +4670,10 @@ BfTypedValue BfModule::GetFieldInitializerValue(BfFieldInstance* fieldInstance,
if (mCompiler->mCeMachine->mExecuteId != ceExecuteId) if (mCompiler->mCeMachine->mExecuteId != ceExecuteId)
fieldInstance->mHadConstEval = true; fieldInstance->mHadConstEval = true;
} }
if (auto autoComplete = mCompiler->GetAutoComplete())
autoComplete->CheckResult(initializer, result);
return result; return result;
} }
} }
@ -9240,6 +9244,9 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExprEvaluator& exprEvaluator,
if ((typedVal.mType->IsValueType()) && ((flags & BfEvalExprFlags_NoValueAddr) != 0)) if ((typedVal.mType->IsValueType()) && ((flags & BfEvalExprFlags_NoValueAddr) != 0))
typedVal = LoadValue(typedVal, 0, exprEvaluator.mIsVolatileReference); typedVal = LoadValue(typedVal, 0, exprEvaluator.mIsVolatileReference);
if (auto autoComplete = mCompiler->GetAutoComplete())
autoComplete->CheckResult(expr, typedVal);
return typedVal; return typedVal;
} }

View file

@ -1778,6 +1778,11 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
resolvedType = initValue.mType; resolvedType = initValue.mType;
unresolvedType = resolvedType; unresolvedType = resolvedType;
} }
if (auto autoComplete = mCompiler->GetAutoComplete())
{
autoComplete->CheckResult(varDecl->mInitializer, initValue);
}
} }
if ((!handledVarInit) && (!isConst)) if ((!handledVarInit) && (!isConst))
{ {