Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ private static SemanticTokenType MapSemanticTokenType(Token token)
return SemanticTokenType.Operator;
}

if ((token.TokenFlags & TokenFlags.AttributeName) != 0)
{
return SemanticTokenType.Decorator;
}

if ((token.TokenFlags & TokenFlags.TypeName) != 0)
{
return SemanticTokenType.Type;
Expand Down Expand Up @@ -142,8 +147,8 @@ private static SemanticTokenType MapSemanticTokenType(Token token)
case TokenKind.Number:
return SemanticTokenType.Number;

case TokenKind.Generic:
return SemanticTokenType.Function;
case TokenKind.Label:
return SemanticTokenType.Label;
}

return null;
Expand Down
25 changes: 20 additions & 5 deletions test/PowerShellEditorServices.Test/Language/SemanticTokenTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public void TokenizesFunctionElements()
{
const string text = @"
function Get-Sum {
param( [int]$a, [int]$b )
param( [parameter()] [int]$a, [int]$b )
:loopLabel while (0) {break loopLabel}
return $a + $b
}
";
Expand All @@ -38,10 +39,21 @@ function Get-Sum {
case "function":
case "param":
case "return":
case "while":
case "break":
Assert.Single(mappedTokens, sToken => SemanticTokenType.Keyword == sToken.Type);
break;
case "Get-Sum":
Assert.Single(mappedTokens, sToken => SemanticTokenType.Function == sToken.Type);
case "parameter":
Assert.Single(mappedTokens, sToken => SemanticTokenType.Decorator == sToken.Type);
break;
case "0":
Assert.Single(mappedTokens, sToken => SemanticTokenType.Number == sToken.Type);
break;
case ":loopLabel":
Assert.Single(mappedTokens, sToken => SemanticTokenType.Label == sToken.Type);
break;
case "loopLabel":
Assert.Single(mappedTokens, sToken => SemanticTokenType.Property == sToken.Type);
break;
case "$a":
case "$b":
Expand Down Expand Up @@ -74,7 +86,6 @@ public void TokenizesStringExpansion()
Token stringExpandableToken = scriptFile.ScriptTokens[1];
mappedTokens = new List<SemanticToken>(PsesSemanticTokensHandler.ConvertToSemanticTokens(stringExpandableToken));
Assert.Collection(mappedTokens,
sToken => Assert.Equal(SemanticTokenType.Function, sToken.Type),
sToken => Assert.Equal(SemanticTokenType.Function, sToken.Type),
sToken => Assert.Equal(SemanticTokenType.Function, sToken.Type)
);
Expand Down Expand Up @@ -103,7 +114,11 @@ function Get-A*A {
Assert.Single(mappedTokens, sToken => SemanticTokenType.Keyword == sToken.Type);
break;
case "Get-A*A":
Assert.Single(mappedTokens, sToken => SemanticTokenType.Function == sToken.Type);
if (t.TokenFlags.HasFlag(TokenFlags.CommandName))
{
Assert.Single(mappedTokens, sToken => SemanticTokenType.Function == sToken.Type);
}

break;
}
}
Expand Down