Skip to content

Commit

Permalink
misc improvements for debug logging resolver issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Feb 14, 2024
1 parent e235ec2 commit b171b19
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 211 deletions.
46 changes: 40 additions & 6 deletions src/main/java/com/intellij/plugins/haxe/lang/psi/HaxeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ private List<? extends PsiElement> doResolveInner(@NotNull HaxeReference referen
String currentQname = enumValueDeclaration.getContainingClass().getQualifiedName();
String data = typeHintPsi.getUserData(typeHintKey);
if (currentQname != null && currentQname.equals(data)) {
LogResolution(reference, "via import & typeHintKey");
return List.of(element);
}
}
Expand All @@ -242,6 +243,7 @@ private List<? extends PsiElement> doResolveInner(@NotNull HaxeReference referen
int currentSize =
Optional.ofNullable(enumValueDeclaration.getParameterList()).map(p -> p.getParameterList().size()).orElse(0);
if (expectedSize == currentSize) {
LogResolution(reference, "via import & enum value declaration");
return List.of(element);
}
}
Expand Down Expand Up @@ -277,11 +279,23 @@ private List<? extends PsiElement> doResolveInner(@NotNull HaxeReference referen
// to avoid caching empty due to already being resolved we mark
// elements so we know if we want to cache as not found or just skip (null is not cached, empty list is cached)
if (reference.getUserData(skipCacheKey) == Boolean.TRUE) {
if (log.isTraceEnabled()) {
String message = "result is empty and skip cache flag is true, skipping cache for: " + referenceText;
traceAs(log, HaxeDebugUtil.getCallerStackFrame(), message);
}
return null;
}else {
if (log.isTraceEnabled()){
String message = "result is empty caching not found for :" + referenceText;
traceAs(log, HaxeDebugUtil.getCallerStackFrame(), message);
}
return EMPTY_LIST;
}
}else {
if (log.isTraceEnabled()){
String message = "caching result for :" + referenceText;
traceAs(log, HaxeDebugUtil.getCallerStackFrame(), message);
}
return result;
}
}
Expand Down Expand Up @@ -357,7 +371,10 @@ private static List<HaxeNamedComponent> findEnumMember(HaxeReference reference,
HaxeClass haxeClass = classReference.getHaxeClass();
if (haxeClass != null) {
HaxeNamedComponent name = haxeClass.findHaxeMemberByName(reference.getText(), null);
if (name != null) return List.of(name);
if (name != null) {
LogResolution(reference, "via enum member name.");
return List.of(name);
}
}
}
}
Expand All @@ -369,7 +386,10 @@ private List<? extends PsiElement> checkGlobalAlias(HaxeReference reference) {
if (!ApplicationManager.getApplication().isUnitTestMode()) {
HaxeProjectModel haxeProjectModel = HaxeProjectModel.fromElement(reference);
HaxeModel model = haxeProjectModel.getLogPackage().resolveTrace();
if (model != null) return List.of(model.getBasePsi());
if (model != null){
LogResolution(reference, "via global alias");
return List.of(model.getBasePsi());
}
}
}
return null;
Expand All @@ -380,7 +400,10 @@ private static List<PsiElement> searchInSameFile(@NotNull HaxeReference referenc
if(fileModel != null) {
String className = reference.getText();
PsiElement target = HaxeResolveUtil.searchInSameFile(fileModel, className, isType);
if (target!= null) return List.of(target);
if (target!= null) {
LogResolution(reference, "via search In Same File");
return List.of(target);
}
}
return null;
}
Expand Down Expand Up @@ -482,7 +505,9 @@ private List<? extends PsiElement> checkEnumExtractor(HaxeReference reference) {
SpecificHaxeClassReference classReference = HaxeResolveUtil.resolveExtractorEnum(argumentExtractor);
if (classReference != null) {
HaxeEnumValueDeclaration declaration = HaxeResolveUtil.resolveExtractorEnumValueDeclaration(classReference, argumentExtractor);
if (declaration!= null) return List.of(declaration);
if (declaration!= null)
LogResolution(reference, "via enum extractor");
return List.of(declaration);
}
}else {
// Last attempt to resolve enum value (not extractor), normally imports would solve this but some typedefs can omit this.
Expand All @@ -496,7 +521,10 @@ private List<? extends PsiElement> checkEnumExtractor(HaxeReference reference) {
if(haxeClass != null && haxeClass.isEnum()) {
SpecificHaxeClassReference classReference = result.getSpecificClassReference(haxeClass, null);
HaxeEnumValueDeclaration declaration = HaxeResolveUtil.resolveExtractorEnumValueDeclaration(classReference, reference.getText());
if (declaration!= null) return List.of(declaration);
if (declaration!= null) {
LogResolution(reference, "via enum extractor");
return List.of(declaration);
}
}
}

Expand All @@ -516,6 +544,7 @@ private List<? extends PsiElement> checkCaptureVarReference(HaxeReference refere
if (haxeExpression instanceof HaxeExtractorMatchExpression matchExpression) {
HaxeExpression PossibleCapture = matchExpression.getSwitchCaseExpr().getExpression();
if (PossibleCapture != null && PossibleCapture.textMatches(reference)) {
LogResolution(reference, "via switch argument extractor");
return List.of(PossibleCapture);
}
}
Expand All @@ -524,6 +553,7 @@ private List<? extends PsiElement> checkCaptureVarReference(HaxeReference refere
else if (expression instanceof HaxeExtractorMatchExpression matchExpression) {
HaxeReferenceExpression referenceFromExtractor = getReferenceFromExtractorMatchExpression(matchExpression);
if (referenceFromExtractor!= null && reference.textMatches(referenceFromExtractor)) {
LogResolution(reference, "via witch extractor");
return List.of(referenceFromExtractor);
}
}
Expand Down Expand Up @@ -557,6 +587,7 @@ private List<? extends PsiElement> checkCaptureVar(HaxeReference reference) {
HaxeExtractorMatchExpression matchExpression = PsiTreeUtil.getParentOfType(reference, HaxeExtractorMatchExpression.class);
if (matchExpression!= null) {
if (matchExpression.getSwitchCaseExpr().textMatches(reference.getText())) {
LogResolution(reference, "via Capture Var");
return List.of(matchExpression.getExpression());
}
}
Expand Down Expand Up @@ -587,7 +618,9 @@ private List<? extends PsiElement> checkIsSwitchVar(HaxeReference reference) {

// try to resolve reference for guard and block (ex. `case [a, b] if ( b > a): b + ">" + a;`)
if (result == null) result = tryResolveVariableForGuardsAndBlock(reference);

if (result != null) {
LogResolution(reference, "via switch var");
}
return result;
}

Expand Down Expand Up @@ -822,6 +855,7 @@ private List<? extends PsiElement> checkIsAlias(HaxeReference reference) {
if (alias != null) {
HaxeIdentifier identifier = alias.getIdentifier();
if (identifier.textMatches(reference)) {
LogResolution(reference, "via import alias name.");
return List.of(alias);
}
}
Expand Down
Loading

0 comments on commit b171b19

Please sign in to comment.