private static string GetTooltipText(SymbolDefinition symbol, ParseTree.Leaf leaf) { if (symbol.kind == SymbolKind.Method) { var method = symbol as MethodDefinition; if (method != null && method.IsExtensionMethod) { var nodeLeft = leaf.parent; if (nodeLeft != null && nodeLeft.RuleName == "accessIdentifier") { nodeLeft = nodeLeft.FindPreviousNode() as ParseTree.Node; if (nodeLeft != null && (nodeLeft.RuleName == "primaryExpressionPart" || nodeLeft.RuleName == "primaryExpressionStart")) { var symbolLeft = FGResolver.GetResolvedSymbol(nodeLeft); if (symbolLeft != null && symbolLeft.kind != SymbolKind.Error && !(symbolLeft is TypeDefinitionBase)) { return(symbol.GetTooltipTextAsExtensionMethod()); } } } } } return(symbol.GetTooltipText()); }
static FindResultsWindow.ResultType ValidateResultAsReference(string assetGuid, TextPosition location, int length, ref SymbolDefinition referencedSymbol) { var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid); if (string.IsNullOrEmpty(assetPath)) { return(FindResultsWindow.ResultType.RemoveResult); } var isCsScript = assetPath.EndsWith(".cs", System.StringComparison.OrdinalIgnoreCase); var buffer = FGTextBufferManager.GetBuffer(assetGuid); if (buffer == null) { return(FindResultsWindow.ResultType.RemoveResult); } if (buffer.Parser == null) { buffer.LoadImmediately(); referencedSymbol = referencedSymbol.Rebind(); } var formatedLine = buffer.formatedLines[location.line]; var textLine = buffer.lines[location.line]; var isVarResult = length == 3 && (referencedSymbol is TypeDefinitionBase) && textLine.Substring(location.index, length) == "var"; if (isCsScript) { if (formatedLine.regionTree.kind > FGTextBuffer.RegionTree.Kind.LastActive) { if (isVarResult) { return(FindResultsWindow.ResultType.RemoveResult); } return(FindResultsWindow.ResultType.InactiveCode); } } else if (isVarResult) { return(FindResultsWindow.ResultType.RemoveResult); } int tokenIndex; bool atTokenEnd; var token = buffer.GetTokenAt(new TextPosition(location.line, location.index + 1), out location.line, out tokenIndex, out atTokenEnd); switch (token.tokenKind) { case SyntaxToken.Kind.Preprocessor: return(FindResultsWindow.ResultType.RemoveResult); case SyntaxToken.Kind.Comment: case SyntaxToken.Kind.PreprocessorArguments: case SyntaxToken.Kind.PreprocessorSymbol: if (isVarResult) { return(FindResultsWindow.ResultType.RemoveResult); } return(FindResultsWindow.ResultType.Comment); case SyntaxToken.Kind.StringLiteral: case SyntaxToken.Kind.VerbatimStringLiteral: if (isVarResult) { return(FindResultsWindow.ResultType.RemoveResult); } return(FindResultsWindow.ResultType.String); } if (!isCsScript || token.parent == null) { return(FindResultsWindow.ResultType.UnresolvedSymbol); } var resolvedSymbol = token.parent.resolvedSymbol; if (resolvedSymbol == null || resolvedSymbol.kind == SymbolKind.Error) { FGResolver.ResolveNode(token.parent.parent); } if (resolvedSymbol != null && resolvedSymbol.kind == SymbolKind.MethodGroup && token.parent.parent != null) { var nextLeaf = token.parent.parent.FindNextLeaf(); if (nextLeaf != null && nextLeaf.IsLit("(")) { var nextNode = nextLeaf.parent; if (nextNode.RuleName == "arguments") { FGResolver.ResolveNode(nextNode); if (token.parent != null) { if (token.parent.resolvedSymbol == null || token.parent.resolvedSymbol.kind == SymbolKind.Error) { token.parent.resolvedSymbol = resolvedSymbol; } } } } } resolvedSymbol = token.parent != null ? token.parent.resolvedSymbol : null; if (resolvedSymbol == null || resolvedSymbol.kind == SymbolKind.Error) { return(FindResultsWindow.ResultType.UnresolvedSymbol); } if (resolvedSymbol.kind == SymbolKind.Constructor || resolvedSymbol.kind == SymbolKind.Destructor) { resolvedSymbol = resolvedSymbol.parentSymbol; } if (resolvedSymbol == null || resolvedSymbol.kind == SymbolKind.Error) { return(FindResultsWindow.ResultType.UnresolvedSymbol); } var constructedSymbol = resolvedSymbol; resolvedSymbol = resolvedSymbol.GetGenericSymbol(); if (referencedSymbol.kind == SymbolKind.MethodGroup && resolvedSymbol.kind == SymbolKind.Method) { resolvedSymbol = resolvedSymbol.parentSymbol; } if (resolvedSymbol != referencedSymbol) { var typeArgument = referencedSymbol as TypeDefinitionBase; var constructedType = constructedSymbol as ConstructedTypeDefinition; if (isVarResult && typeArgument != null && constructedType != null) { if (IsUsedAsTypeArgument(typeArgument.GetGenericSymbol() as TypeDefinitionBase, constructedType)) { return(FindResultsWindow.ResultType.VarTemplateReference); } } if (resolvedSymbol.kind == SymbolKind.Method && referencedSymbol.kind == SymbolKind.Method) { if (resolvedSymbol.parentSymbol == referencedSymbol.parentSymbol) { return(FindResultsWindow.ResultType.MethodOverload); } var resolvedMethod = resolvedSymbol as MethodDefinition; var referencedMethod = referencedSymbol as MethodDefinition; if (resolvedMethod != null && referencedMethod != null) { var resolvedType = resolvedMethod.parentSymbol as TypeDefinitionBase ?? resolvedMethod.parentSymbol.parentSymbol as TypeDefinitionBase; var referencedType = referencedMethod.parentSymbol as TypeDefinitionBase ?? referencedMethod.parentSymbol.parentSymbol as TypeDefinitionBase; var isInterface = resolvedType.kind == SymbolKind.Interface || referencedType.kind == SymbolKind.Interface; var resolvedIsVirtual = isInterface || resolvedMethod.IsOverride || resolvedMethod.IsVirtual || resolvedMethod.IsAbstract; var referencedIsVirtual = isInterface || referencedMethod.IsOverride || referencedMethod.IsVirtual || referencedMethod.IsAbstract; if (resolvedIsVirtual && referencedIsVirtual) { if (System.Linq.Enumerable.SequenceEqual( System.Linq.Enumerable.Select(resolvedMethod.GetParameters(), x => x.TypeOf()), System.Linq.Enumerable.Select(referencedMethod.GetParameters(), x => x.TypeOf()))) { if (resolvedType.DerivesFrom(referencedType)) { return(FindResultsWindow.ResultType.OverridingMethod); } if (referencedType.DerivesFrom(resolvedType)) { return(FindResultsWindow.ResultType.OverriddenMethod); } } } } } if (resolvedSymbol.kind != SymbolKind.MethodGroup || referencedSymbol.parentSymbol != resolvedSymbol) { return(FindResultsWindow.ResultType.RemoveResult); } } if (isVarResult) { return(FindResultsWindow.ResultType.VarReference); } if (FGResolver.IsWriteReference(token)) { return(FindResultsWindow.ResultType.WriteReference); } return(FindResultsWindow.ResultType.ReadReference); }