Skip to content

Commit e8dce0c

Browse files
committed
Define 'class-method' context in syntax file
Static and instance methods are now identified as functions. F12 and shift+F12 can now correctly find definitions and references of class methods.
1 parent 290970e commit e8dce0c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

PowerShell.sublime-syntax

+15
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ contexts:
5252
- include: script-block
5353
- include: escape-characters
5454
- include: numeric-constant
55+
- include: class-method
5556
- match: (@)(\()
5657
captures:
5758
1: keyword.other.array.begin.powershell
@@ -793,3 +794,17 @@ contexts:
793794
3: support.variable.drive.powershell
794795
4: variable.other.readwrite.powershell
795796
5: punctuation.section.braces.end
797+
798+
class-method:
799+
- match: ^(?:\s*)(?i)(hidden|static)?\s*(\[)((?!\d+|\.)[\p{L}\p{N}.]+)(\])\s*((?:\p{L}|\d|_|-|\.)+)\s*(?=\()
800+
scope: meta.function.powershell
801+
captures:
802+
1: storage.modifier.powershell
803+
2: punctuation.section.braces.begin.powershell
804+
3: storage.type.powershell
805+
4: punctuation.section.braces.end.powershell
806+
5: entity.name.function.powershell
807+
push:
808+
- match: (?=\()
809+
pop: true
810+
- include: comment-line

Tests/syntax_test_PowerShell.ps1

+19
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,9 @@ function New-File ($Name) { }
916916
# @@@@@@@@ definition
917917
# ^ punctuation.section.braces.begin
918918
# ^ punctuation.section.braces.end
919+
New-File
920+
#^^^^^^^^ meta.function-call support.function
921+
#@@@@@@@@ reference
919922
function NewFile($Name) { }
920923
# <- storage.type
921924
# ^^^^^^^ entity.name.function
@@ -1129,6 +1132,8 @@ class Vehicle {
11291132

11301133
[void]Drive([int]$NumberOfMiles) {
11311134
# ^^^^ storage.type
1135+
# ^^^^^ meta.function entity.name.function
1136+
# @@@@@ definition
11321137
# ^^^ storage.type
11331138
# ^ punctuation.definition.variable
11341139
# ^ variable.other.readwrite
@@ -1140,9 +1145,23 @@ class Vehicle {
11401145

11411146
}
11421147
# <- punctuation.section.braces.end
1148+
static [System.Array] GetAvailableColors() {
1149+
# ^^^^^^^^^^^^^^^^^^ meta.function entity.name.function
1150+
# @@@@@@@@@@@@@@@@@@ definition
1151+
# ^^^^^^ meta.function storage.modifier
1152+
# ^^^^^^^^^^^ meta.function storage.type
1153+
return 'yellow', 'red'
1154+
}
11431155
}
11441156
# <- punctuation.section.braces.end
11451157

1158+
$fiat.Drive(42)
1159+
# ^^^^^ meta.function-call
1160+
# @@@@@ reference
1161+
[Vehicle]::GetAvailableColors()
1162+
# ^^^^^^^^^^^^^^^^^^ meta.function-call variable.function
1163+
# @@@@@@@@@@@@@@@@@@ reference
1164+
11461165
# Control words
11471166
foreach ($item in $collection) {
11481167
# <- keyword.control

0 commit comments

Comments
 (0)