Skip to content

Commit cc148a9

Browse files
Initial support for .csproj, .slnx, .proj, .props and .targets files (#64)
This PR implements syntax highlighting for following XML-based file types: - `.csproj` - `.slnx` - `.proj` - `.props` - `.targets` The syntax highlighting is done by replicating the standard XML grammar (from Zed XML extension) for each of the file types. Additionally, this PR includes support for running .NET Restore/Build for currently-opened Solution or Project file, through Zed Tasks. --- **EDIT:** - The PR now includes `.proj` extension too. - The `.proj`, `.props` and `.targets` combined into a single language called "MSBuild". - Since the grammars share the same queries (sourced from Original Zed XML extension), the PR has been updated to use symlinks to reduce duplication. --------- Co-authored-by: MrSubidubi <dev@bahn.sh>
1 parent 5d65437 commit cc148a9

15 files changed

Lines changed: 306 additions & 0 deletions

extension.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ language = "CSharp"
2424
[grammars.c_sharp]
2525
repository = "https://github.com/tree-sitter/tree-sitter-c-sharp"
2626
commit = "485f0bae0274ac9114797fc10db6f7034e4086e3"
27+
28+
[grammars.xml]
29+
repository = "https://github.com/tree-sitter-grammars/tree-sitter-xml"
30+
commit = "863dbc381f44f6c136a399e684383b977bb2beaa"
31+
path = "xml"

languages/csproj/config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "C# Project File"
2+
grammar = "xml"
3+
path_suffixes = ["csproj"]
4+
block_comment = ["<!-- ", " -->"]
5+
autoclose_before = "<"
6+
brackets = [{ start = "<", end = ">", close = true, newline = true }]
7+
prettier_parser_name = "xml"
8+
prettier_plugins = ["@prettier/plugin-xml"]
9+
hard_tabs = true

languages/csproj/highlights.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../msbuild/highlights.scm

languages/csproj/indents.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../msbuild/indents.scm

languages/csproj/outline.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../msbuild/outline.scm

languages/csproj/tasks.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"label": "Restore Current Project",
4+
"command": "dotnet restore",
5+
"args": ["$ZED_FILE"],
6+
"use_new_terminal": false,
7+
"allow_concurrent_runs": false,
8+
"reveal": "always",
9+
"reveal_target": "center",
10+
"hide": "on_success",
11+
"shell": "system"
12+
},
13+
{
14+
"label": "Build Current Project",
15+
"command": "dotnet build",
16+
"args": ["$ZED_FILE"],
17+
"use_new_terminal": false,
18+
"allow_concurrent_runs": false,
19+
"reveal": "always",
20+
"reveal_target": "center",
21+
"hide": "on_success",
22+
"shell": "system"
23+
}
24+
]

languages/msbuild/config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "MSBuild File"
2+
grammar = "xml"
3+
path_suffixes = ["proj", "props", "targets"]
4+
block_comment = ["<!-- ", " -->"]
5+
autoclose_before = "<"
6+
brackets = [{ start = "<", end = ">", close = true, newline = true }]
7+
prettier_parser_name = "xml"
8+
prettier_plugins = ["@prettier/plugin-xml"]
9+
hard_tabs = true

