EditorSyntax icon indicating copy to clipboard operation
EditorSyntax copied to clipboard

Version v2021.5.1 Semantic Textmate Scope is incorrect for negative numeric literals, when used as a parameter

Open ninmonkey opened this issue 4 years ago • 4 comments
trafficstars

"editor.semanticHighlighting.enabled": true is on

System Details

System Details (Click to Expand)

System Details Output

### VSCode version: 1.56.2 054a9295330880ed74ceaedda236253b4f39a335 x64

### VSCode extensions:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]


### PSES version: 2.3.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Description

The Textmate scopes or token is wrong on negative numeric literals

image

Working behavior

Non-parameters, and positive numbers are okay

textmate_scopes-example1

Expected Behaviour

To share similar tokens/scopes

To reproduce

It seems to occur when:

  1. it's a negative numeric literal (int, or decimal)
  2. it's a parameter
  3. the parameter type doesn't matter

Code used:


function DoNothing {
    param(
        [Parameter(Mandatory, Position = 0)]
        [int]$Number
    )
}
function DoMoreNothing {
    param(
        [Parameter(Mandatory, Position = 0)]
        [string]$Text
    )
}

$x = 6                                               ; $x
$x = -6
DoNothing -6
DoNothing 6
DoNothing -Number 6
DoNothing -Number -6
DoMoreNothing -Text 6
DoMoreNothing -Text -6

Actual Behavior

textmate_scopes-example2-as-parameter

ninmonkey avatar Jun 05 '21 21:06 ninmonkey

@rjmholt I'm unclear, is this a semantic highlighting issue, or an editor syntax grammar issue?

andyleejordan avatar Jun 11 '21 20:06 andyleejordan

@andschwa It looks like

  • the textmate scope is right
  • the semantic scope is overriding it as a function
  • If I wrap it as (-6), it gets the expected semantic scope

I created a new image that's more clear. image

ninmonkey avatar Jul 05 '21 18:07 ninmonkey

Technically negative numeric constants as an argument are considered unquoted text by the PS tokenizer (as indicated by PSReadLine highlighting). So the TextMate scope is wrong. But the sematic highlighter is no better, as 'function' is definitely not the right scope. Neither of these things are what the OP wants to hear.

This is a very important demonstration.

Echo -0006

outputs

-0006

but

echo (-0006)

outputs

-6

msftrncs avatar Sep 30 '21 05:09 msftrncs

Actually, I give a bad example with 'echo' (Write-Output) because the output processor (formatter) just provides the original text behind the argument, so:

echo 0006

results in

0006

This provides a more meaningful demonstration:

(echo 0006).GetType().Name
(echo -0006).GetType().Name
(echo (-0006)).GetType().Name

which results in

Int32
String
Int32

msftrncs avatar Sep 30 '21 16:09 msftrncs