Skip to content

Commit 8f57f8c

Browse files
committed
Change C# context to use indicators
Rather than triggering on Add-Type
1 parent 98fa78d commit 8f57f8c

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

PowerShell.sublime-syntax

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ contexts:
211211
###[ COMMANDS ]################################################################
212212

213213
commands:
214-
- include: commands-add-type
215214
- include: commands-verb-noun
216215
- include: commands-reserved
217216
- include: script-invocation
@@ -236,32 +235,6 @@ contexts:
236235
- match: \b[\w.\\/-]+\.(?i:exe|com|cmd|bat|ps1)\b
237236
scope: variable.function.powershell
238237

239-
commands-add-type:
240-
- match: \b(?i:Add-Type)\b
241-
scope: support.function.powershell
242-
push: inside-add-type
243-
244-
inside-add-type:
245-
- include: pop-eol
246-
247-
- match: '@"'
248-
scope: meta.string.interpolated.powershell string.quoted.double.powershell punctuation.definition.string.begin.powershell
249-
embed: scope:source.cs
250-
embed_scope: meta.string.interpolated.powershell string.quoted.double.powershell source.cs.embedded
251-
escape: ("@)
252-
escape_captures:
253-
1: meta.string.powershell string.quoted.double.powershell punctuation.definition.string.end.powershell
254-
255-
- match: "@'"
256-
scope: meta.string.powershell string.quoted.single.powershell punctuation.definition.string.begin.powershell
257-
embed: scope:source.cs
258-
embed_scope: meta.string.powershell string.quoted.single.powershell source.cs.embedded
259-
escape: ('@)
260-
escape_captures:
261-
1: meta.string.powershell string.quoted.single.powershell punctuation.definition.string.end.powershell
262-
263-
- include: expressions
264-
265238
parameters:
266239
# Flags/Options/Parameters
267240
- match: \B(--?|[/+])\p{L}(?:[\w-]*\w)?
@@ -754,7 +727,20 @@ contexts:
754727
single-quoted-heredoc-strings:
755728
- match: \@'(?=$)
756729
scope: punctuation.definition.string.begin.powershell
757-
push: inside-single-quoted-heredoc-string
730+
push:
731+
- inside-single-quoted-heredoc-string
732+
- inside-single-quoted-heredoc-string.syntax
733+
734+
inside-single-quoted-heredoc-string.syntax:
735+
- meta_include_prototype: false
736+
- match: (?={{csharp_indicator}})
737+
set: scope:source.cs
738+
with_prototype:
739+
- match: (?=^'@)
740+
pop: 1
741+
- match: "''"
742+
scope: constant.character.escape.powershell
743+
- include: else-pop
758744

759745
inside-single-quoted-heredoc-string:
760746
- meta_include_prototype: false
@@ -768,7 +754,9 @@ contexts:
768754
double-quoted-heredoc-strings:
769755
- match: \@"(?=$)
770756
scope: punctuation.definition.string.begin.powershell
771-
push: inside-double-quoted-heredoc-string
757+
push:
758+
- inside-double-quoted-heredoc-string
759+
- inside-double-quoted-heredoc-string.syntax
772760

773761
inside-double-quoted-heredoc-string:
774762
- meta_include_prototype: false
@@ -779,6 +767,16 @@ contexts:
779767
- include: escape-sequences
780768
- include: string-interpolations
781769

770+
inside-double-quoted-heredoc-string.syntax:
771+
- meta_include_prototype: false
772+
- match: (?={{csharp_indicator}})
773+
set: scope:source.cs
774+
with_prototype:
775+
- match: (?=^"@)
776+
pop: 1
777+
- include: escape-sequences
778+
- include: else-pop
779+
782780
string-interpolations:
783781
- match: \$\(
784782
scope: punctuation.section.interpolation.begin.powershell
@@ -1062,3 +1060,11 @@ variables:
10621060
Alias | Cmdlet | HelpFile | Function | Provider | General | FAQ
10631061
| Glossary | ScriptCommand | ExternalScript | Filter | All
10641062
)
1063+
1064+
# Strings
1065+
csharp_indicator: |-
1066+
(?x: \s* (?:
1067+
using\s+System[.;]
1068+
| public\s+class\s+
1069+
| \[DllImport\b
1070+
))

Tests/syntax_test_Add-Type.ps1

Lines changed: 0 additions & 24 deletions
This file was deleted.

Tests/syntax_test_strings.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
'@
5151
#^ meta.string.powershell string.quoted.single.heredoc.powershell punctuation.definition.string.end.powershell
5252

53+
@'
54+
using System;
55+
#^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.heredoc.powershell source.cs
56+
# ^^^^^ keyword.control.import.cs
57+
# ^^^^^^ meta.path.cs
58+
# ^ punctuation.terminator.statement.cs
59+
'@
5360

5461
###[ Double Quoted Strings ]###################################################
5562

@@ -192,6 +199,14 @@
192199
# ^^ constant.character.escape.powershell
193200
# ^ punctuation.definition.string.end.powershell
194201

202+
@"
203+
using System;
204+
#^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.heredoc.powershell source.cs
205+
# ^^^^^ keyword.control.import.cs
206+
# ^^^^^^ meta.path.cs
207+
# ^ punctuation.terminator.statement.cs
208+
"@
209+
195210

196211
###[ String Formatting ]#######################################################
197212

0 commit comments

Comments
 (0)