Skip to content

Commit bb9cdfe

Browse files
committed
Add not null assertion to symbols service test (and clean up)
1 parent bc123b4 commit bb9cdfe

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,10 @@ public async Task<SymbolReference> GetDefinitionOfSymbolAsync(
427427
SymbolReference foundDefinition = null;
428428
foreach (ScriptFile scriptFile in referencedFiles)
429429
{
430-
foundDefinition =
431-
AstOperations.FindDefinitionOfSymbol(
432-
scriptFile.ScriptAst,
433-
foundSymbol);
430+
foundDefinition = AstOperations.FindDefinitionOfSymbol(scriptFile.ScriptAst, foundSymbol);
434431

435432
filesSearched.Add(scriptFile.FilePath);
436-
if (foundDefinition != null)
433+
if (foundDefinition is not null)
437434
{
438435
foundDefinition.FilePath = scriptFile.FilePath;
439436
break;
@@ -453,7 +450,7 @@ public async Task<SymbolReference> GetDefinitionOfSymbolAsync(
453450

454451
// if the definition the not found in referenced files
455452
// look for it in all the files in the workspace
456-
if (foundDefinition == null)
453+
if (foundDefinition is null)
457454
{
458455
// Get a list of all powershell files in the workspace path
459456
foreach (string file in _workspaceService.EnumeratePSFiles())
@@ -469,7 +466,7 @@ public async Task<SymbolReference> GetDefinitionOfSymbolAsync(
469466
foundSymbol);
470467

471468
filesSearched.Add(file);
472-
if (foundDefinition != null)
469+
if (foundDefinition is not null)
473470
{
474471
foundDefinition.FilePath = file;
475472
break;
@@ -480,7 +477,7 @@ public async Task<SymbolReference> GetDefinitionOfSymbolAsync(
480477
// if the definition is not found in a file in the workspace
481478
// look for it in the builtin commands but only if the symbol
482479
// we are looking at is possibly a Function.
483-
if (foundDefinition == null
480+
if (foundDefinition is null
484481
&& (foundSymbol.SymbolType == SymbolType.Function
485482
|| foundSymbol.SymbolType == SymbolType.Unknown))
486483
{

src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,8 @@ public static SymbolReference FindDefinitionOfSymbol(
215215
Ast scriptAst,
216216
SymbolReference symbolReference)
217217
{
218-
FindDeclarationVisitor declarationVisitor =
219-
new(
220-
symbolReference);
218+
FindDeclarationVisitor declarationVisitor = new(symbolReference);
221219
scriptAst.Visit(declarationVisitor);
222-
223220
return declarationVisitor.FoundDeclaration;
224221
}
225222

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public async Task FindsFunctionDefinition()
133133
[Fact]
134134
public async Task FindsFunctionDefinitionForAlias()
135135
{
136-
// TODO: Eventually we should get the alises through the AST instead of relying on them
136+
// TODO: Eventually we should get the aliases through the AST instead of relying on them
137137
// being defined in the runspace.
138138
await psesHost.ExecutePSCommandAsync(
139139
new PSCommand().AddScript("Set-Alias -Name My-Alias -Value My-Function"),
@@ -184,6 +184,7 @@ public async Task FindsFunctionDefinitionInDotSourceReference()
184184
public async Task FindsDotSourcedFile()
185185
{
186186
SymbolReference definitionResult = await GetDefinition(FindsDotSourcedFileData.SourceDetails).ConfigureAwait(true);
187+
Assert.NotNull(definitionResult);
187188
Assert.True(
188189
definitionResult.FilePath.EndsWith(Path.Combine("References", "ReferenceFileE.ps1")),
189190
"Unexpected reference file: " + definitionResult.FilePath);

0 commit comments

Comments
 (0)