/// <nodoc /> public static SymbolLocation GetLocationFromNode(INode node, ISymbol symbol) { return(SymbolLocation.LocalLocation( node.GetSourceFile().Path.AbsolutePath, TextRange.FromLength( node.GetNodeStartPositionWithoutTrivia(), node.GetNodeWidth()), symbol)); }
private static Possible <IReadOnlyList <SymbolLocation> > DefinitionForTemplateExpression(INode node, string name) { var taggedTemplte = node.Parent.Cast <ITaggedTemplateExpression>(); var literal = taggedTemplte.TemplateExpression.Cast <ILiteralExpression>(); var interpolationKind = taggedTemplte.GetInterpolationKind(); // This is p`` or f`` or `r` if (interpolationKind == InterpolationKind.FileInterpolation || interpolationKind == InterpolationKind.PathInterpolation || interpolationKind == InterpolationKind.RelativePathInterpolation) { string fullPath = string.Empty; // Exceptions can happen if the string literal contains any invalid path characters (such as * and ?) // as well if there is any string interoplation in them such as ${variable} as the $ is also an invalid path // character. try { if (Path.IsPathRooted(literal.Text)) { fullPath = literal.Text; } else { fullPath = Path.Combine(Path.GetDirectoryName(node.GetSourceFile().Path.AbsolutePath), literal.Text); } } catch (ArgumentException) { // An ArgumentException from IsPathRooted indicates that the path has invalid characters. // Path.IsPathRooted and Path.Combine throw ArgumentException; } // This is path or file. // They can be absolute or relative to the current file. if (!string.IsNullOrEmpty(fullPath)) { return(Success(SymbolLocation.FileLocation(fullPath))); } } return(SilentError()); }