Skip to content

notify gopls about changes #2171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2019
Merged
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
44 changes: 44 additions & 0 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ function! go#lsp#Definition(fname, line, col, handler)
call call(a:next, l:args)
endfunction

call go#lsp#DidChange(a:fname)

let l:lsp = s:lspfactory.get()
let l:state = s:newHandlerState('definition')
let l:state.handleResult = funcref('s:definitionHandler', [function(a:handler, [], l:state)], l:state)
Expand All @@ -365,13 +367,55 @@ function! go#lsp#TypeDef(fname, line, col, handler)
call call(a:next, l:args)
endfunction

call go#lsp#DidChange(a:fname)

let l:lsp = s:lspfactory.get()
let l:state = s:newHandlerState('type definition')
let l:msg = go#lsp#message#TypeDefinition(fnamemodify(a:fname, ':p'), a:line, a:col)
let l:state.handleResult = funcref('s:typeDefinitionHandler', [function(a:handler, [], l:state)], l:state)
call l:lsp.sendMessage(l:msg, l:state)
endfunction

function! go#lsp#DidOpen(fname)
if get(b:, 'go_lsp_did_open', 0)
return
endif

let l:lsp = s:lspfactory.get()
let l:msg = go#lsp#message#DidOpen(fnamemodify(a:fname, ':p'), join(go#util#GetLines(), "\n") . "\n")
let l:state = s:newHandlerState('')
let l:state.handleResult = funcref('s:noop')
call l:lsp.sendMessage(l:msg, l:state)

let b:go_lsp_did_open = 1
endfunction

function! go#lsp#DidChange(fname)
if get(b:, 'go_lsp_did_open', 0)
return go#lsp#DidOpen(a:fname)
endif

let l:lsp = s:lspfactory.get()
let l:msg = go#lsp#message#DidChange(fnamemodify(a:fname, ':p'), join(go#util#GetLines(), "\n") . "\n")
let l:state = s:newHandlerState('')
let l:state.handleResult = funcref('s:noop')
call l:lsp.sendMessage(l:msg, l:state)
endfunction

function! go#lsp#DidClose(fname)
if !get(b:, 'go_lsp_did_open', 0)
return
endif

let l:lsp = s:lspfactory.get()
let l:msg = go#lsp#message#DidClose(fnamemodify(a:fname, ':p'))
let l:state = s:newHandlerState('')
let l:state.handleResult = funcref('s:noop')
call l:lsp.sendMessage(l:msg, l:state)

let b:go_lsp_did_open = 0
endfunction

" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
Expand Down
43 changes: 43 additions & 0 deletions autoload/go/lsp/message.vim
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,49 @@ function! go#lsp#message#TypeDefinition(file, line, col)
\ }
endfunction

function! go#lsp#message#DidOpen(file, content)
return {
\ 'notification': 1,
\ 'method': 'textDocument/didOpen',
\ 'params': {
\ 'textDocument': {
\ 'uri': go#path#ToURI(a:file),
\ 'languageId': 'go',
\ 'text': a:content,
\ }
\ }
\ }
endfunction

function! go#lsp#message#DidChange(file, content)
return {
\ 'notification': 1,
\ 'method': 'textDocument/didChange',
\ 'params': {
\ 'textDocument': {
\ 'uri': go#path#ToURI(a:file),
\ },
\ 'contentChanges': [
\ {
\ 'text': a:content,
\ }
\ ]
\ }
\ }
endfunction

function! go#lsp#message#DidClose(file)
return {
\ 'notification': 1,
\ 'method': 'textDocument/didClose',
\ 'params': {
\ 'textDocument': {
\ 'uri': go#path#ToURI(a:file),
\ }
\ }
\ }
endfunction

function! s:position(line, col)
return {'line': a:line - 1, 'character': a:col-1}
endfunction
Expand Down