Skip to content

Commit b5a64fc

Browse files
committed
Highlight the new type in all type declarations
1 parent baca6f1 commit b5a64fc

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

syntax/cs.vim

+17-5
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ set cpoptions&vim
2424
syn keyword csType bool byte char decimal double float int long object sbyte short string T uint ulong ushort var void dynamic
2525
syn keyword csType nint nuint " contextual
2626

27-
syn keyword csStorage enum interface namespace struct
28-
syn match csStorage "\<delegate\>"
27+
syn keyword csStorage namespace
28+
" syn keyword csStorage enum interface namespace struct
29+
" syn match csStorage "\<delegate\>"
2930
syn keyword csRepeat break continue do for foreach goto return while
3031
syn keyword csConditional else if switch
3132
syn keyword csLabel case default
@@ -154,13 +155,21 @@ endif
154155

155156
syn cluster csPreProcessor contains=csPreProc.*
156157

157-
syn region csClassType start="\<class\>"hs=s+6 end="[:\n{]"me=e-1 contains=csClass
158+
syn region csClassType matchgroup=csStorage start="\<class\>" end="[:{]"me=e-1
159+
syn region csInterfaceType matchgroup=csStorage start="\<interface\>" end="[:{]"me=e-1
160+
161+
syn region csStructType matchgroup=csStorage start="\<struct\>" end="[:{]"me=e-1
162+
syn region csEnumType matchgroup=csStorage start="\<enum\>" end="[:{]"me=e-1
163+
164+
syn match csStorage "\<delegate\>\%(\_s*[*(]\)\@!" nextgroup=csDelegateReturnType skipwhite skipempty
165+
syn match csDelegateReturnType "@\=\h\w*\_s*\%(<\_[^>]\+>\)\=?\=" nextgroup=csDelegateType skipwhite skipempty contained contains=csType,csGeneric
166+
syn match csDelegateType "@\=\h\w*\_s*\%(<\_[^>]\+>\)\=\ze\_s*(" contained
167+
158168
" csUserType may be defined by user scripts/plugins - it should be contained in csNewType
159169
syn region csNewType start="\<new\>"hs=s+4 end="[;\n{(<\[]"me=e-1 contains=csNew,@csNamespaceAlias,csUserType
160170
syn region csIsType start=" is "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs
161171
syn region csIsType start=" as "hs=s+4 end="[A-Za-z0-9]\+" oneline contains=csIsAs
162172
syn keyword csNew new contained
163-
syn keyword csClass class contained
164173
syn keyword csIsAs is as
165174

166175
syn keyword csBoolean false true
@@ -223,9 +232,12 @@ syn match csIdentifier "@\h\w*"
223232
" The default highlighting.
224233
hi def link csType Type
225234
hi def link csClassType Type
235+
hi def link csInterfaceType Type
236+
hi def link csStructType Type
237+
hi def link csEnumType Type
238+
hi def link csDelegateType Type
226239
hi def link csIsType Type
227240
hi def link csStorage Structure
228-
hi def link csClass Structure
229241
hi def link csRepeat Repeat
230242
hi def link csConditional Conditional
231243
hi def link csLabel Label

test/types.vader

+39
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,42 @@ Execute:
2727
AssertEqual 'csOpSymbols', SyntaxOf('\*')
2828
AssertEqual 'csManagedModifier', SyntaxOf('\<managed')
2929

30+
Given cs (class type declaration):
31+
class Foo<T, U> : Bar<T, U> {}
32+
33+
Execute:
34+
AssertEqual 'csStorage', SyntaxOf('class')
35+
AssertEqual 'csClassType', SyntaxOf('Foo')
36+
AssertEqual 'csClassType', SyntaxOf('T', 1)
37+
38+
Given cs (interface type declaration):
39+
interface Foo<T, U> : Bar<T, U> {}
40+
41+
Execute:
42+
AssertEqual 'csStorage', SyntaxOf('interface')
43+
AssertEqual 'csInterfaceType', SyntaxOf('Foo')
44+
AssertEqual 'csInterfaceType', SyntaxOf('T', 1)
45+
46+
Given cs (struct type declaration):
47+
struct Foo<T, U> : Bar<T, U> {}
48+
49+
Execute:
50+
AssertEqual 'csStorage', SyntaxOf('struct')
51+
AssertEqual 'csStructType', SyntaxOf('Foo')
52+
AssertEqual 'csStructType', SyntaxOf('T', 1)
53+
54+
Given cs (enum type declaration):
55+
enum Foo : int {}
56+
57+
Execute:
58+
AssertEqual 'csStorage', SyntaxOf('enum')
59+
AssertEqual 'csEnumType', SyntaxOf('Foo')
60+
61+
Given cs (delegate type declaration):
62+
delegate Foo<Bar<T>> Baz<T>();
63+
64+
Execute:
65+
AssertEqual 'csStorage', SyntaxOf('delegate')
66+
AssertEqual 'csDelegateType', SyntaxOf('Baz')
67+
AssertEqual 'csDelegateType', SyntaxOf('T', 2)
68+

0 commit comments

Comments
 (0)