Stop creating closure function in global scope by using partials instead
This commit is contained in:
parent
5323f000aa
commit
9cdd8b67b2
@ -424,6 +424,59 @@ function! ale#completion#HandleLSPResponse(conn_id, response) abort
|
|||||||
\)
|
\)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:OnReady(linter, lsp_details, ...) abort
|
||||||
|
let l:buffer = a:lsp_details.buffer
|
||||||
|
let l:id = a:lsp_details.connection_id
|
||||||
|
let l:root = a:lsp_details.project_root
|
||||||
|
|
||||||
|
" If we have sent a completion request already, don't send another.
|
||||||
|
if b:ale_completion_info.request_id
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:Callback = a:linter.lsp is# 'tsserver'
|
||||||
|
\ ? function('ale#completion#HandleTSServerResponse')
|
||||||
|
\ : function('ale#completion#HandleLSPResponse')
|
||||||
|
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
||||||
|
|
||||||
|
if a:linter.lsp is# 'tsserver'
|
||||||
|
let l:message = ale#lsp#tsserver_message#Completions(
|
||||||
|
\ l:buffer,
|
||||||
|
\ b:ale_completion_info.line,
|
||||||
|
\ b:ale_completion_info.column,
|
||||||
|
\ b:ale_completion_info.prefix,
|
||||||
|
\)
|
||||||
|
else
|
||||||
|
" Send a message saying the buffer has changed first, otherwise
|
||||||
|
" completions won't know what text is nearby.
|
||||||
|
call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
|
||||||
|
|
||||||
|
" For LSP completions, we need to clamp the column to the length of
|
||||||
|
" the line. python-language-server and perhaps others do not implement
|
||||||
|
" this correctly.
|
||||||
|
let l:message = ale#lsp#message#Completion(
|
||||||
|
\ l:buffer,
|
||||||
|
\ b:ale_completion_info.line,
|
||||||
|
\ min([
|
||||||
|
\ b:ale_completion_info.line_length,
|
||||||
|
\ b:ale_completion_info.column,
|
||||||
|
\ ]),
|
||||||
|
\ ale#completion#GetTriggerCharacter(&filetype, b:ale_completion_info.prefix),
|
||||||
|
\)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:request_id = ale#lsp#Send(l:id, l:message, l:root)
|
||||||
|
|
||||||
|
if l:request_id
|
||||||
|
let b:ale_completion_info.conn_id = l:id
|
||||||
|
let b:ale_completion_info.request_id = l:request_id
|
||||||
|
|
||||||
|
if has_key(a:linter, 'completion_filter')
|
||||||
|
let b:ale_completion_info.completion_filter = a:linter.completion_filter
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:GetLSPCompletions(linter) abort
|
function! s:GetLSPCompletions(linter) abort
|
||||||
let l:buffer = bufnr('')
|
let l:buffer = bufnr('')
|
||||||
let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter)
|
let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter)
|
||||||
@ -435,56 +488,9 @@ function! s:GetLSPCompletions(linter) abort
|
|||||||
let l:id = l:lsp_details.connection_id
|
let l:id = l:lsp_details.connection_id
|
||||||
let l:root = l:lsp_details.project_root
|
let l:root = l:lsp_details.project_root
|
||||||
|
|
||||||
function! OnReady(...) abort closure
|
let l:OnReady = function('s:OnReady', [a:linter, l:lsp_details])
|
||||||
" If we have sent a completion request already, don't send another.
|
|
||||||
if b:ale_completion_info.request_id
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:Callback = a:linter.lsp is# 'tsserver'
|
call ale#lsp#WaitForCapability(l:id, l:root, 'completion', l:OnReady)
|
||||||
\ ? function('ale#completion#HandleTSServerResponse')
|
|
||||||
\ : function('ale#completion#HandleLSPResponse')
|
|
||||||
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
|
||||||
|
|
||||||
if a:linter.lsp is# 'tsserver'
|
|
||||||
let l:message = ale#lsp#tsserver_message#Completions(
|
|
||||||
\ l:buffer,
|
|
||||||
\ b:ale_completion_info.line,
|
|
||||||
\ b:ale_completion_info.column,
|
|
||||||
\ b:ale_completion_info.prefix,
|
|
||||||
\)
|
|
||||||
else
|
|
||||||
" Send a message saying the buffer has changed first, otherwise
|
|
||||||
" completions won't know what text is nearby.
|
|
||||||
call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
|
|
||||||
|
|
||||||
" For LSP completions, we need to clamp the column to the length of
|
|
||||||
" the line. python-language-server and perhaps others do not implement
|
|
||||||
" this correctly.
|
|
||||||
let l:message = ale#lsp#message#Completion(
|
|
||||||
\ l:buffer,
|
|
||||||
\ b:ale_completion_info.line,
|
|
||||||
\ min([
|
|
||||||
\ b:ale_completion_info.line_length,
|
|
||||||
\ b:ale_completion_info.column,
|
|
||||||
\ ]),
|
|
||||||
\ ale#completion#GetTriggerCharacter(&filetype, b:ale_completion_info.prefix),
|
|
||||||
\)
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root)
|
|
||||||
|
|
||||||
if l:request_id
|
|
||||||
let b:ale_completion_info.conn_id = l:id
|
|
||||||
let b:ale_completion_info.request_id = l:request_id
|
|
||||||
|
|
||||||
if has_key(a:linter, 'completion_filter')
|
|
||||||
let b:ale_completion_info.completion_filter = a:linter.completion_filter
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
call ale#lsp#WaitForCapability(l:id, l:root, 'completion', function('OnReady'))
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#completion#GetCompletions() abort
|
function! ale#completion#GetCompletions() abort
|
||||||
|
@ -57,6 +57,40 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:OnReady(linter, lsp_details, line, column, options, ...) abort
|
||||||
|
let l:buffer = a:lsp_details.buffer
|
||||||
|
let l:id = a:lsp_details.connection_id
|
||||||
|
let l:root = a:lsp_details.project_root
|
||||||
|
|
||||||
|
let l:Callback = a:linter.lsp is# 'tsserver'
|
||||||
|
\ ? function('ale#definition#HandleTSServerResponse')
|
||||||
|
\ : function('ale#definition#HandleLSPResponse')
|
||||||
|
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
||||||
|
|
||||||
|
if a:linter.lsp is# 'tsserver'
|
||||||
|
let l:message = ale#lsp#tsserver_message#Definition(
|
||||||
|
\ l:buffer,
|
||||||
|
\ a:line,
|
||||||
|
\ a:column
|
||||||
|
\)
|
||||||
|
else
|
||||||
|
" Send a message saying the buffer has changed first, or the
|
||||||
|
" definition position probably won't make sense.
|
||||||
|
call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
|
||||||
|
|
||||||
|
" For LSP completions, we need to clamp the column to the length of
|
||||||
|
" the line. python-language-server and perhaps others do not implement
|
||||||
|
" this correctly.
|
||||||
|
let l:message = ale#lsp#message#Definition(l:buffer, a:line, a:column)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:request_id = ale#lsp#Send(l:id, l:message, l:root)
|
||||||
|
|
||||||
|
let s:go_to_definition_map[l:request_id] = {
|
||||||
|
\ 'open_in_tab': get(a:options, 'open_in_tab', 0),
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:GoToLSPDefinition(linter, options) abort
|
function! s:GoToLSPDefinition(linter, options) abort
|
||||||
let l:buffer = bufnr('')
|
let l:buffer = bufnr('')
|
||||||
let [l:line, l:column] = getcurpos()[1:2]
|
let [l:line, l:column] = getcurpos()[1:2]
|
||||||
@ -73,37 +107,11 @@ function! s:GoToLSPDefinition(linter, options) abort
|
|||||||
let l:id = l:lsp_details.connection_id
|
let l:id = l:lsp_details.connection_id
|
||||||
let l:root = l:lsp_details.project_root
|
let l:root = l:lsp_details.project_root
|
||||||
|
|
||||||
function! OnReady(...) abort closure
|
let l:OnReady = function('s:OnReady', [
|
||||||
let l:Callback = a:linter.lsp is# 'tsserver'
|
\ a:linter, l:lsp_details, l:line, l:column, a:options
|
||||||
\ ? function('ale#definition#HandleTSServerResponse')
|
\])
|
||||||
\ : function('ale#definition#HandleLSPResponse')
|
|
||||||
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
|
||||||
|
|
||||||
if a:linter.lsp is# 'tsserver'
|
call ale#lsp#WaitForCapability(l:id, l:root, 'definition', l:OnReady)
|
||||||
let l:message = ale#lsp#tsserver_message#Definition(
|
|
||||||
\ l:buffer,
|
|
||||||
\ l:line,
|
|
||||||
\ l:column
|
|
||||||
\)
|
|
||||||
else
|
|
||||||
" Send a message saying the buffer has changed first, or the
|
|
||||||
" definition position probably won't make sense.
|
|
||||||
call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
|
|
||||||
|
|
||||||
" For LSP completions, we need to clamp the column to the length of
|
|
||||||
" the line. python-language-server and perhaps others do not implement
|
|
||||||
" this correctly.
|
|
||||||
let l:message = ale#lsp#message#Definition(l:buffer, l:line, l:column)
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root)
|
|
||||||
|
|
||||||
let s:go_to_definition_map[l:request_id] = {
|
|
||||||
\ 'open_in_tab': get(a:options, 'open_in_tab', 0),
|
|
||||||
\}
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
call ale#lsp#WaitForCapability(l:id, l:root, 'definition', function('OnReady'))
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#definition#GoTo(options) abort
|
function! ale#definition#GoTo(options) abort
|
||||||
|
@ -92,7 +92,45 @@ function! ale#hover#HandleLSPResponse(conn_id, response) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ShowDetails(linter, buffer, line, column, opt) abort
|
function! s:OnReady(linter, lsp_details, line, column, opt, ...) abort
|
||||||
|
let l:buffer = a:lsp_details.buffer
|
||||||
|
let l:id = a:lsp_details.connection_id
|
||||||
|
let l:root = a:lsp_details.project_root
|
||||||
|
|
||||||
|
let l:Callback = a:linter.lsp is# 'tsserver'
|
||||||
|
\ ? function('ale#hover#HandleTSServerResponse')
|
||||||
|
\ : function('ale#hover#HandleLSPResponse')
|
||||||
|
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
||||||
|
|
||||||
|
if a:linter.lsp is# 'tsserver'
|
||||||
|
let l:column = a:column
|
||||||
|
|
||||||
|
let l:message = ale#lsp#tsserver_message#Quickinfo(
|
||||||
|
\ l:buffer,
|
||||||
|
\ a:line,
|
||||||
|
\ l:column
|
||||||
|
\)
|
||||||
|
else
|
||||||
|
" Send a message saying the buffer has changed first, or the
|
||||||
|
" hover position probably won't make sense.
|
||||||
|
call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
|
||||||
|
|
||||||
|
let l:column = min([a:column, len(getbufline(l:buffer, a:line)[0])])
|
||||||
|
|
||||||
|
let l:message = ale#lsp#message#Hover(l:buffer, a:line, l:column)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:request_id = ale#lsp#Send(l:id, l:message, l:root)
|
||||||
|
|
||||||
|
let s:hover_map[l:request_id] = {
|
||||||
|
\ 'buffer': l:buffer,
|
||||||
|
\ 'line': a:line,
|
||||||
|
\ 'column': l:column,
|
||||||
|
\ 'hover_from_balloonexpr': get(a:opt, 'called_from_balloonexpr', 0),
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:ShowDetails(linter, buffer, line, column, opt, ...) abort
|
||||||
let l:lsp_details = ale#lsp_linter#StartLSP(a:buffer, a:linter)
|
let l:lsp_details = ale#lsp_linter#StartLSP(a:buffer, a:linter)
|
||||||
|
|
||||||
if empty(l:lsp_details)
|
if empty(l:lsp_details)
|
||||||
@ -101,43 +139,12 @@ function! s:ShowDetails(linter, buffer, line, column, opt) abort
|
|||||||
|
|
||||||
let l:id = l:lsp_details.connection_id
|
let l:id = l:lsp_details.connection_id
|
||||||
let l:root = l:lsp_details.project_root
|
let l:root = l:lsp_details.project_root
|
||||||
let l:language_id = l:lsp_details.language_id
|
|
||||||
|
|
||||||
function! OnReady(...) abort closure
|
let l:OnReady = function('s:OnReady', [
|
||||||
let l:Callback = a:linter.lsp is# 'tsserver'
|
\ a:linter, l:lsp_details, a:line, a:column, a:opt
|
||||||
\ ? function('ale#hover#HandleTSServerResponse')
|
\])
|
||||||
\ : function('ale#hover#HandleLSPResponse')
|
|
||||||
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
|
||||||
|
|
||||||
if a:linter.lsp is# 'tsserver'
|
call ale#lsp#WaitForCapability(l:id, l:root, 'hover', l:OnReady)
|
||||||
let l:column = a:column
|
|
||||||
|
|
||||||
let l:message = ale#lsp#tsserver_message#Quickinfo(
|
|
||||||
\ a:buffer,
|
|
||||||
\ a:line,
|
|
||||||
\ l:column
|
|
||||||
\)
|
|
||||||
else
|
|
||||||
" Send a message saying the buffer has changed first, or the
|
|
||||||
" hover position probably won't make sense.
|
|
||||||
call ale#lsp#NotifyForChanges(l:id, l:root, a:buffer)
|
|
||||||
|
|
||||||
let l:column = min([a:column, len(getbufline(a:buffer, a:line)[0])])
|
|
||||||
|
|
||||||
let l:message = ale#lsp#message#Hover(a:buffer, a:line, l:column)
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root)
|
|
||||||
|
|
||||||
let s:hover_map[l:request_id] = {
|
|
||||||
\ 'buffer': a:buffer,
|
|
||||||
\ 'line': a:line,
|
|
||||||
\ 'column': l:column,
|
|
||||||
\ 'hover_from_balloonexpr': get(a:opt, 'called_from_balloonexpr', 0),
|
|
||||||
\}
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
call ale#lsp#WaitForCapability(l:id, l:root, 'hover', function('OnReady'))
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Obtain Hover information for the specified position
|
" Obtain Hover information for the specified position
|
||||||
|
@ -64,6 +64,36 @@ function! ale#references#HandleLSPResponse(conn_id, response) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:OnReady(linter, lsp_details, line, column, ...) abort
|
||||||
|
let l:buffer = a:lsp_details.buffer
|
||||||
|
let l:id = a:lsp_details.connection_id
|
||||||
|
let l:root = a:lsp_details.project_root
|
||||||
|
|
||||||
|
let l:Callback = a:linter.lsp is# 'tsserver'
|
||||||
|
\ ? function('ale#references#HandleTSServerResponse')
|
||||||
|
\ : function('ale#references#HandleLSPResponse')
|
||||||
|
|
||||||
|
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
||||||
|
|
||||||
|
if a:linter.lsp is# 'tsserver'
|
||||||
|
let l:message = ale#lsp#tsserver_message#References(
|
||||||
|
\ l:buffer,
|
||||||
|
\ a:line,
|
||||||
|
\ a:column
|
||||||
|
\)
|
||||||
|
else
|
||||||
|
" Send a message saying the buffer has changed first, or the
|
||||||
|
" references position probably won't make sense.
|
||||||
|
call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
|
||||||
|
|
||||||
|
let l:message = ale#lsp#message#References(l:buffer, a:line, a:column)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:request_id = ale#lsp#Send(l:id, l:message, a:lsp_details.project_root)
|
||||||
|
|
||||||
|
let s:references_map[l:request_id] = {}
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:FindReferences(linter) abort
|
function! s:FindReferences(linter) abort
|
||||||
let l:buffer = bufnr('')
|
let l:buffer = bufnr('')
|
||||||
let [l:line, l:column] = getcurpos()[1:2]
|
let [l:line, l:column] = getcurpos()[1:2]
|
||||||
@ -81,33 +111,11 @@ function! s:FindReferences(linter) abort
|
|||||||
let l:id = l:lsp_details.connection_id
|
let l:id = l:lsp_details.connection_id
|
||||||
let l:root = l:lsp_details.project_root
|
let l:root = l:lsp_details.project_root
|
||||||
|
|
||||||
function! OnReady(...) abort closure
|
let l:OnReady = function('s:OnReady', [
|
||||||
let l:Callback = a:linter.lsp is# 'tsserver'
|
\ a:linter, l:lsp_details, l:line, l:column
|
||||||
\ ? function('ale#references#HandleTSServerResponse')
|
\])
|
||||||
\ : function('ale#references#HandleLSPResponse')
|
|
||||||
|
|
||||||
call ale#lsp#RegisterCallback(l:id, l:Callback)
|
call ale#lsp#WaitForCapability(l:id, l:root, 'references', l:OnReady)
|
||||||
|
|
||||||
if a:linter.lsp is# 'tsserver'
|
|
||||||
let l:message = ale#lsp#tsserver_message#References(
|
|
||||||
\ l:buffer,
|
|
||||||
\ l:line,
|
|
||||||
\ l:column
|
|
||||||
\)
|
|
||||||
else
|
|
||||||
" Send a message saying the buffer has changed first, or the
|
|
||||||
" references position probably won't make sense.
|
|
||||||
call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer)
|
|
||||||
|
|
||||||
let l:message = ale#lsp#message#References(l:buffer, l:line, l:column)
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root)
|
|
||||||
|
|
||||||
let s:references_map[l:request_id] = {}
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
call ale#lsp#WaitForCapability(l:id, l:root, 'references', function('OnReady'))
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#references#Find() abort
|
function! ale#references#Find() abort
|
||||||
|
Loading…
Reference in New Issue
Block a user