Skip to content

Commit e0babbf

Browse files
committed
fix(syntax): highlight mod paths without ::
There is one specific case when we know that a token is a modpath, but it doesn't precede a '::'. Example: ```rust use foo; ``` We know `foo` must be a module, but under normal circumstances it appears like an Identifier. This commit adds special logic to identify these cases.
1 parent 6440754 commit e0babbf

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

syntax/rust.vim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ syn keyword rustKeyword yield nextgroup=@rustIdentifiers skipempty skipwhi
5151
syn keyword rustSuper super
5252
syn keyword rustKeyword where nextgroup=@rustIdentifiers skipempty skipwhite
5353
syn keyword rustUnsafeKeyword unsafe
54-
syn keyword rustKeyword use nextgroup=rustModPath skipempty skipwhite
54+
syn keyword rustKeyword mod use nextgroup=rustModPath skipempty skipwhite
5555
" FIXME: Scoped impl's name is also fallen in this category
56-
syn keyword rustKeyword mod trait nextgroup=rustType skipempty skipwhite
56+
syn keyword rustKeyword trait nextgroup=rustType skipempty skipwhite
5757
syn keyword rustStorage move mut ref static const nextgroup=rustStorage,@rustIdentifiers skipempty skipwhite
5858
syn match rustDefault /\<default\ze\_s\+\(impl\|fn\|type\|const\)\>/ display
5959
syn keyword rustAwait await nextgroup=@rustIdentifiers skipempty skipwhite
@@ -121,7 +121,9 @@ syn keyword rustBoolean true false
121121

122122
" If foo::bar changes to foo.bar, change this ("::" to "\.").
123123
" If foo::bar changes to Foo::bar, change this (first "\w" to "\u").
124-
syn match rustModPath "\w\(\w\)*::\(<\)\@!"he=e-2,me=e-2 nextgroup=rustModPathSep contains=rustSelf display
124+
syn cluster rustScopes contains=rustSuper,rustSelf,rustPubScopeCrate
125+
syn match rustModPath "\w\(\w\)*::\(<\)\@!"he=e-2,me=e-2 nextgroup=rustModPathSep contains=@rustScopes display
126+
syn match rustModPath "\(use\|mod\)\@<=\(::\| \)\<\w\+\>\(;\)\@=" contains=@rustScopes display
125127
syn match rustModPathSep "::" nextgroup=@rustIdentifiers skipempty skipwhite display
126128
syn region rustFoldModPath matchgroup=rustNoise start="\(::\s*\n*\)\@<={" end="}" contains=rustCommentBlock,rustCommentBlockDoc,rustCommentLineDoc,rustCommentLine,@rustIdentifiers,rustNoise transparent fold
127129

0 commit comments

Comments
 (0)