Skip to content

Commit 7b9767e

Browse files
authored
Add scopes symbol navigation (#189)
* Add meta.function-call.powershell scope to function calls This enables Sublime Text to correctly find references to functions being called, at least for functions written according to the recommended style. * 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. * Fix wrong scope name in 'class-method' context
1 parent a243f8b commit 7b9767e

4 files changed

+167
-72
lines changed

PowerShell.sublime-syntax

+16-1
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
@@ -342,7 +343,7 @@ contexts:
342343
\-\w+? # Any "noun"
343344
(?:\.(?i:exe|cmd|bat|ps1))?\b # More path stuff
344345
)
345-
scope: support.function.powershell
346+
scope: meta.function-call.powershell support.function.powershell
346347
# Builtin cmdlets with reserved verbs
347348
- match: \b(?i:(?:foreach|where|sort|tee)-object)\b
348349
scope: support.function.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.brackets.begin.powershell
804+
3: storage.type.powershell
805+
4: punctuation.section.brackets.end.powershell
806+
5: entity.name.function.powershell
807+
push:
808+
- match: (?=\()
809+
pop: true
810+
- include: comment-line

Tests/syntax_test_Class.ps1

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class TypeName
8080
# ^ punctuation.section.brackets.begin
8181
# ^^^^ storage.type
8282
# ^ punctuation.section.brackets.end
83+
# ^^^^^^^^^^^^^ entity.name.function
84+
# @@@@@@@@@@@@@ definition
8385
# ^ punctuation.section.group.begin
8486
# ^ punctuation.section.brackets.begin
8587
# ^^^^^^^^^ storage.type
@@ -105,6 +107,8 @@ class TypeName
105107
# <- punctuation.section.brackets.begin
106108
# ^ storage.type
107109
# ^ punctuation.section.brackets.end
110+
# ^^^^^^^^^^^^^ entity.name.function
111+
# @@@@@@@@@@@@@ definition
108112
# ^ punctuation.section.group.begin
109113
# ^ punctuation.section.brackets.begin
110114
# ^^^ storage.type
@@ -126,3 +130,9 @@ class TypeName
126130
# ^^ variable.other.member
127131
}
128132
}
133+
134+
[TypeName]::MemberMethod1()
135+
# @@@@@@@@@@@@@ reference
136+
137+
$object.MemberMethod2()
138+
# @@@@@@@@@@@@@ reference

Tests/syntax_test_Function.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ using module Microsoft.Management
55
# ^ keyword.other
66
# ^ variable.parameter
77

8+
function Test-Path {}
9+
# @@@@@@@@@ definition
810
<#
911
# <- punctuation.definition.comment.block.begin
1012
.Synopsis
@@ -321,6 +323,7 @@ function Verb-Noun {
321323
# ^ meta.attribute punctuation.section.group.end
322324
# ^ meta.attribute punctuation.section.brackets.end
323325
[ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting
326+
# @@@@@@@@@ reference
324327
# <- meta.attribute punctuation.section.brackets.begin
325328
# ^ meta.attribute support.function.attribute
326329
# ^ meta.attribute punctuation.section.group.begin

0 commit comments

Comments
 (0)