Echoing diag text on when cursor on diag line
This commit is contained in:
parent
6c01881e1a
commit
c9e9a640ac
@ -365,6 +365,7 @@ function! s:OnCursorMovedInsertMode()
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
py ycm_state.OnCursorMoved()
|
||||||
call s:UpdateCursorMoved()
|
call s:UpdateCursorMoved()
|
||||||
|
|
||||||
" Basically, we need to only trigger the completion menu when the user has
|
" Basically, we need to only trigger the completion menu when the user has
|
||||||
@ -402,6 +403,7 @@ function! s:OnCursorMovedNormalMode()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
call s:OnFileReadyToParse()
|
call s:OnFileReadyToParse()
|
||||||
|
py ycm_state.OnCursorMoved()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,36 +20,66 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from ycm import vimsupport
|
from ycm import vimsupport
|
||||||
|
import vim
|
||||||
|
|
||||||
|
|
||||||
class DiagnosticInterface( object ):
|
class DiagnosticInterface( object ):
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
self._buffer_number_to_diags = {}
|
# Line and column numbers are 1-based
|
||||||
|
self._buffer_number_to_line_to_diags = defaultdict(
|
||||||
|
lambda: defaultdict( list ) )
|
||||||
self._next_sign_id = 1
|
self._next_sign_id = 1
|
||||||
|
self._previous_line_number = -1
|
||||||
|
|
||||||
|
|
||||||
|
def OnCursorMoved( self ):
|
||||||
|
line, _ = vimsupport.CurrentLineAndColumn()
|
||||||
|
line += 1 # Convert to 1-based
|
||||||
|
if line != self._previous_line_number:
|
||||||
|
self._previous_line_number = line
|
||||||
|
self._EchoDiagnosticForLine( line )
|
||||||
|
|
||||||
|
|
||||||
def UpdateWithNewDiagnostics( self, diags ):
|
def UpdateWithNewDiagnostics( self, diags ):
|
||||||
self._buffer_number_to_diags = ConvertDiagListToDict( diags )
|
self._buffer_number_to_line_to_diags = _ConvertDiagListToDict( diags )
|
||||||
for buffer_number, buffer_diags in self._buffer_number_to_diags.iteritems():
|
self._next_sign_id = _UpdateSigns( self._buffer_number_to_line_to_diags,
|
||||||
|
self._next_sign_id )
|
||||||
|
|
||||||
|
|
||||||
|
def _EchoDiagnosticForLine( self, line_num ):
|
||||||
|
buffer_num = vim.current.buffer.number
|
||||||
|
diags = self._buffer_number_to_line_to_diags[ buffer_num ][ line_num ]
|
||||||
|
if not diags:
|
||||||
|
# Clear any previous diag echo
|
||||||
|
vimsupport.EchoText( '', False )
|
||||||
|
return
|
||||||
|
vimsupport.EchoTextVimWidth( diags[ 0 ][ 'text' ] )
|
||||||
|
|
||||||
|
|
||||||
|
def _UpdateSigns( buffer_number_to_line_to_diags, next_sign_id ):
|
||||||
|
for buffer_number, line_to_diags in buffer_number_to_line_to_diags.iteritems():
|
||||||
if not vimsupport.BufferIsVisible( buffer_number ):
|
if not vimsupport.BufferIsVisible( buffer_number ):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
vimsupport.UnplaceAllSignsInBuffer( buffer_number )
|
vimsupport.UnplaceAllSignsInBuffer( buffer_number )
|
||||||
for diag in buffer_diags:
|
for line, diags in line_to_diags.iteritems():
|
||||||
vimsupport.PlaceSign( self._next_sign_id,
|
for diag in diags:
|
||||||
diag[ 'lnum' ],
|
vimsupport.PlaceSign( next_sign_id,
|
||||||
|
line,
|
||||||
buffer_number,
|
buffer_number,
|
||||||
diag[ 'type' ] == 'E' )
|
diag[ 'type' ] == 'E' )
|
||||||
self._next_sign_id += 1
|
next_sign_id += 1
|
||||||
|
return next_sign_id
|
||||||
|
|
||||||
|
|
||||||
def ConvertDiagListToDict( diags ):
|
def _ConvertDiagListToDict( diag_list ):
|
||||||
buffer_to_diags = defaultdict( list )
|
buffer_to_line_to_diags = defaultdict( lambda: defaultdict( list ) )
|
||||||
for diag in diags:
|
for diag in diag_list:
|
||||||
buffer_to_diags[ diag[ 'bufnr' ] ].append( diag )
|
buffer_to_line_to_diags[ diag[ 'bufnr' ] ][ diag[ 'lnum' ] ].append( diag )
|
||||||
for buffer_diags in buffer_to_diags.itervalues():
|
for line_to_diags in buffer_to_line_to_diags.itervalues():
|
||||||
|
for diags in line_to_diags.itervalues():
|
||||||
# We also want errors to be listed before warnings so that errors aren't
|
# We also want errors to be listed before warnings so that errors aren't
|
||||||
# hidden by the warnings; Vim won't place a sign oven an existing one.
|
# hidden by the warnings; Vim won't place a sign oven an existing one.
|
||||||
buffer_diags.sort( key = lambda diag: itemgetter( 'lnum', 'col', 'type' ) )
|
diags.sort( key = lambda diag: itemgetter( 'col', 'type' ) )
|
||||||
return buffer_to_diags
|
return buffer_to_line_to_diags
|
||||||
|
|
||||||
|
@ -220,14 +220,23 @@ def Confirm( message ):
|
|||||||
return bool( PresentDialog( message, [ "Ok", "Cancel" ] ) == 0 )
|
return bool( PresentDialog( message, [ "Ok", "Cancel" ] ) == 0 )
|
||||||
|
|
||||||
|
|
||||||
def EchoText( text ):
|
def EchoText( text, log_as_message = True ):
|
||||||
def EchoLine( text ):
|
def EchoLine( text ):
|
||||||
vim.command( "echom '{0}'".format( EscapeForVim( text ) ) )
|
command = 'echom' if log_as_message else 'echo'
|
||||||
|
vim.command( "{0} '{1}'".format( command, EscapeForVim( text ) ) )
|
||||||
|
|
||||||
for line in text.split( '\n' ):
|
for line in text.split( '\n' ):
|
||||||
EchoLine( line )
|
EchoLine( line )
|
||||||
|
|
||||||
|
|
||||||
|
# Echos text but truncates the text so that it all fits on one line
|
||||||
|
def EchoTextVimWidth( text ):
|
||||||
|
vim_width = GetIntValue( '&columns' )
|
||||||
|
truncated_text = text[ : int( vim_width * 0.9 ) ]
|
||||||
|
truncated_text.replace( '\n', ' ' )
|
||||||
|
EchoText( truncated_text, False )
|
||||||
|
|
||||||
|
|
||||||
def EscapeForVim( text ):
|
def EscapeForVim( text ):
|
||||||
return text.replace( "'", "''" )
|
return text.replace( "'", "''" )
|
||||||
|
|
||||||
|
@ -246,6 +246,10 @@ class YouCompleteMe( object ):
|
|||||||
SendEventNotificationAsync( 'InsertLeave' )
|
SendEventNotificationAsync( 'InsertLeave' )
|
||||||
|
|
||||||
|
|
||||||
|
def OnCursorMoved( self ):
|
||||||
|
self._diag_interface.OnCursorMoved()
|
||||||
|
|
||||||
|
|
||||||
def OnVimLeave( self ):
|
def OnVimLeave( self ):
|
||||||
self._ServerCleanup()
|
self._ServerCleanup()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user