Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
matrix:
vim: [ 'new', 'old' ]
arch: [ 'x86_64' ]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container: 'youcompleteme/ycm-vim-${{ matrix.arch }}-py3:test'
env:
COVERAGE: true
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1795,12 +1795,20 @@ in the Vim gutter, the relevant groups are:
`error` if they exist
- `YcmWarningSign`, which falls back to group `SyntasticWarningSign` and then
`todo` if they exist
- `YcmInformationSign`, which falls back to group `SyntasticInformationSign` and then
`added` if they exist
- `YcmHintSign`, which falls back to group `SyntasticHintSign` and then
`changed` if they exist

You can also style the line that has the warning/error with these groups:

- `YcmErrorLine`, which falls back to group `SyntasticErrorLine` if it exists
- `YcmWarningLine`, which falls back to group `SyntasticWarningLine` if it
exists
- `YcmInformationLine`, which falls back to group `SyntasticInformationLine` if it
exists
- `YcmHintLine`, which falls back to group `SyntasticHintLine` if it
exists

Finally, you can also style the popup for the detailed diagnostics (it is shown
if `g:ycm_show_detailed_diag_in_popup` is set) using the group `YcmErrorPopup`,
Expand All @@ -1820,6 +1828,10 @@ The syntax groups used to highlight regions of text with errors/warnings:
then `SpellBad`
- `YcmWarningSection`, which falls back to group `SyntasticWarning` if it exists
and then `SpellCap`
- `YcmInformationSection`, which falls back to group `SyntasticInformation` if it exists
and then `SpellLocal`
- `YcmHintSection`, which falls back to group `SyntasticHint` if it exists
and then `SpellRare`

Here's how you'd change the style for a group:

Expand Down Expand Up @@ -2942,8 +2954,8 @@ let g:ycm_warning_symbol = '>>'
### The `g:ycm_enable_diagnostic_signs` option

When this option is set, YCM will put icons in Vim's gutter on lines that have a
diagnostic set. Turning this off will also turn off the `YcmErrorLine` and
`YcmWarningLine` highlighting.
diagnostic set. Turning this off will also turn off the `YcmErrorLine`,
`YcmWarningLine`, `YcmInformationLine` and `YcmHintLine` highlighting.

This option is part of the Syntastic compatibility layer; if the option is not
set, YCM will fall back to the value of the `g:syntastic_enable_signs` option
Expand Down
102 changes: 102 additions & 0 deletions autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,22 @@
endif
endif

if !hlexists( 'YcmInformationSign' )
if hlexists( 'SyntasticInformationSign')
highlight default link YcmInformationSign SyntasticInformationSign

Check warning on line 405 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L405

Added line #L405 was not covered by tests
else
highlight default link YcmInformationSign added
endif
endif

if !hlexists( 'YcmHintSign' )
if hlexists( 'SyntasticHintSign')
highlight default link YcmHintSign SyntasticHintSign

Check warning on line 413 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L413

Added line #L413 was not covered by tests
else
highlight default link YcmHintSign changed
endif
endif

if !hlexists( 'YcmErrorLine' )
highlight default link YcmErrorLine SyntasticErrorLine
endif
Expand All @@ -408,6 +424,14 @@
highlight default link YcmWarningLine SyntasticWarningLine
endif

if !hlexists( 'YcmInformationLine' )
highlight default link YcmInformationLine SyntasticInformationLine
endif

if !hlexists( 'YcmHintLine' )
highlight default link YcmHintLine SyntasticHintLine
endif

call sign_define( [
\ { 'name': 'YcmError',
\ 'text': g:ycm_error_symbol,
Expand All @@ -418,6 +442,16 @@
\ 'text': g:ycm_warning_symbol,
\ 'texthl': 'YcmWarningSign',
\ 'linehl': 'YcmWarningLine',
\ 'group': 'ycm_signs' },
\ { 'name': 'YcmInformation',
\ 'text': g:ycm_information_symbol,
\ 'texthl': 'YcmInformationSign',
\ 'linehl': 'YcmInformationLine',
\ 'group': 'ycm_signs' },
\ { 'name': 'YcmHint',
\ 'text': g:ycm_hint_symbol,
\ 'texthl': 'YcmHintSign',
\ 'linehl': 'YcmHintLine',
\ 'group': 'ycm_signs' }
\ ] )

