Skip to content

Commit ff46822

Browse files
authored
Remove configuration variables for highlights (#97)
Closes #95 Keep the `dart_html_in_strings` variable since it has behavior that can't be changed with highlight groups. Remove the `dart_highlight_types` and `dart_corelib_highlight` variables. The behavior from setting these can be achieved by linking specific highlight groups to `Normal`. Move the lowercase "primitive" type names from `dartCoreType` to `dartSdkClass` since they fit better alongside `String`. The ones remaining in `dartCoreType` are still a "type", or at least often used in a similar way, but have no class definition. When we add `Never` it will be a `dartCoreType`. Add a doc section that describes the highlight groups that are most likely to be configured with an example of how to disable them. Rename some groups from "core" to "sdk" since they are more broad than the `dart:core` library. Use singular names for all highlight groups. Adjust some spacing for better alignment within the syntax file.
1 parent 07f4d70 commit ff46822

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ call vundle#end()
7171
Enable HTML syntax highlighting inside Dart strings with `let
7272
dart_html_in_string=v:true` (default false).
7373

74-
Disable highlighting of core library classes with `let
75-
dart_corelib_highlight=v:false` (default true).
74+
Highlighting for specific syntax groups can be disabled by defining custom
75+
highlight group links. See `:help dart-syntax`
7676

77-
Disable highlighting of user defined types (words starting with a capital
78-
letter) with `let dart_highlight_types=v:false` (default true).
77+
Enable Dart style guide syntax (like 2-space indentation) with
78+
`let g:dart_style_guide = 2`
7979

80-
Enable Dart style guide syntax (like 2-space indentation) with `let dart_style_guide = 2`
81-
82-
Enable DartFmt execution on buffer save with `let dart_format_on_save = 1`
80+
Enable DartFmt execution on buffer save with `let g:dart_format_on_save = 1`
8381

8482
## FAQ
8583

doc/dart.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,31 @@ Set to any value (set to `2` by convention) to set tab and width behavior to
5151
match the Dart style guide - spaces only with an indent of 2. Also sets
5252
`formatoptions += t` to auto wrap text.
5353

54+
SYNTAX HIGHLIGHTING *dart-syntax*
55+
56+
This plugin uses narrow highlight groups to allow selectively disabling the
57+
syntax highlights. Link any of the following groups to the `Normal` highlight
58+
group to disable them:
59+
60+
`dartSdkException`: Capitalized exception or error classes defined in the SDK.
61+
62+
`dartCoreType`: `void`, `var`, `dynamic`
63+
64+
`dartSdkClass`: Capitalized classes defined in the SDK, along with `bool`,
65+
`int`, `double`, and `num`.
66+
67+
`dartUserType`: Any capitalized identifier.
68+
69+
`dartType`: Combines `dartCoreType`, `dartSdkClass`, and `dartUserType`.
70+
71+
`dartSdkTypedef`: SDK defined `typdef`s.
72+
73+
`dartFunction`: Any lower cased identifier preceding an open parenthesis.
74+
75+
For example, to remove the highlighting for type and function names:
76+
>
77+
highlight link dartType Normal
78+
highlight link dartFunction Normal
79+
<
80+
5481
vim:tw=78:sw=4:ts=8:ft=help:norl:

syntax/dart.vim

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ syntax keyword dartConstant null
2626
syntax keyword dartTypedef this super class typedef enum mixin
2727
syntax keyword dartOperator new is as in
2828
syntax match dartOperator "+=\=\|-=\=\|*=\=\|/=\=\|%=\=\|\~/=\=\|<<=\=\|>>=\=\|[<>]=\=\|===\=\|\!==\=\|&=\=\|\^=\=\||=\=\|||\|&&\|\[\]=\=\|=>\|!\|\~\|?\|:"
29-
syntax keyword dartType void var bool int double num dynamic
29+
syntax keyword dartCoreType void var dynamic
3030
syntax keyword dartStatement return
3131
syntax keyword dartStorageClass static abstract final const factory
3232
syntax keyword dartExceptions throw rethrow try on catch finally
@@ -49,30 +49,26 @@ syntax match dartLibrary "^\(library\|part of\|part\)\>"
4949
syntax match dartMetadata "@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>"
5050

5151
" Numbers
52-
syntax match dartNumber "\<\d\+\(\.\d\+\)\=\>"
52+
syntax match dartNumber "\<\d\+\(\.\d\+\)\=\>"
5353

5454
" User Types
55-
if !exists('dart_highlight_types') || dart_highlight_types
56-
syntax match dartTypeName "\<_\?\u[[:alnum:]_\$]*\>"
57-
endif
55+
syntax match dartUserType "\<_\?\u[[:alnum:]_\$]*\>"
5856

5957
" Function highlighting
60-
syntax match dartFunction "\zs\<\(_\?\l[[:alnum:]_\$]*\)\>*\s*\ze("
61-
62-
" Core libraries
63-
if !exists('dart_corelib_highlight') || dart_corelib_highlight
64-
syntax keyword dartCoreClasses BidirectionalIterator Comparable DateTime
65-
\ Duration Expando Function Invocation Iterable Iterator List Map Match
66-
\ Object Pattern RegExp RuneIterator Runes Set StackTrace Stopwatch String
67-
\ StringBuffer StringSink Symbol Type
68-
syntax keyword dartCoreTypedefs Comparator
69-
syntax keyword dartCoreExceptions AbstractClassInstantiationError
70-
\ ArgumentError AssertionError CastError ConcurrentModificationError
71-
\ Error Exception FallThroughError FormatException
72-
\ IntegerDivisionByZeroException NoSuchMethodError NullThrownError
73-
\ OutOfMemoryError RangeError RuntimeError StackOverflowError StateError
74-
\ TypeError UnimplementedError UnsupportedError
75-
endif
58+
syntax match dartFunction "\zs\<\(_\?\l[[:alnum:]_\$]*\)\>*\s*\ze("
59+
60+
" SDK libraries
61+
syntax keyword dartSdkClass BidirectionalIterator Comparable DateTime
62+
\ Duration Expando Function Invocation Iterable Iterator List Map Match
63+
\ Object Pattern RegExp RuneIterator Runes Set StackTrace Stopwatch String
64+
\ StringBuffer StringSink Symbol Type bool int double num
65+
syntax keyword dartSdkTypedef Comparator
66+
syntax keyword dartSdkException AbstractClassInstantiationError
67+
\ ArgumentError AssertionError CastError ConcurrentModificationError
68+
\ Error Exception FallThroughError FormatException
69+
\ IntegerDivisionByZeroException NoSuchMethodError NullThrownError
70+
\ OutOfMemoryError RangeError RuntimeError StackOverflowError StateError
71+
\ TypeError UnimplementedError UnsupportedError
7672

7773
" Comments
7874
syntax keyword dartTodo contained TODO FIXME XXX
@@ -120,21 +116,22 @@ highlight default link dartLineComment Comment
120116
highlight default link dartLineDocComment Comment
121117
highlight default link dartShebangLine Comment
122118
highlight default link dartConstant Constant
123-
highlight default link dartTypedef Typedef
124119
highlight default link dartTodo Todo
125120
highlight default link dartKeyword Keyword
126-
highlight default link dartType Type
127-
highlight default link dartTypeName Type
128121
highlight default link dartInterpolation PreProc
129122
highlight default link dartDocLink SpecialComment
130123
highlight default link dartSpecialChar SpecialChar
131124
highlight default link dartLibrary Include
132125
highlight default link dartUri String
133126
highlight default link dartCombinator Keyword
134-
highlight default link dartCoreClasses Type
135-
highlight default link dartCoreTypedefs Typedef
136-
highlight default link dartCoreExceptions Exception
137127
highlight default link dartMetadata PreProc
128+
highlight default link dartSdkTypedef Typedef
129+
highlight default link dartTypedef Typedef
130+
highlight default link dartSdkException Exception
131+
highlight default link dartSdkClass dartType
132+
highlight default link dartCoreType dartType
133+
highlight default link dartUserType dartType
134+
highlight default link dartType Type
138135
highlight default link dartFunction Function
139136

140137
let b:current_syntax = "dart"

0 commit comments

Comments
 (0)