YCM now working on new buffers with ft set

We used to demand a name be set for the buffer.

Fixes #568.
This commit is contained in:
Strahinja Val Markovic 2013-10-06 19:45:47 -07:00
parent 915d092364
commit a9d7105e1b
4 changed files with 22 additions and 5 deletions

View File

@ -87,7 +87,10 @@ function! youcompleteme#Enable()
" is read. This is because youcompleteme#Enable() is called on VimEnter and
" that happens *after" BufRead/BufEnter has already triggered for the
" initial file.
autocmd BufRead,BufEnter * call s:OnBufferVisit()
" We also need to trigger buf init code on the FileType event because when
" the user does :enew and then :set ft=something, we need to run buf init
" code again.
autocmd BufRead,BufEnter,FileType * call s:OnBufferVisit()
autocmd BufUnload * call s:OnBufferUnload( expand( '<afile>:p' ) )
autocmd CursorHold,CursorHoldI * call s:OnCursorHold()
autocmd InsertLeave * call s:OnInsertLeave()

View File

@ -85,13 +85,14 @@ class BaseRequest( object ):
def BuildRequestData( start_column = None, query = None ):
line, column = vimsupport.CurrentLineAndColumn()
filepath = vimsupport.GetCurrentBufferFilepath()
request_data = {
'filetypes': vimsupport.CurrentFiletypes(),
'line_num': line,
'column_num': column,
'start_column': start_column,
'line_value': vim.current.line,
'filepath': vim.current.buffer.name,
'filepath': filepath,
'file_data': vimsupport.GetUnsavedAndCurrentBufferData()
}

View File

@ -69,7 +69,7 @@ def GetUnsavedAndCurrentBufferData():
buffer_object == vim.current.buffer ):
continue
buffers_data[ buffer_object.name ] = {
buffers_data[ GetBufferFilepath( buffer_object ) ] = {
'contents': '\n'.join( buffer_object ),
'filetypes': FiletypesForBuffer( buffer_object )
}
@ -83,6 +83,18 @@ def GetBufferNumberForFilename( filename, open_file_if_needed = True ):
int( open_file_if_needed ) ) ) )
def GetCurrentBufferFilepath():
return GetBufferFilepath( vim.current.buffer )
def GetBufferFilepath( buffer_object ):
if buffer_object.name:
return buffer_object.name
# Buffers that have just been created by a command like :enew don't have any
# buffer name so we use the buffer number for that.
return os.path.join( os.getcwd(), str( buffer_object.number ) )
# Given a dict like {'a': 1}, loads it into Vim as if you ran 'let g:a = 1'
# When |overwrite| is True, overwrites the existing value in Vim.
def LoadDictIntoVimGlobals( new_globals, overwrite = True ):
@ -111,7 +123,7 @@ def JumpToLocation( filename, line, column ):
# Add an entry to the jumplist
vim.command( "normal! m'" )
if filename != vim.current.buffer.name:
if filename != GetCurrentBufferFilepath():
# We prefix the command with 'keepjumps' so that opening the file is not
# recorded in the jumplist. So when we open the file and move the cursor to
# a location in it, the user can use CTRL-O to jump back to the original

View File

@ -116,7 +116,8 @@ class YouCompleteMe( object ):
def NativeFiletypeCompletionAvailable( self ):
try:
return _NativeFiletypeCompletionAvailableForFile( vim.current.buffer.name )
return _NativeFiletypeCompletionAvailableForFile(
vimsupport.GetCurrentBufferFilepath() )
except:
return False