Expand Down Expand Up @@ -476,6 +510,32 @@
hi default link YcmWarningText Conceal
endif
endif
if !hlexists( 'YcmInformationText' )
if exists( '*hlget' )
let YcmInformationText = hlget( 'SpellLocal', v:true )[ 0 ]
let YcmInformationText.name = 'YcmInformationText'
let YcmInformationText.cterm = {}
let YcmInformationText.gui = {}
let YcmInformationText.term = {}
call hlset( [ YcmInformationText] )
else

Check warning on line 521 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L521

Added line #L521 was not covered by tests
" Lame approximation
hi default link YcmInformationText Conceal

Check warning on line 523 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L523

Added line #L523 was not covered by tests
endif
endif
if !hlexists( 'YcmHintText' )
if exists( '*hlget' )
let YcmHintText = hlget( 'SpellRare', v:true )[ 0 ]
let YcmHintText.name = 'YcmHintText'
let YcmHintText.cterm = {}
let YcmHintText.gui = {}
let YcmHintText.term = {}
call hlset( [ YcmHintText] )
else

Check warning on line 534 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L534

Added line #L534 was not covered by tests
" Lame approximation
hi default link YcmHintText Conceal

Check warning on line 536 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L536

Added line #L536 was not covered by tests
endif
endif

if s:PropertyTypeNotDefined( 'YcmVirtDiagError' )
call prop_type_add( 'YcmVirtDiagError', {
Expand All @@ -489,6 +549,18 @@
\ 'priority': 19,
\ 'combine': 0 } )
endif
if s:PropertyTypeNotDefined( 'YcmVirtDiagInformation' )
call prop_type_add( 'YcmVirtDiagInformation', {
\ 'highlight': 'YcmInformationText',
\ 'priority': 18,
\ 'combine': 0 } )
endif
if s:PropertyTypeNotDefined( 'YcmVirtDiagHint' )
call prop_type_add( 'YcmVirtDiagHint', {
\ 'highlight': 'YcmHintText',
\ 'priority': 17,
\ 'combine': 0 } )
endif


if s:PropertyTypeNotDefined( 'YcmVirtDiagPadding' )
Expand All @@ -513,6 +585,36 @@
\ 'override': 1 } )
endif

if !hlexists( 'YcmInformationSection' )
if hlexists( 'SyntasticInformation' )
highlight default link YcmInformationSection SyntasticInformation

Check warning on line 590 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L590

Added line #L590 was not covered by tests
else
highlight default link YcmInformationSection SpellLocal
endif
endif
if s:PropertyTypeNotDefined( 'YcmInformationProperty' )
call prop_type_add( 'YcmInformationProperty', {
\ 'highlight': 'YcmInformationSection',
\ 'priority': 28,
\ 'combine': 0,
\ 'override': 1 } )
endif

if !hlexists( 'YcmHintSection' )
if hlexists( 'SyntasticHint' )
highlight default link YcmHintSection SyntasticHint

Check warning on line 605 in autoload/youcompleteme.vim

View check run for this annotation

Codecov / codecov/patch

autoload/youcompleteme.vim#L605

Added line #L605 was not covered by tests
else
highlight default link YcmHintSection SpellRare
endif
endif
if s:PropertyTypeNotDefined( 'YcmHintProperty' )
call prop_type_add( 'YcmHintProperty', {
\ 'highlight': 'YcmHintSection',
\ 'priority': 27,
\ 'combine': 0,
\ 'override': 1 } )
endif

if !hlexists( 'YcmErrorPopup' )
highlight default link YcmErrorPopup ErrorMsg
endif
Expand Down
18 changes: 16 additions & 2 deletions doc/youcompleteme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2052,11 +2052,21 @@ in the Vim gutter, the relevant groups are:
- 'YcmWarningSign', which falls back to group 'SyntasticWarningSign' and then
'todo' if they exist

- 'YcmInformationSign', which falls back to group 'SyntasticInformationSign' and then
'added' if they exist

- 'YcmHintSign', which falls back to group 'SyntasticHintSign' and then
'changed' if they exist

You can also style the line that has the warning/error with these groups:

- 'YcmErrorLine', which falls back to group 'SyntasticErrorLine' if it exists
- 'YcmWarningLine', which falls back to group 'SyntasticWarningLine' if it
exists
- 'YcmInformationLine', which falls back to group 'SyntasticInformationLine' if it
exists
- 'YcmHintLine', which falls back to group 'SyntasticHintLine' if it
exists

