Skip to content

Commit 1ca1512

Browse files
committed
Fix custom text properties for semantic highlighting
We were supposed to allow users to set highlight groups for any token types that we don't understand, as servers can basically return anything they like. This didn't work and we just always complained about it. Now we trap the "text property type doesn't exist" error and warn then. This allows users to specify the missing ones to stfu the error. Also improved the message to point to the help.
1 parent 142a559 commit 1ca1512

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

python/ycm/semantic_highlighting.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from ycm import text_properties as tp
2323
from ycm import scrolling_range as sr
2424

25+
import vim
26+
2527

2628
HIGHLIGHT_GROUP = {
2729
'namespace': 'Type',
@@ -107,16 +109,21 @@ def _Draw( self ):
107109
self._prop_id = NextPropID()
108110

109111
for token in tokens:
110-
if token[ 'type' ] not in HIGHLIGHT_GROUP:
111-
if token[ 'type' ] not in REPORTED_MISSING_TYPES:
112-
REPORTED_MISSING_TYPES.add( token[ 'type' ] )
113-
vimsupport.PostVimMessage(
114-
f"Missing property type for { token[ 'type' ] }" )
115-
continue
116112
prop_type = f"YCM_HL_{ token[ 'type' ] }"
117-
118113
rng = token[ 'range' ]
119114
self.GrowRangeIfNeeded( rng )
120-
tp.AddTextProperty( self._bufnr, self._prop_id, prop_type, rng )
115+
116+
try:
117+
tp.AddTextProperty( self._bufnr, self._prop_id, prop_type, rng )
118+
except vim.error as e:
119+
if 'E971:' in str( e ): # Text property doesn't exist
120+
if token[ 'type' ] not in REPORTED_MISSING_TYPES:
121+
REPORTED_MISSING_TYPES.add( token[ 'type' ] )
122+
vimsupport.PostVimMessage(
123+
f"Token type { token[ 'type' ] } not supported. "
124+
f"Define property type { prop_type }. "
125+
f"See :help youcompleteme-customising-highlight-groups" )
126+
else:
127+
raise e
121128

122129
tp.ClearTextProperties( self._bufnr, prop_id = prev_prop_id )

0 commit comments

Comments
 (0)