Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add not null assertion to symbols service test (and clean up)
  • Loading branch information
andyleejordan committed Jun 15, 2022
commit bb9cdfe32ab49ca87206e7ee404e7c249d256a5a
13 changes: 5 additions & 8 deletions src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,10 @@ public async Task<SymbolReference> GetDefinitionOfSymbolAsync(
SymbolReference foundDefinition = null;
foreach (ScriptFile scriptFile in referencedFiles)
{
foundDefinition =
AstOperations.FindDefinitionOfSymbol(
scriptFile.ScriptAst,
foundSymbol);
foundDefinition = AstOperations.FindDefinitionOfSymbol(scriptFile.ScriptAst, foundSymbol);

filesSearched.Add(scriptFile.FilePath);
if (foundDefinition != null)
if (foundDefinition is not null)
{
foundDefinition.FilePath = scriptFile.FilePath;
break;
Expand All @@ -453,7 +450,7 @@ public async Task<SymbolReference> GetDefinitionOfSymbolAsync(

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

filesSearched.Add(file);
if (foundDefinition != null)
if (foundDefinition is not null)
{
foundDefinition.FilePath = file;
break;
Expand All @@ -480,7 +477,7 @@ public async Task<SymbolReference> GetDefinitionOfSymbolAsync(
// if the definition is not found in a file in the workspace
// look for it in the builtin commands but only if the symbol
// we are looking at is possibly a Function.
if (foundDefinition == null
if (foundDefinition is null
&& (foundSymbol.SymbolType == SymbolType.Function
|| foundSymbol.SymbolType == SymbolType.Unknown))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,8 @@ public static SymbolReference FindDefinitionOfSymbol(
Ast scriptAst,
SymbolReference symbolReference)
{
FindDeclarationVisitor declarationVisitor =
new(
symbolReference);
FindDeclarationVisitor declarationVisitor = new(symbolReference);
scriptAst.Visit(declarationVisitor);

return declarationVisitor.FoundDeclaration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task FindsFunctionDefinition()
[Fact]
public async Task FindsFunctionDefinitionForAlias()
{
// TODO: Eventually we should get the alises through the AST instead of relying on them
// TODO: Eventually we should get the aliases through the AST instead of relying on them
// being defined in the runspace.
await psesHost.ExecutePSCommandAsync(
new PSCommand().AddScript("Set-Alias -Name My-Alias -Value My-Function"),
Expand Down Expand Up @@ -184,6 +184,7 @@ public async Task FindsFunctionDefinitionInDotSourceReference()
public async Task FindsDotSourcedFile()
{
SymbolReference definitionResult = await GetDefinition(FindsDotSourcedFileData.SourceDetails).ConfigureAwait(true);
Assert.NotNull(definitionResult);
Assert.True(
definitionResult.FilePath.EndsWith(Path.Combine("References", "ReferenceFileE.ps1")),
"Unexpected reference file: " + definitionResult.FilePath);
Expand Down