/// <nodoc /> public TestFunction(string shortName, string fullIdentifier, LineAndColumn originalLineAndColumn, string lkgFilePath) { ShortName = shortName; FullIdentifier = fullIdentifier; OriginalLineAndColumn = originalLineAndColumn; LkgFilePath = lkgFilePath; }
private static string MinimalDiagnosticsToString(List <Diagnostic> diagnostics) { StringBuilder errorOutput = new StringBuilder(); foreach (var diagnostic in diagnostics) { if (diagnostic.File != null) { LineAndColumn lineAndCharacter = Scanning.Scanner.GetLineAndCharacterOfPosition(diagnostic.File, diagnostic.Start.Value); errorOutput .Append(diagnostic.File.FileName) .Append("(") .Append(lineAndCharacter.Line) .Append(",") .Append(lineAndCharacter.Character) .Append("): "); } errorOutput .Append(diagnostic.Category.ToString().ToLower()) .Append(" TS") .Append(diagnostic.Code) .Append(": ") .Append(diagnostic.MessageText.ToString()) .AppendLine(); } return(errorOutput.ToString()); }
/// <summary> /// Converts <paramref name="lineAndColumn"/> (which is 1-based) to <see cref="Position"/> (which is 0-based). /// </summary> public static Position ToPosition(this LineAndColumn lineAndColumn) { return(new Position() { Line = lineAndColumn.Line - 1, Character = lineAndColumn.Character - 1, }); }
/// <summary> /// Tries to find the node with the smallest width in the <paramref name="sourceFile"/> that contains the input <paramref name="lineAndColumn"/>. /// </summary> public static bool TryGetNodeAtPosition( ISourceFile sourceFile, LineAndColumn lineAndColumn, out INode nodeAtPosition) { return(TryGetNodeAtPosition( sourceFile, lineAndColumn, isNodeAcceptable: (node) => true, // Any node that matches the lineAndColumn is acceptable nodeAtPosition: out nodeAtPosition)); }
/// <nodoc /> public static Range ToRange(this LineAndColumn lineAndColumn, LineMap lineMap, int?length) { var start = lineAndColumn.ToPosition(); // Compute the absolute end of the range by getting the absolute start and offseting that with the length var absoluteStart = lineMap.Map[lineAndColumn.Line - 1] + lineAndColumn.Character - 1; var absoluteEnd = absoluteStart + length ?? 0; var end = LineInfo.FromLineMap(lineMap, absoluteEnd).ToPosition(); return(new Range { Start = start, End = end }); }
/// <summary> /// Tries to find the node with the smallest width in the <paramref name="sourceFile"/> /// that contains the input <paramref name="lineAndColumn"/>, and is deemed acceptable by /// <paramref name="isNodeAcceptable"/>. /// </summary> /// <param name="sourceFile">Source file to search for node in.</param> /// <param name="lineAndColumn">The line-and-column location to get the node for.</param> /// <param name="isNodeAcceptable">A function that lets the caller have a say about which node to pick.</param> /// <param name="nodeAtPosition">Holds the returned node if the function returns true, and null otherwise.</param> /// <remarks> /// This function can return null in cases were there is no node at the current position. For example, asking /// for a node at an empty source line, or asking for a node when the position is inside a comment that /// encompasses the remainder of the file. /// </remarks> public static bool TryGetNodeAtPosition( ISourceFile sourceFile, LineAndColumn lineAndColumn, Func <INode, bool> isNodeAcceptable, out INode nodeAtPosition) { INode currentNode = null; NodeWalker.ForEachChildRecursively(sourceFile, (node) => { if (node.IsInjectedForDScript()) { // Need to skip injected nodes. return(null); } var nodeStart = LineInfoExtensions.GetLineAndColumnBy( position: Types.NodeUtilities.GetTokenPosOfNode(node, sourceFile), sourceFile: sourceFile, skipTrivia: false); var nodeEnd = LineInfoExtensions.GetLineAndColumnBy( position: node.End, sourceFile: sourceFile, skipTrivia: false); if (nodeStart > lineAndColumn || nodeEnd < lineAndColumn) { // If this node starts after or ends before the position we are searching for, then we skip it return(null); } if (currentNode == null || node.GetWidth() <= currentNode.GetWidth()) { if (isNodeAcceptable(node)) { currentNode = node; } } return((object)null); }); nodeAtPosition = currentNode; return(currentNode != null); }