diff --git a/autoload/blacklist.vim b/autoload/blacklist.vim index 7d1dd1f..0aad20f 100644 --- a/autoload/blacklist.vim +++ b/autoload/blacklist.vim @@ -484,45 +484,94 @@ let s:blacklist = { \ 'while' \ ], \ 'rust': [ - \ 'Self', \ 'as', + \ 'AsMut', + \ 'AsRef', + \ 'assert', \ 'bool', + \ 'Box', \ 'box', \ 'break', \ 'char', \ 'const', \ 'continue', + \ 'Copy', \ 'crate', + \ 'Debug', + \ 'Decodable', + \ 'Default', + \ 'DoubleEndedIterator', + \ 'Drop', \ 'else', + \ 'Encodable', \ 'enum', + \ 'Eq', + \ 'Err', + \ 'ExactSizeIterator', + \ 'Extend', \ 'extern', \ 'f32', \ 'f64', + \ 'false', + \ 'Fn', \ 'fn', + \ 'FnMut', + \ 'FnOnce', \ 'for', + \ 'From', + \ 'FromPrimitive', + \ 'Hash', + \ 'i128', \ 'i16', \ 'i32', \ 'i64', \ 'i8', \ 'if', \ 'impl', + \ 'in', + \ 'Into', + \ 'IntoIterator', \ 'isize', + \ 'Iterator', \ 'let', \ 'loop', \ 'match', \ 'mod', \ 'move', \ 'mut', + \ 'None', + \ 'Ok', + \ 'Option', + \ 'Ord', + \ 'panic', + \ 'PartialEq', + \ 'PartialOrd', \ 'pub', - \ 'return', + \ 'Rand', \ 'ref', + \ 'Result', + \ 'return', + \ 'RustcDecodable', + \ 'RustcEncodable', + \ 'Self', \ 'self', + \ 'Send', + \ 'Show', + \ 'Sized', + \ 'SliceConcatExt', + \ 'Some', \ 'static', \ 'str', + \ 'String', \ 'struct', \ 'super', + \ 'Sync', + \ 'ToOwned', + \ 'ToString', \ 'trait', + \ 'true', \ 'type', + \ 'u128', \ 'u16', \ 'u32', \ 'u64', @@ -530,6 +579,7 @@ let s:blacklist = { \ 'unsafe', \ 'use', \ 'usize', + \ 'Vec', \ 'where', \ 'while', \ ], diff --git a/plugin/semhl.vim b/plugin/semhl.vim index 8c094ef..d524a65 100644 --- a/plugin/semhl.vim +++ b/plugin/semhl.vim @@ -13,9 +13,29 @@ if (exists('g:semanticEnableFileTypes')) endif endif +function! BuildColorSubset(start, offset, end) + let subSet = range(a:start + a:offset, a:start + a:end) + return subSet +endfunction + +function! BuildTermColors() + let termColors = [] + let start_at = 16 + let max_colors = 195 + let offset = 6 + let subset_size = 30 + + while start_at < max_colors + let colorSubset = BuildColorSubset(start_at, offset, subset_size) + let termColors = termColors + colorSubset + let start_at = start_at + offset + subset_size + endwhile + return termColors +endfunction + " Set defaults for colors let s:semanticGUIColors = ["#9CD8F7", "#F5FA1D", "#F97C65", "#35D27F", "#EB75D6", "#E5D180", "#8997F5", "#D49DA5", "#7FEC35", "#F6B223", "#B4F1C3", "#99B730", "#F67C1B", "#3AC6BE", "#EAAFF1", "#DE9A4E", "#BBEA87", "#EEF06D", "#8FB272", "#EAA481", "#F58AAE", "#80B09B", "#5DE866", "#B5A5C5", "#88ADE6", "#4DAABD", "#EDD528", "#FA6BB2", "#47F2D4", "#F47F86", "#2ED8FF", "#B8E01C", "#C5A127", "#74BB46", "#D386F1", "#97DFD6", "#B1A96F", "#66BB75", "#97AA49", "#EF874A", "#48EDF0", "#C0AE50", "#89AAB6", "#D7D1EB", "#5EB894", "#57F0AC", "#B5AF1B", "#B7A5F0", "#8BE289", "#D38AC6", "#C8EE63", "#ED9C36", "#85BA5F", "#9DEA74", "#85C52D", "#40B7E5", "#EEA3C2", "#7CE9B6", "#8CEC58", "#D8A66C", "#51C03B", "#C4CE64", "#45E648", "#4DC15E", "#63A5F3", "#EA8C66", "#D2D43E", "#E5BCE8", "#E4B7CB", "#B092F4", "#44C58C", "#D1E998", "#76E4F2", "#E19392", "#A8E5A4", "#BF9FD6", "#E8C25B", "#58F596", "#6BAEAC", "#94C291", "#7EF1DB", "#E8D65C", "#A7EA38", "#D38AE0", "#ECF453", "#5CD8B8", "#B6BF6B", "#BEE1F1", "#B1D43E", "#EBE77B", "#84A5CD", "#CFEF7A", "#A3C557", "#E4BB34", "#ECB151", "#BDC9F2", "#5EB0E9", "#E09764", "#9BE3C8", "#B3ADDC", "#B2AC36", "#C8CD4F", "#C797AF", "#DCDB26", "#BCA85E", "#E495A5", "#F37DB8", "#70C0B1", "#5AED7D", "#E49482", "#8AA1F0", "#B3EDEE", "#DAEE34", "#EBD646", "#ECA2D2", "#A0A7E6", "#3EBFD3", "#C098BF", "#F1882E", "#77BFDF", "#7FBFC7", "#D4951F", "#A5C0D0", "#B892DE", "#F8CB31", "#75D0D9", "#A6A0B4", "#EA98E4", "#F38BE6", "#DC83A4"] -let s:semanticTermColors = range(20) +let s:semanticTermColors = BuildTermColors() " The user can change the GUI/Term colors, but cannot directly access the list of colors we use " If the user overrode the default in their vimrc, use that @@ -103,33 +123,39 @@ function! s:semHighlight() let b:cache_defined = {} let buflen = line('$') - let pattern = '\<[\$]*[a-zA-Z\_][a-zA-Z0-9\_]*\>' - let cur_color = 0 + let pattern = '\<[\$@]*[a-zA-Z\_][a-zA-Z0-9\_]*\>' let colorLen = len(s:semanticColors) + let cur_color = str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:]) % colorLen " found on https://stackoverflow.com/questions/12737977/native-vim-random-number-script + let l:blacklist_exists_for_filetype = !empty(s:blacklist) && has_key(s:blacklist, &filetype) while buflen let curline = getline(buflen) let index = 0 while 1 - let match = matchstr(curline, pattern, index) + let [match, start_at, stop_at] = matchstrpos(curline, pattern, index) if (empty(match)) break endif - - let l:no_blacklist_exists_for_filetype = empty(s:blacklist) || !has_key(s:blacklist, &filetype) - if ((l:no_blacklist_exists_for_filetype || index(s:blacklist[&filetype], match) == -1) && !has_key(b:cache_defined, match)) - let b:cache_defined[match] = 1 - let l:containedin = '' - if (!empty(s:containedinlist) && has_key(s:containedinlist, &filetype)) - let l:containedin = ' containedin=' . s:containedinlist[&filetype] - endif - - execute 'syn keyword _semantic' . s:getCachedColor(cur_color, match) . l:containedin . ' ' . match - let cur_color = (cur_color + 1) % colorLen - endif - - let index += len(match) + 1 + + let l:match_is_blacklisted = l:blacklist_exists_for_filetype && index(s:blacklist[&filetype], match) > 0 + let l:is_already_cached = has_key(b:cache_defined, match) + let l:is_already_contained_in_list = !empty(s:containedinlist) && has_key(s:containedinlist, &filetype) + + if (l:match_is_blacklisted || l:is_already_cached) + break + endif + + let b:cache_defined[match] = 1 + let l:containedin = '' + if (l:is_already_contained_in_list) + let l:containedin = ' containedin=' . s:containedinlist[&filetype] + endif + + execute 'syn keyword _semantic' . s:getCachedColor(cur_color, match) . l:containedin . ' ' . match + + let cur_color = ((cur_color + 1) % colorLen) + 1 + let index = stop_at endwhile let buflen -= 1 endwhile @@ -141,7 +167,7 @@ function! s:buildColors() else let type = 'fg' endif - if $NVIM_TUI_ENABLE_TRUE_COLOR || has('gui_running') || (exists('&guicolors') && &guicolors) + if $NVIM_TUI_ENABLE_TRUE_COLOR || has('gui_running') || (exists('&guicolors') && &guicolors) || (exists('&termguicolors') && &termguicolors) let colorType = 'gui' " Update color list in case the user made any changes let s:semanticColors = g:semanticGUIColors