Skip to content

Decide on scope names for all language constructs #8

Description

I'd like to have a discussion where we decide on the "correct" scope names for all PowerShell language constructs. This will mean much less work when doing updates to the tmLanguage file in the future, as the scopes (as well as the color(!) of each) are checked by a Travis CI build job on the vscode repo.

General
  • All scope names should end in .powershell

As we decide, we can fill out this table:

Language constructScope NameComments/Examples
Line commentcomment.line.number-sign# comments
Block commentcomment.block<# comments #>
Help directivescomment.documentation.embeddedMeta scope
Help directives - keywordskeyword.operator.documentation.SYNOPSIS
Help directives - keyword valueconstant.string.documentation'ParameterName' in .PARAMETER ParameterName
#Requires statementkeywords.operator.documentation'Requires' in #Requires -Version 3.0
#Requires statement - parameterconstant.string.documentation'-Version 3.0' in #Requires -Version 3.0
String - double quotedstring.quoted.double"string"
String - single quotedstring.quoted.single'string'
String - escape charactersconstant.character.escape't' in "onettwo"
String - heredoc double quotedstring.quoted.double.heredoc
String - heredoc single quotedstring.quoted.single.heredoc
ScriptBlockmeta.scriptblock{ ... }
SubExpressionmeta.subexpression$( ... )
Hashtablemeta.hashtable@{ ... }
Arraymeta.array@(1,2,3) & (1,2,3)
Property/Memberentity.other.attribute-name'property' in (Invoke-Something).property & 'property' in $var.property
Numeric Constant - realconstant.numeric.real+.5
Numeric Constant - integerconstant.numeric.integer5
Numeric Constant - hexadecimalconstant.numeric.hexadecimal0x20
Typeentity.name.type'string' in [string]
Type - static methodmeta.method'::MinValue' in [int]::MinValue
Parameter decoratorentity.name.type'Parameter' in [Parameter(Position = 1)]
Parameter decorator - propertyentity.other.attribute-name'Position' in [Parameter(Position = 1)]
Functionmeta.functionMeta scope
Function - keywordstorage.type'function' in function script:Invoke-Something { ... }
Function - scopestorage.modifier.scope'script' in function script:Invoke-Something { ... }
Function - nameentity.name.function'Invoke-Something' in function script:Invoke-Something { ... }
Commandmeta.commandMeta scope
Command - keywordsupport.function'Invoke-Something' in Invoke-Something -p1 'v1'
Command - parametervariable.parameter'-p1' in Invoke-Something -p1 'v1'
Reserved wordskeyword.otherconfiguration
Control wordskeyword.controlbreak
Enum - keywordstorage.type'enum' in enum myEnum { ... }
Enum - nameentity.name.function'myEnum' in enum myEnum { ... }
Classmeta.classMeta scope
Class - keywordstorage.type'class' in class myClass : inheritedClass { ... }
Class - nameentity.name.function'myClass' in class myClass : inheritedClass { ... }
Class - inheritanceentity.other.inherited-class'inheritedClass' in class myClass : inheritedClass { ... }
Class - reserved wordskeyword.otherhidden & static
Class - control wordskeyword.control.class'base' in : base( ... )
Operator - redirectionkeyword.operator.redirection2>&1
Operator - comparisonkeyword.operator.comparison-gt
Operator - bitwisekeyword.operator.bitwise-band
Operator - logicalkeyword.operator.logical-and
Operator - formatkeyword.operator.format-f
Operator - assignmentkeyword.operator.assignment+=
Operator - logical notkeyword.operator.logical-not-not & !
Operator - multiplicativekeyword.operator.multiplicative/ & *
Operator - unary pluskeyword.operator.unary-plus+
Operator - unary minuskeyword.operator.unary-minus-
Operator - additivekeyword.operator.additive+ & -
Operator - rangekeyword.operator.range..
Operator - command invocationkeyword.operator.other&
Operator - stop parsingkeyword.operator--%
Switch - keywordkeyword.control'switch' in switch -regex ($var) { ... }
Switch - parametervariable.parameter'-regex' in switch -regex ($var) { ... }
Switch - reserved wordkeyword.otherdefault
Illegalinvalid.illegalSpace after backtick
Variable - $keyword.other'$' in $variable
Variable - ${..}keyword.other'${' and '}' in ${variable}
Variable - automaticconstant.language$_ & $error
Variable - scopestorage.modifier.scope'script' in $script:variable
Variable - namevariable.other.readwrite'variable' in $script:variable

I have started by filling out the scope names as I have used them in my refactored language file.

About scopes and highlighting

If, in the theme, there are colorization rules only for the scope constant.operator, both constant.operator and constant.operator.range will be colorized the same.

If there isn't any colorization rules for a scope, it will be colorized with the "root" color of the current scope. Meaning if the word 'test' only belong to the source scope (or have a scope name that is not defined in the current theme), it will be colorized with the default background color. If the word 'test' is found inside another scope, for instance a string, it will be colorized with the color for the string scope.

Colorization rules may differ between editors. For instance the background parameter. This is supported on Sublime Text, but not in VSCode.

A matched set of characters can be (and more often than not are) assigned multiple scopes. So for example the word variable in function MyFunction {"this is $("a $variable")"} have the following scopes: source, string.quoted.double, meta.subexpression, string.quoted.double and lastly variable.other.readwrite. Only the last one is used for colorization.

About the default themes in VSCode

There are five themes that are defined as default themes in Visual Studio Code:

  • dark_plus "Dark+"
  • dark_vs "Dark Visual Studio"
  • hc_black "Dark Visual Studio"
  • light_plus "Light+"
  • light_vs "Light Visual Studio"

The themes supports nesting, and:

  • Light+ includes light_vs (Light Visual Studio)
  • Dark+ includes dark_vs (Dark Visual Studio)

The following scopes are defined in the plus-themes:

  • meta.type.name, meta.return.type, meta.return-type, meta.cast, meta.type.annotation, support.type, entity.name.class, entity.name.type, storage.type.cs, storage.type.java
  • entity.name.function, entity.name.method
  • keyword.control
  • meta.parameter.type.variable, variable.parameter, variable, variable.name

The following scopes are defined in the "old" default themes:

  • emphasis
  • strong
  • header
  • comment
  • constant.language
  • constant.numeric
  • constant.regexp
  • constant.rgb-value
  • entity.name.tag
  • entity.name.selector
  • entity.other.attribute-name
  • entity.other.attribute-name.css
  • invalid
  • markup.underline
  • markup.bold
  • markup.heading
  • markup.italic
  • markup.inserted
  • markup.deleted
  • markup.changed
  • meta.selector
  • meta.tag
  • meta.preprocessor
  • meta.preprocessor.string
  • meta.preprocessor.numeric
  • meta.structure.dictionary.key.python
  • storage
  • storage.type
  • storage.modifier
  • string
  • string.xml, string.jade, string.yaml, string.html
  • string.regexp
  • support.property-value
  • support.type.property-name.css, support.type.property-name.less, support.type.property-name.sass
  • support.type.property-name
  • keyword
  • keyword.control
  • keyword.operator
  • keyword.operator.new
  • keyword.other.unit
  • keyword.control.less
  • metatag.php
  • support.function.git-rebase
  • constant.sha.git-rebase
  • storage.modifier.import.java, storage.modifier.package.java

Scope names on the same line, means they are defined in the same colorization rule.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions