private Result <ArrayOrObject <Location, Location>, ResponseError> GetDefinitionFromSymbol([NotNull] ISymbol symbol, INode node) { var result = new List <Location>(); var declarations = symbol.GetDeclarations(); var symbolName = TypeChecker.SymbolToString(symbol); var symbolKind = DScriptUtilities.GetSymbolKind(symbol, node); var containerSymbol = symbol.Parent; var containerName = containerSymbol != null?TypeChecker.SymbolToString(containerSymbol, node) : string.Empty; if (!TryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !TryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { // Just add all the declarations foreach (var declaration in declarations) { result.Add(GetLocationFromNode(declaration)); } } return(Success(result.ToArray())); }
private Possible <IReadOnlyList <SymbolLocation> > GetDefinitionFromSymbol([NotNull] ISymbol symbol, INode node) { var result = new List <SymbolLocation>(); var declarations = symbol.GetDeclarations(); var symbolName = TypeChecker.SymbolToString(symbol); var symbolKind = Utilities.GetSymbolKind(symbol, node); var containerSymbol = symbol.Parent; var containerName = containerSymbol != null?TypeChecker.SymbolToString(containerSymbol, node) : string.Empty; if (!TryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) && !TryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { // Just add all the declarations foreach (var declaration in declarations) { result.Add(GetLocationFromNode(declaration, symbol)); } } return(result.Count != 0 ? Success(result.ToArray()) : SilentError()); }
private static bool TryAddConstructSignature( ISymbol symbol, INode location, string symbolKind, string symbolName, string containerName, List <SymbolLocation> result) { // Applicable only if we are in a new expression, or we are on a constructor declaration // and in either case the symbol has a construct signature definition, i.e. class if (Utilities.IsNewExpressionTarget(location) || location.Kind == SyntaxKind.ConstructorKeyword) { if ((symbol.Flags & SymbolFlags.Class) != SymbolFlags.None) { // Find the first class-like declaration and try to get the construct signature. foreach (var declaration in symbol.GetDeclarations()) { var classLikeDeclaration = NodeUtilities.IsClassLike(declaration); if (classLikeDeclaration != null) { return(TryAddSignature( symbol, classLikeDeclaration.Members.Elements, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result)); } } Debug.Fail("Expected declaration to have at least one class-like declaration"); } } return(false); }