languages/msbuild/highlights.scm

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
; XML declaration
2+
"xml" @keyword
3+
4+
[
5+
"version"
6+
"encoding"
7+
"standalone"
8+
] @property
9+
10+
(EncName) @string.special
11+
12+
(VersionNum) @number
13+
14+
[
15+
"yes"
16+
"no"
17+
] @boolean
18+
19+
; Processing instructions
20+
(PI) @embedded
21+
22+
(PI
23+
(PITarget) @keyword)
24+
25+
; Element declaration
26+
(elementdecl
27+
"ELEMENT" @keyword
28+
(Name) @tag)
29+
30+
(contentspec
31+
(_
32+
(Name) @property))
33+
34+
"#PCDATA" @type.builtin
35+
36+
[
37+
"EMPTY"
38+
"ANY"
39+
] @string.special.symbol
40+
41+
[
42+
"*"
43+
"?"
44+
"+"
45+
] @operator
46+
47+
; Entity declaration
48+
(GEDecl
49+
"ENTITY" @keyword
50+
(Name) @constant)
51+
52+
(GEDecl
53+
(EntityValue) @string)
54+
55+
(NDataDecl
56+
"NDATA" @keyword
57+
(Name) @label)
58+
59+
; Parsed entity declaration
60+
(PEDecl
61+
"ENTITY" @keyword
62+
"%" @operator
63+
(Name) @constant)
64+
65+
(PEDecl
66+
(EntityValue) @string)
67+
68+
; Notation declaration
69+
(NotationDecl
70+
"NOTATION" @keyword
71+
(Name) @constant)
72+
73+
(NotationDecl
74+
(ExternalID
75+
(SystemLiteral
76+
(URI) @string.special)))
77+
78+
; Attlist declaration
79+
(AttlistDecl
80+
"ATTLIST" @keyword
81+
(Name) @tag)
82+
83+
(AttDef
84+
(Name) @property)
85+
86+
(AttDef
87+
(Enumeration
88+
(Nmtoken) @string))
89+
90+
(DefaultDecl
91+
(AttValue) @string)
92+
93+
[
94+
(StringType)
95+
(TokenizedType)
96+
] @type.builtin
97+
98+
(NotationType
99+
"NOTATION" @type.builtin)
100+
101+
[
102+
"#REQUIRED"
103+
"#IMPLIED"
104+
"#FIXED"
105+
] @attribute
106+
107+
; Entities
108+
(EntityRef) @constant
109+
110+
((EntityRef) @constant.builtin
111+
(#any-of? @constant.builtin "&amp;" "&lt;" "&gt;" "&quot;" "&apos;"))
112+
113+
(CharRef) @constant
114+
115+
(PEReference) @constant
116+
117+
; External references
118+
[
119+
"PUBLIC"
120+
"SYSTEM"
121+
] @keyword
122+
123+
(PubidLiteral) @string.special
124+
125+
(SystemLiteral
126+
(URI) @markup.link)
127+
128+
; Processing instructions
129+
(XmlModelPI
130+
"xml-model" @keyword)
131+
132+
(StyleSheetPI
133+
"xml-stylesheet" @keyword)
134+
135+
(PseudoAtt
136+
(Name) @property)
137+
138+
(PseudoAtt
139+
(PseudoAttValue) @string)
140+
141+
; Doctype declaration
142+
(doctypedecl
143+
"DOCTYPE" @keyword)
144+
145+
(doctypedecl
146+
(Name) @type)
147+
148+
; Tags
149+
(STag
150+
(Name) @tag)
151+
152+
(ETag
153+
(Name) @tag)
154+
155+
(EmptyElemTag
156+
(Name) @tag)
157+
158+
; Attributes
159+
(Attribute
160+
(Name) @property)
161+
162+
(Attribute
163+
(AttValue) @string)
164+
165+
; Delimiters & punctuation
166+
[
167+
"<?"
168+
"?>"
169+
"<!"
170+
"]]>"
171+
"<"
172+
">"
173+
"</"
174+
"/>"
175+
] @punctuation.delimiter
176+
177+
[
178+
"("
179+
")"
180+
"["
181+
"]"
182+
] @punctuation.bracket
183+
184+
[
185+
"\""
186+
"'"
187+
] @punctuation.delimiter
188+
189+
[
190+
","
191+
"|"
192+
"="
193+
] @operator
194+
195+
; Text
196+
(CharData) @markup
197+
198+
(CDSect
199+
(CDStart) @markup.heading
200+
(CData) @markup.raw
201+
"]]>" @markup.heading)
202+
203+
; Misc
204+
(Comment) @comment
205+
206+
(ERROR) @error

languages/msbuild/indents.scm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(STag
2+
">" @end) @indent
3+
4+
(EmptyElemTag
5+
"/>" @end) @indent

languages/msbuild/outline.scm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(element
2+
(STag
3+
(Name) @name)) @item
4+
5+
(EmptyElemTag
6+
(Name) @name) @item
7+
8+
(doctypedecl
9+
(Name) @name) @item

0 commit comments

Comments
 (0)