Skip to content

Commit e990670

Browse files
committed
Fix ScriptRegion.ContainsPosition
To actually be an inclusive check of the given point being between the two boundary points.
1 parent b634dfa commit e990670

File tree

5 files changed

+14
-46
lines changed

5 files changed

+14
-46
lines changed

src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ public static IEnumerable<SymbolReference> FindOccurrencesInFile(
233233
ScriptFile scriptFile, int line, int column)
234234
{
235235
// This needs to get by whole extent, not just the name, as it completes e.g.
236-
// `Get-Process -` (after the dash) and so also needs to look backwards a column.
237-
SymbolReference? symbol = scriptFile.References.TryGetSymbolContainingPosition(line, column - 1);
236+
// `Get-Process -` (after the dash).
237+
SymbolReference? symbol = scriptFile.References.TryGetSymbolContainingPosition(line, column);
238238

239239
// If we are not possibly looking at a Function, we don't
240240
// need to continue because we won't be able to get the

src/PowerShellEditorServices/Services/TextDocument/ScriptRegion.cs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,11 @@ public bool IsEmpty()
4242
&& string.IsNullOrEmpty(Text);
4343
}
4444

45-
// Same as PowerShell's ContainsLineAndColumn
45+
// Do not use PowerShell's ContainsLineAndColumn, it's nonsense.
4646
public bool ContainsPosition(int line, int column)
4747
{
48-
if (StartLineNumber == line)
49-
{
50-
if (column == 0)
51-
{
52-
return true;
53-
}
54-
55-
if (column >= StartColumnNumber)
56-
{
57-
if (EndLineNumber != StartLineNumber)
58-
{
59-
return true;
60-
}
61-
62-
return column < EndColumnNumber;
63-
}
64-
65-
return false;
66-
}
67-
68-
if (StartLineNumber > line)
69-
{
70-
return false;
71-
}
72-
73-
if (line > EndLineNumber)
74-
{
75-
return false;
76-
}
77-
78-
if (EndLineNumber == line)
79-
{
80-
return column < EndColumnNumber;
81-
}
82-
83-
return true;
48+
return StartLineNumber <= line && line <= EndLineNumber
49+
&& StartColumnNumber <= column && column <= EndColumnNumber;
8450
}
8551

8652
public override string ToString() => $"Start {StartLineNumber}:{StartColumnNumber}, End {EndLineNumber}:{EndColumnNumber}";

test/PowerShellEditorServices.Test.Shared/Occurrences/FindOccurrencesOnParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class FindOccurrencesOnParameterData
1111
file: TestUtilities.NormalizePath("References/SimpleFile.ps1"),
1212
text: string.Empty,
1313
startLineNumber: 1,
14-
startColumnNumber: 30,
14+
startColumnNumber: 31,
1515
startOffset: 0,
1616
endLineNumber: 0,
1717
endColumnNumber: 0,

test/PowerShellEditorServices.Test.Shared/References/FindsReferencesOnTypeSymbols.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public static class FindsReferencesOnTypeSymbolsData
5050
public static readonly ScriptRegion PropertySourceDetails = new(
5151
file: TestUtilities.NormalizePath("References/TypeAndClassesFile.ps1"),
5252
text: string.Empty,
53-
startLineNumber: 17,
54-
startColumnNumber: 15,
53+
startLineNumber: 35,
54+
startColumnNumber: 12,
5555
startOffset: 0,
5656
endLineNumber: 0,
5757
endColumnNumber: 0,

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,12 @@ public void FindsOccurrencesOnProperty()
655655
[Fact]
656656
public async Task FindsEnumMemberDefinition()
657657
{
658-
SymbolReference definitionResult = await GetDefinition(FindsTypeSymbolsDefinitionData.EnumMemberSourceDetails).ConfigureAwait(true);
659-
Assert.Equal(41, definitionResult.ScriptRegion.StartLineNumber);
660-
Assert.Equal(5, definitionResult.ScriptRegion.StartColumnNumber);
661-
Assert.Equal("MyEnum.Second", definitionResult.SymbolName);
658+
SymbolReference symbol = await GetDefinition(FindsTypeSymbolsDefinitionData.EnumMemberSourceDetails).ConfigureAwait(true);
659+
Assert.Equal("Second", symbol.SymbolName);
660+
Assert.Equal("Second", symbol.DisplayString);
661+
Assert.True(symbol.IsDeclaration);
662+
AssertIsRegion(symbol.NameRegion, 41, 5, 41, 11);
663+
Assert.Equal(41, symbol.ScriptRegion.StartLineNumber);
662664
}
663665

664666
[Fact]

0 commit comments

Comments
 (0)