-
Notifications
You must be signed in to change notification settings - Fork 237
Fix document highlight column #1279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TylerLeonhardt
merged 6 commits into
PowerShell:master
from
TylerLeonhardt:fix-highlight-column
May 1, 2020
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6c8a902
Fix document highlight column
TylerLeonhardt 9438862
make method static
TylerLeonhardt 73616c6
handle newlines and add test
TylerLeonhardt 4752ab4
codacy and skip a bad test
TylerLeonhardt ff81058
tired of this test failing
TylerLeonhardt 671cae6
Windows is slow so give an extra second
TylerLeonhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
86 changes: 86 additions & 0 deletions
86
test/PowerShellEditorServices.Test/Services/Symbols/AstOperationsTests.cs
This file contains hidden or 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,86 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using System.Management.Automation.Language; | ||
using Microsoft.PowerShell.EditorServices.Services.Symbols; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.PowerShell.EditorServices.Test.Services.Symbols | ||
{ | ||
public class AstOperationsTests | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
public AstOperationsTests(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
private static string s_scriptString = @"function BasicFunction {} | ||
BasicFunction | ||
|
||
function FunctionWithExtraSpace | ||
{ | ||
|
||
} FunctionWithExtraSpace | ||
|
||
function | ||
|
||
|
||
FunctionNameOnDifferentLine | ||
|
||
|
||
|
||
|
||
|
||
|
||
{} | ||
|
||
|
||
FunctionNameOnDifferentLine | ||
"; | ||
private static ScriptBlockAst s_ast = (ScriptBlockAst) ScriptBlock.Create(s_scriptString).Ast; | ||
|
||
[Trait("Category", "AstOperations")] | ||
[Theory] | ||
[InlineData(2, 3, "BasicFunction")] | ||
[InlineData(7, 18, "FunctionWithExtraSpace")] | ||
[InlineData(22, 13, "FunctionNameOnDifferentLine")] | ||
public void CanFindSymbolAtPostion(int lineNumber, int columnNumber, string expectedName) | ||
{ | ||
SymbolReference reference = AstOperations.FindSymbolAtPosition(s_ast, lineNumber, columnNumber); | ||
Assert.NotNull(reference); | ||
Assert.Equal(expectedName, reference.SymbolName); | ||
} | ||
|
||
[Trait("Category", "AstOperations")] | ||
[Theory] | ||
[MemberData(nameof(FindReferencesOfSymbolAtPostionData), parameters: 3)] | ||
public void CanFindReferencesOfSymbolAtPostion(int lineNumber, int columnNumber, Position[] positions) | ||
{ | ||
SymbolReference symbol = AstOperations.FindSymbolAtPosition(s_ast, lineNumber, columnNumber); | ||
|
||
IEnumerable<SymbolReference> references = AstOperations.FindReferencesOfSymbol(s_ast, symbol, needsAliases: false); | ||
|
||
int positionsIndex = 0; | ||
foreach (SymbolReference reference in references) | ||
{ | ||
Assert.Equal((int)positions[positionsIndex].Line, reference.ScriptRegion.StartLineNumber); | ||
Assert.Equal((int)positions[positionsIndex].Character, reference.ScriptRegion.StartColumnNumber); | ||
|
||
positionsIndex++; | ||
} | ||
} | ||
|
||
public static object[][] FindReferencesOfSymbolAtPostionData = new object[][] | ||
{ | ||
new object[] { 2, 3, new Position[] { new Position(1, 10), new Position(2, 1) } }, | ||
new object[] { 7, 18, new Position[] { new Position(4, 19), new Position(7, 3) } }, | ||
new object[] { 22, 13, new Position[] { new Position(12, 8), new Position(22, 5) } }, | ||
}; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.