-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix symbol highlight when hovering function name (#1890)
* move helper to VistiorUtils class * find function name if indented or after newline * extend tests to cover function definition name * extend test to include end position * Fix `postion` to `position` typo Co-authored-by: Andy Jordan <[email protected]>
- Loading branch information
1 parent
b0bfce7
commit 87cd721
Showing
4 changed files
with
90 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Management.Automation.Language; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Utility | ||
{ | ||
/// <summary> | ||
/// General common utilities for AST visitors to prevent reimplementation. | ||
/// </summary> | ||
internal static class VisitorUtils | ||
{ | ||
/// <summary> | ||
/// Calculates the start line and column of the actual function name in a function definition AST. | ||
/// </summary> | ||
/// <param name="ast">A FunctionDefinitionAst object in the script's AST</param> | ||
/// <returns>A tuple with start column and line for the function name</returns> | ||
internal static (int startColumn, int startLine) GetNameStartColumnAndLineNumbersFromAst(FunctionDefinitionAst ast) | ||
{ | ||
int startColumnNumber = ast.Extent.StartColumnNumber; | ||
int startLineNumber = ast.Extent.StartLineNumber; | ||
int astOffset = ast.IsFilter ? "filter".Length : ast.IsWorkflow ? "workflow".Length : "function".Length; | ||
string astText = ast.Extent.Text; | ||
// The line offset represents the offset on the line that we're on where as | ||
// astOffset is the offset on the entire text of the AST. | ||
int lineOffset = astOffset; | ||
for (; astOffset < astText.Length; astOffset++, lineOffset++) | ||
{ | ||
if (astText[astOffset] == '\n') | ||
{ | ||
// reset numbers since we are operating on a different line and increment the line number. | ||
startColumnNumber = 0; | ||
startLineNumber++; | ||
lineOffset = 0; | ||
} | ||
else if (astText[astOffset] == '\r') | ||
{ | ||
// Do nothing with carriage returns... we only look for line feeds since those | ||
// are used on every platform. | ||
} | ||
else if (!char.IsWhiteSpace(astText[astOffset])) | ||
{ | ||
// This is the start of the function name so we've found our start column and line number. | ||
break; | ||
} | ||
} | ||
|
||
return (startColumnNumber + lineOffset, startLineNumber); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters