PowerShell / EditorSyntax

PowerShell syntax highlighting for editors (VS Code, Atom, SublimeText, TextMate, etc.) and GitHub!
MIT License
132 stars 43 forks source link

Extend type definition to include static members and methods. #59

Open Halkcyon opened 6 years ago

Halkcyon commented 6 years ago

When using the PowerShell Subexpression operator $() in the contents of a non-literal string "", the contents of the expression should revert to a non-string syntax highlighting.

Currently, parts are highlighted correctly (like type references, variables, and function calls), but member references and function parameters are still highlighted as if they were part of the string.

Replicated in the following:

"An example string generated on $([Net.Dns]::GetHostByName($env:ComputerName).Hostname) at $(Get-Date -Format HH:mm)"
rkeithhill commented 6 years ago

Furthermore, VSCode will now enable quick suggestions support for subexpression inside dq strings if the syntax is tagged with meta.embedded. From 1.18 release notes:

Quick suggestions are disabled inside of strings and comments by default. In some cases, such as in JavaScript template strings, a string or comment may contain blocks of code where quick suggestions should be enabled. Grammars can now hint that VS Code should re-enable quick suggestions by adding a meta.embedded scope on tokens inside of a string or comment:

For example, see https://github.com/Microsoft/vscode/blob/f4b45dcbc93cd1525a3e6cd9fb16f93fbc4a2d58/extensions/php/syntaxes/php.tmLanguage.json

omniomi commented 6 years ago

Using your example GetHostByName is currently scoped as source.powershell -> string.quoted.double.powershell -> interpolated.complex.source.powershell; The complex source scope is effectively a meta scope for everything in a subexpression but is unlikely to be covered by any themes because it's not a legal name so it inherits from the next scope that is covered (string.*).

To address this issue we need to extend to the type definitions which currently only scope what amounts to [*[*]]. Added to this list.

msftrncs commented 6 years ago

Is there anything wrong with using multiple scopes? I was doing some testing with VS Code, applying both scopes, and its a nice improvement to get intellisense inside the subexpressions.

I placed this on the 'interpolation' rule (I technically separated it in to a new 'stringIterpolation' rule so that it doesn't apply to subexpressions outside quoted strings)

"contentName": "interpolated.complex.source.powershell meta.embedded.powershell",

Unfortunately this doesn't appear that it would fix the ability have 'format document' properly format up subexpressions in side expandable strings.

msftrncs commented 6 years ago

I got the best result actually putting 'meta.embedded' on "name" of the pattern rather than "contentName". Dark+, Monokai, and Monokai Dimmed all started coloring subexpressions within strings correctly, including the enclosing parenthesis, but doesn't work for PowerShell ISE theme. For some reason, Abyss must be using the wrong color for meta.embedded, as its set the same color as variable. A few of the others (of all VS Code's stock themes) also used a slightly different text color for meta.embedded, but they all had applied meta.embedded a color.

msftrncs commented 5 years ago

I plan to post a PR per my previous comment.

Does anyone know where the interpolated.complex scope came from?