Finally, you can also style the popup for the detailed diagnostics (it is shown
if |g:ycm_show_detailed_diag_in_popup| is set) using the group 'YcmErrorPopup',
Expand All @@ -2073,6 +2083,10 @@ The syntax groups used to highlight regions of text with errors/warnings: -
'YcmErrorSection', which falls back to group 'SyntasticError' if it exists and
then 'SpellBad' - 'YcmWarningSection', which falls back to group
'SyntasticWarning' if it exists and then 'SpellCap'
- 'YcmInformationSection', which falls back to group
'SyntasticInformation' if it exists and then 'SpellLocal'
- 'YcmHintSection', which falls back to group
'SyntasticHint' if it exists and then 'SpellRare'

Here's how you'd change the style for a group:
>
Expand Down Expand Up @@ -3217,8 +3231,8 @@ Default: '>>'
The *g:ycm_enable_diagnostic_signs* option

When this option is set, YCM will put icons in Vim's gutter on lines that have
a diagnostic set. Turning this off will also turn off the 'YcmErrorLine' and
'YcmWarningLine' highlighting.
a diagnostic set. Turning this off will also turn off the 'YcmErrorLine',
'YcmWarningLine', 'YcmInformationLine' and 'YcmHintLine' highlighting.

This option is part of the Syntastic compatibility layer; if the option is not
set, YCM will fall back to the value of the 'g:syntastic_enable_signs' option
Expand Down
8 changes: 8 additions & 0 deletions plugin/youcompleteme.vim
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ let g:ycm_warning_symbol =
\ get( g:, 'ycm_warning_symbol',
\ get( g:, 'syntastic_warning_symbol', '>>' ) )

let g:ycm_information_symbol =
\ get( g:, 'ycm_information_symbol',
\ get( g:, 'syntastic_information_symbol', '--' ) )

let g:ycm_hint_symbol =
\ get( g:, 'ycm_hint_symbol',
\ get( g:, 'syntastic_hint_symbol', '? ' ) )

let g:ycm_complete_in_comments =
\ get( g:, 'ycm_complete_in_comments', 0 )

Expand Down
2 changes: 1 addition & 1 deletion python/ycm/diagnostic_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def FilterRegex( diagnostic ):


