mirror of
https://github.com/dense-analysis/ale.git
synced 2026-05-11 09:08:32 +08:00
Use one LSP connection per project
This commit is contained in:
+11
-16
@@ -143,7 +143,8 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
||||
|
||||
if a:linter.lsp is# 'socket'
|
||||
let l:address = ale#linter#GetAddress(a:buffer, a:linter)
|
||||
let l:conn_id = ale#lsp#ConnectToAddress(l:address, l:init_options)
|
||||
let l:conn_id = ale#lsp#Register(l:address, l:root, l:init_options)
|
||||
let l:ready = ale#lsp#ConnectToAddress(l:conn_id, l:address)
|
||||
else
|
||||
let l:executable = ale#linter#GetExecutable(a:buffer, a:linter)
|
||||
|
||||
@@ -151,18 +152,16 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
||||
return {}
|
||||
endif
|
||||
|
||||
let l:conn_id = ale#lsp#Register(l:executable, l:root, l:init_options)
|
||||
|
||||
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
|
||||
" Format the command, so %e can be formatted into it.
|
||||
let l:command = ale#command#FormatCommand(a:buffer, l:executable, l:command, 0)[1]
|
||||
let l:command = ale#job#PrepareCommand(a:buffer, l:command)
|
||||
let l:conn_id = ale#lsp#StartProgram(
|
||||
\ l:executable,
|
||||
\ l:command,
|
||||
\ l:init_options,
|
||||
\)
|
||||
let l:ready = ale#lsp#StartProgram(l:conn_id, l:executable, l:command)
|
||||
endif
|
||||
|
||||
if empty(l:conn_id)
|
||||
if !l:ready
|
||||
if g:ale_history_enabled && !empty(l:command)
|
||||
call ale#history#Add(a:buffer, 'failed', l:conn_id, l:command)
|
||||
endif
|
||||
@@ -175,9 +174,6 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
||||
call ale#lsp#MarkConnectionAsTsserver(l:conn_id)
|
||||
endif
|
||||
|
||||
" Register the project now the connection is ready.
|
||||
call ale#lsp#RegisterProject(l:conn_id, l:root)
|
||||
|
||||
let l:language_id = ale#util#GetFunction(a:linter.language_callback)(a:buffer)
|
||||
|
||||
let l:details = {
|
||||
@@ -188,7 +184,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
||||
\ 'language_id': l:language_id,
|
||||
\}
|
||||
|
||||
if ale#lsp#OpenDocument(l:conn_id, l:root, a:buffer, l:language_id)
|
||||
if ale#lsp#OpenDocument(l:conn_id, a:buffer, l:language_id)
|
||||
if g:ale_history_enabled && !empty(l:command)
|
||||
call ale#history#Add(a:buffer, 'started', l:conn_id, l:command)
|
||||
endif
|
||||
@@ -196,7 +192,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
||||
|
||||
" The change message needs to be sent for tsserver before doing anything.
|
||||
if a:linter.lsp is# 'tsserver'
|
||||
call ale#lsp#NotifyForChanges(l:conn_id, l:root, a:buffer)
|
||||
call ale#lsp#NotifyForChanges(l:conn_id, a:buffer)
|
||||
endif
|
||||
|
||||
return l:details
|
||||
@@ -211,7 +207,6 @@ function! ale#lsp_linter#CheckWithLSP(buffer, linter) abort
|
||||
endif
|
||||
|
||||
let l:id = l:lsp_details.connection_id
|
||||
let l:root = l:lsp_details.project_root
|
||||
|
||||
" Register a callback now for handling errors now.
|
||||
let l:Callback = function('ale#lsp_linter#HandleLSPResponse')
|
||||
@@ -222,16 +217,16 @@ function! ale#lsp_linter#CheckWithLSP(buffer, linter) abort
|
||||
|
||||
if a:linter.lsp is# 'tsserver'
|
||||
let l:message = ale#lsp#tsserver_message#Geterr(a:buffer)
|
||||
let l:notified = ale#lsp#Send(l:id, l:message, l:root) != 0
|
||||
let l:notified = ale#lsp#Send(l:id, l:message) != 0
|
||||
else
|
||||
let l:notified = ale#lsp#NotifyForChanges(l:id, l:root, a:buffer)
|
||||
let l:notified = ale#lsp#NotifyForChanges(l:id, a:buffer)
|
||||
endif
|
||||
|
||||
" If this was a file save event, also notify the server of that.
|
||||
if a:linter.lsp isnot# 'tsserver'
|
||||
\&& getbufvar(a:buffer, 'ale_save_event_fired', 0)
|
||||
let l:save_message = ale#lsp#message#DidSave(a:buffer)
|
||||
let l:notified = ale#lsp#Send(l:id, l:save_message, l:root) != 0
|
||||
let l:notified = ale#lsp#Send(l:id, l:save_message) != 0
|
||||
endif
|
||||
|
||||
if l:notified
|
||||
|
||||
Reference in New Issue
Block a user