Skip to content

Commit 2760cd6

Browse files
authored
Merge pull request #2663 from bhcleek/prop-ordering
define text property types in syntax/go.vim
2 parents d5ef8ec + bd63415 commit 2760cd6

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

autoload/go/util.vim

+4
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ endfunction
553553

554554
function! go#util#ClearHighlights(group) abort
555555
if exists('*prop_remove')
556+
" the property type may not exist when syntax highlighting is not enabled.
557+
if empty(prop_type_get(a:group))
558+
return
559+
endif
556560
if !has('patch-8.1.1035')
557561
return prop_remove({'type': a:group, 'all': 1}, 1, line('$'))
558562
endif

ftplugin/go.vim

+1-13
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,6 @@ if get(g:, "go_textobj_enabled", 1)
7474
xnoremap <buffer> <silent> [[ :<c-u>call go#textobj#FunctionJump('v', 'prev')<cr>
7575
endif
7676

77-
if exists('*prop_type_add')
78-
if empty(prop_type_get('goSameId'))
79-
call prop_type_add('goSameId', {'highlight': 'goSameId'})
80-
endif
81-
if empty(prop_type_get('goDiagnosticError'))
82-
call prop_type_add('goDiagnosticError', {'highlight': 'goDiagnosticError'})
83-
endif
84-
if empty(prop_type_get('goDiagnosticWarning'))
85-
call prop_type_add('goDiagnosticWarning', {'highlight': 'goDiagnosticWarning'})
86-
endif
87-
endif
88-
8977
" Autocommands
9078
" ============================================================================
9179
"
@@ -131,7 +119,7 @@ augroup vim-go-buffer
131119
" window doesn't highlight th previously loaded buffer's diagnostics.
132120
autocmd BufWinLeave <buffer> call go#lsp#ClearDiagnosticHighlights()
133121
" clear diagnostics when a new buffer is loaded in the window so that the
134-
" previous buffer's diagnostcs aren't used.
122+
" previous buffer's diagnostics aren't used.
135123
autocmd BufWinEnter <buffer> call go#lsp#ClearDiagnosticHighlights()
136124

137125
autocmd BufEnter <buffer>

syntax/go.vim

+18
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,24 @@ function! s:hi()
393393
hi def link goDiagnosticError SpellBad
394394
hi def link goDiagnosticWarning SpellRare
395395

396+
" TODO(bc): is it appropriate to define text properties in a syntax file?
397+
" The highlight groups need to be defined before the text properties types
398+
" are added, and when users have syntax enabled in their vimrc after
399+
" filetype plugin on, the highlight groups won't be defined when
400+
" ftplugin/go.vim is executed when the first go file is opened.
401+
" See https://github.com/fatih/vim-go/issues/2658.
402+
if exists('*prop_type_add')
403+
if empty(prop_type_get('goSameId'))
404+
call prop_type_add('goSameId', {'highlight': 'goSameId'})
405+
endif
406+
if empty(prop_type_get('goDiagnosticError'))
407+
call prop_type_add('goDiagnosticError', {'highlight': 'goDiagnosticError'})
408+
endif
409+
if empty(prop_type_get('goDiagnosticWarning'))
410+
call prop_type_add('goDiagnosticWarning', {'highlight': 'goDiagnosticWarning'})
411+
endif
412+
endif
413+
396414
hi def link goDeclsFzfKeyword Keyword
397415
hi def link goDeclsFzfFunction Function
398416
hi def link goDeclsFzfSpecialComment SpecialComment

0 commit comments

Comments
 (0)