def CompileLevel( level ):
# valid kinds are WARNING and ERROR;
# valid kinds are WARNING, ERROR, INFORMATION and HINT;
# expected input levels are `warning` and `error`
# NOTE: we don't validate the input...
expected_kind = level.upper()
Expand Down
39 changes: 32 additions & 7 deletions python/ycm/diagnostic_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@
tp.ClearTextProperties( self._bufnr,
prop_types = [ 'YcmVirtDiagPadding',
'YcmVirtDiagError',
'YcmVirtDiagWarning' ] )
'YcmVirtDiagWarning'
'YcmVirtDiagInformation',
'YcmVirtDiagHint' ] )
else:
if not will_be_replaced:
vimsupport.PostVimMessage( '', warning = False )
Expand Down Expand Up @@ -175,7 +177,9 @@
' ' * vim.buffers[ self._bufnr ].options[ 'shiftwidth' ] ),
MakeVritualTextProperty(
'YcmVirtDiagError' if _DiagnosticIsError( first_diag )
else 'YcmVirtDiagWarning',
else 'YcmVirtDiagWarning' if _DiagnosticIsWarning( first_diag )
else 'YcmVirtDiagInformation' if _DiagnosticIsInformation( first_diag )
else 'YcmVirtDiagHint',
marker + ' ' + [ line for line in text.splitlines() if line ][ 0 ] )
else:
if not text:
Expand Down Expand Up @@ -259,7 +263,10 @@
# We always go for the first diagnostic on the line because diagnostics
# are sorted by errors in priority and Vim can only display one sign by
# line.
name = 'YcmError' if _DiagnosticIsError( diags[ 0 ] ) else 'YcmWarning'
name = ( 'YcmError' if _DiagnosticIsError( diags[ 0 ] )
else 'YcmWarning' if _DiagnosticIsWarning( diags[ 0 ] )
else 'YcmInformation' if _DiagnosticIsInformation( diags[ 0 ] )
else 'YcmHint' )
sign = {
'lnum': line,
'name': name,
Expand All @@ -286,14 +293,30 @@
self._line_to_diags[ line_number ].append( diag )

for diags in self._line_to_diags.values():
# We also want errors to be listed before warnings so that errors aren't
# hidden by the warnings; Vim won't place a sign over an existing one.
diags.sort( key = lambda diag: ( diag[ 'kind' ],
# We also want sorted by kind priority (e.g. errors than warning etc) so
# that the most important sign is applied first; Vim won't place a sign
# over an existing one.
diags.sort( key = lambda diag: ( _DiagnosticKindSortKey( diag ),
diag[ 'location' ][ 'column_num' ] ) )


def _DiagnosticKindSortKey( diag ):
if _DiagnosticIsError( diag ):
return 1
elif _DiagnosticIsWarning( diag ):
return 2
elif _DiagnosticIsInformation( diag ):
return 3
elif _DiagnosticIsHint( diag ):
return 4

Check warning on line 311 in python/ycm/diagnostic_interface.py

View check run for this annotation

Codecov / codecov/patch

python/ycm/diagnostic_interface.py#L310-L311

Added lines #L310 - L311 were not covered by tests
else:
return 5

Check warning on line 313 in python/ycm/diagnostic_interface.py

View check run for this annotation

Codecov / codecov/patch

python/ycm/diagnostic_interface.py#L313

Added line #L313 was not covered by tests


_DiagnosticIsError = CompileLevel( 'error' )
_DiagnosticIsWarning = CompileLevel( 'warning' )
_DiagnosticIsInformation = CompileLevel( 'information' )
_DiagnosticIsHint = CompileLevel( 'information' )


def _NormalizeDiagnostic( diag ):
Expand All @@ -310,7 +333,9 @@
properties = []

name = ( 'YcmErrorProperty' if _DiagnosticIsError( diagnostic ) else
'YcmWarningProperty' )
'YcmWarningProperty' if _DiagnosticIsWarning( diagnostic ) else
'YcmInformationProperty' if _DiagnosticIsInformation( diagnostic )
else 'YcmHintProperty' )
if vimsupport.VimIsNeovim():
name = name.replace( 'Property', 'Section' )

Expand Down
28 changes: 21 additions & 7 deletions python/ycm/tests/diagnostic_interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
MockVimModule()


def SimpleDiagnosticToJson( start_line, start_col, end_line, end_col ):
def SimpleDiagnosticToJson( start_line, start_col, end_line, end_col,
kind = "ERROR" ):
return {
'kind': 'ERROR',
'kind': kind,
'location': { 'line_num': start_line, 'column_num': start_col },
'location_extent': {
'start': {
Expand Down Expand Up @@ -94,11 +95,12 @@ def SimpleDiagnosticToJsonWithInvalidLineNum( start_line, start_col,
}


def YcmTextPropertyTupleMatcher( start_line, start_col, end_line, end_col ):
def YcmTextPropertyTupleMatcher( start_line, start_col, end_line, end_col,
highlight_group = 'YcmErrorProperty' ):
return has_item( contains_exactly(
start_line,
start_col,
'YcmErrorProperty',
highlight_group,
has_entries( { 'end_col': end_col, 'end_lnum': end_line } ) ) )


Expand All @@ -111,11 +113,23 @@ def test_ConvertDiagnosticToTextProperties( self ):
[ 'Highlight this error please' ],
YcmTextPropertyTupleMatcher( 1, 16, 1, 23 )
],
# Error at the end of the line
# Warning at the end of the line
[
SimpleDiagnosticToJson( 1, 16, 1, 21 ),
SimpleDiagnosticToJson( 1, 16, 1, 21, 'WARNING' ),
[ 'Highlight this warning' ],
YcmTextPropertyTupleMatcher( 1, 16, 1, 21 )
YcmTextPropertyTupleMatcher( 1, 16, 1, 21, 'YcmWarningProperty' )
],
# Info at the start of the line
[
SimpleDiagnosticToJson( 1, 1, 1, 5, 'INFORMATION' ),
[ 'Highlight this information' ],
YcmTextPropertyTupleMatcher( 1, 1, 1, 5, 'YcmInformationProperty' )
],
# Hint at the start of the line
[
SimpleDiagnosticToJson( 1, 5, 1, 5, 'HINT' ),
[ 'Highlight this hint' ],
YcmTextPropertyTupleMatcher( 1, 5, 1, 5, 'YcmHintProperty' )
],
[
SimpleDiagnosticToJson( 1, 16, 1, 19 ),
Expand Down
Loading
Loading