Skip to content

Commit 43baed3

Browse files
committed
Decorate more type names
And guard from null exception in definition handler.
1 parent ec8cf7b commit 43baed3

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

src/PowerShellEditorServices/Services/Symbols/ReferenceTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal IEnumerable<SymbolReference> TryGetReferences(SymbolReference? symbol)
5252
}
5353

5454
internal SymbolReference? TryGetSymbolAtPosition(int line, int column) => GetAllReferences()
55-
.FirstOrDefault((i) => i.NameRegion.ContainsPosition(line, column));
55+
.FirstOrDefault(i => i.NameRegion.ContainsPosition(line, column));
5656

5757
internal IEnumerable<SymbolReference> GetAllReferences()
5858
{

src/PowerShellEditorServices/Services/Symbols/Visitors/SymbolVisitor.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public override AstVisitAction VisitVariableExpression(VariableExpressionAst var
8989
// the same function definition.
9090
return _action(new SymbolReference(
9191
SymbolType.Variable,
92-
$"${variableExpressionAst.VariablePath.UserPath}",
93-
$"${variableExpressionAst.VariablePath.UserPath}",
92+
"$" + variableExpressionAst.VariablePath.UserPath,
93+
"$" + variableExpressionAst.VariablePath.UserPath,
9494
variableExpressionAst.Extent,
9595
variableExpressionAst.Extent, // TODO: Maybe parent?
9696
_file,
@@ -119,7 +119,7 @@ public override AstVisitAction VisitTypeExpression(TypeExpressionAst typeExpress
119119
return _action(new SymbolReference(
120120
SymbolType.Type,
121121
typeExpressionAst.TypeName.Name,
122-
typeExpressionAst.TypeName.Name,
122+
"(type) " + typeExpressionAst.TypeName.Name,
123123
typeExpressionAst.Extent,
124124
typeExpressionAst.Extent,
125125
_file,
@@ -131,7 +131,7 @@ public override AstVisitAction VisitTypeConstraint(TypeConstraintAst typeConstra
131131
return _action(new SymbolReference(
132132
SymbolType.Type,
133133
typeConstraintAst.TypeName.Name,
134-
"[" + typeConstraintAst.TypeName.Name + "]",
134+
"(type) " + typeConstraintAst.TypeName.Name,
135135
typeConstraintAst.Extent,
136136
typeConstraintAst.Extent,
137137
_file,
@@ -184,12 +184,13 @@ public override AstVisitAction VisitMemberExpression(MemberExpressionAst memberE
184184
return AstVisitAction.Continue;
185185
}
186186

187+
// TODO: It's too bad we can't get the member's real symbol and reuse its display string.
187188
return _action(new SymbolReference(
188189
SymbolType.Property,
189190
#pragma warning disable CS8604 // Possible null reference argument.
190191
memberName,
191192
#pragma warning restore CS8604
192-
memberExpressionAst.Member.Extent.Text,
193+
"(method) " + memberName,
193194
memberExpressionAst.Member.Extent,
194195
memberExpressionAst.Extent,
195196
_file,
@@ -209,7 +210,7 @@ public override AstVisitAction VisitInvokeMemberExpression(InvokeMemberExpressio
209210
#pragma warning disable CS8604 // Possible null reference argument.
210211
memberName,
211212
#pragma warning restore CS8604
212-
methodCallAst.Member.Extent.Text,
213+
"(method) " + memberName,
213214
methodCallAst.Member.Extent,
214215
methodCallAst.Extent,
215216
_file,

src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public override async Task<LocationOrLocationLinks> Handle(DefinitionParams requ
4343
request.Position.Line + 1,
4444
request.Position.Character + 1);
4545

46+
if (foundSymbol is null)
47+
{
48+
return new LocationOrLocationLinks();
49+
}
50+
4651
// Short-circuit if we're already on the definition.
4752
if (foundSymbol.IsDeclaration)
4853
{
@@ -57,19 +62,16 @@ public override async Task<LocationOrLocationLinks> Handle(DefinitionParams requ
5762
}
5863

5964
List<LocationOrLocationLink> definitionLocations = new();
60-
if (foundSymbol is not null)
65+
foreach (SymbolReference foundDefinition in await _symbolsService.GetDefinitionOfSymbolAsync(
66+
scriptFile, foundSymbol, cancellationToken).ConfigureAwait(false))
6167
{
62-
foreach (SymbolReference foundDefinition in await _symbolsService.GetDefinitionOfSymbolAsync(
63-
scriptFile, foundSymbol, cancellationToken).ConfigureAwait(false))
64-
{
65-
definitionLocations.Add(
66-
new LocationOrLocationLink(
67-
new Location
68-
{
69-
Uri = DocumentUri.From(foundDefinition.FilePath),
70-
Range = foundDefinition.NameRegion.ToRange()
71-
}));
72-
}
68+
definitionLocations.Add(
69+
new LocationOrLocationLink(
70+
new Location
71+
{
72+
Uri = DocumentUri.From(foundDefinition.FilePath),
73+
Range = foundDefinition.NameRegion.ToRange()
74+
}));
7375
}
7476

7577
return new LocationOrLocationLinks(definitionLocations);

0 commit comments

Comments
 (0)