Skip to content

Commit

Permalink
Handle events.
Browse files Browse the repository at this point in the history
  • Loading branch information
Junfeng Li committed Oct 25, 2017
1 parent ddb2c97 commit 18b8b6a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
38 changes: 33 additions & 5 deletions plugin/LanguageClient.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ function! LanguageClient_initialize()
return s:lc.call('initialize')
endfunction

" handle_BufReadPost
function! HandleBufReadPost()
return s:lc.notify('handle_BufWritePost', {
\ 'languageId': &filetype,
\ 'filename': expand('%:p'),
\ })
endfunction

autocmd BufReadPost * call HandleBufReadPost()

function! LanguageClient_textDocument_didOpen()
return s:lc.call('textDocument_didOpen')
Expand Down Expand Up @@ -73,14 +80,28 @@ function! LanguageClient_rustDocument_implementations()
return s:lc.call('rustDocument_implementations')
endfunction

" handle_TextChanged
" handle_TextChangedI
function! HandleTextChanged()
return s:lc.notify('handle_TextChanged', {
\ 'filename': expand('%:p'),
\ 'buftype': &buftype,
\ })
endfunction

autocmd TextChanged * call HandleTextChanged()
autocmd TextChangedI * call HandleTextChanged()

function! LanguageClient_textDocument_didChange()
return s:lc.call('textDocument_didChange')
endfunction

" handle_BufWritePost
function! HandleBufWritePost()
return s:lc.notify('handle_BufWritePost', {
\ 'languageId': &filetype,
\ 'filename': expand('%:p'),
\ })
endfunction

autocmd BufWritePost * call HandleBufWritePost()

function! LanguageClient_textDocument_didSave()
return s:lc.call('textDocument_didSave')
Expand All @@ -102,7 +123,14 @@ function! LanguageClient_exit()
return s:lc.call('exit')
endfunction

" handle_CursorMoved
function! HandleCursorMoved()
return s:lc.notify('handle_CursorMoved', {
\ 'buftype': &buftype,
\ 'line': line('.'),
\ })
endfunction

autocmd CursorMoved * call HandleCursorMoved()

function! LanguageClient_completionItem_resolve()
return s:lc.call('completionItem_resolve')
Expand Down
29 changes: 15 additions & 14 deletions rplugin/python3/LanguageClient/LanguageClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ def registerCMSource(self, languageId: str, result: Dict) -> None:
repr(ex))

@neovim.autocmd("BufReadPost", pattern="*",
eval="{'languageId': &filetype, 'filename': expand('%:p')}")
def handle_BufReadPost(self, kwargs):
eval="[{'languageId': &filetype, 'filename': expand('%:p')}]")
def handle_BufReadPost(self, args: List) -> None:
logger.info("Begin handleBufReadPost")

languageId, uri = gather_args(["languageId", "uri"], kwargs=kwargs)
languageId, uri = gather_args(["languageId", "uri"], args=args)
if not uri:
return
# Language server is running but file is not within rootUri.
Expand Down Expand Up @@ -903,9 +903,9 @@ def fzfSinkTextDocumentReferences(self, args: List) -> None:
execute_command(cmd)

@neovim.autocmd("TextChanged", pattern="*",
eval="{'filename': expand('%:p'), 'buftype': &buftype}")
def handle_TextChanged(self, kwargs) -> None:
uri, buftype = gather_args(["uri", "buftype"], kwargs=kwargs)
eval="[{'filename': expand('%:p'), 'buftype': &buftype}]")
def handle_TextChanged(self, args: List) -> None:
uri, buftype = gather_args(["uri", "buftype"], args=args)
if buftype != "" or state.get(uri, {}).get("textDocument") is None:
return
text_doc = state[uri]["textDocument"]
Expand All @@ -914,9 +914,9 @@ def handle_TextChanged(self, kwargs) -> None:
self.textDocument_didChange()

@neovim.autocmd("TextChangedI", pattern="*",
eval="{'filename': expand('%:p'), 'buftype': &buftype}")
def handle_TextChangedI(self, kwargs):
self.handle_TextChanged(kwargs)
eval="[{'filename': expand('%:p'), 'buftype': &buftype}]")
def handle_TextChangedI(self, args: List) -> None:
self.handle_TextChanged(args)

@neovim.function("textDocument_didChange")
@deco_args(warn=False)
Expand Down Expand Up @@ -946,9 +946,9 @@ def textDocument_didChange(self, uri: str, languageId: str) -> None:
doc.commit_change()

@neovim.autocmd("BufWritePost", pattern="*",
eval="{'languageId': &filetype, 'filename': expand('%:p')}")
def handle_BufWritePost(self, kwargs):
uri, languageId = gather_args(["uri", "languageId"], kwargs=kwargs)
eval="[{'languageId': &filetype, 'filename': expand('%:p')}]")
def handle_BufWritePost(self, args: List) -> None:
uri, languageId = gather_args(["uri", "languageId"], args=args)
self.textDocument_didSave()

@neovim.function("textDocument_didSave")
Expand Down Expand Up @@ -1098,9 +1098,10 @@ def textDocument_publishDiagnostics(self, diagnostics_params: Dict) -> None:
line, columns = gather_args(["line", "columns"])
show_line_diagnostic(uri, line, columns)

@neovim.autocmd("CursorMoved", pattern="*", eval="[&buftype, line('.')]")
@neovim.autocmd("CursorMoved", pattern="*",
eval="[{'buftype': &buftype, 'line': line('.')}]")
def handle_CursorMoved(self, args: List) -> None:
buftype, line = args
buftype, line = gather_args(["buftype", "line"], args=args)
# Regular file buftype is "".
if buftype != "" or line == state["last_cursor_line"]:
return
Expand Down

0 comments on commit 18b8b6a

Please sign in to comment.