mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-05 01:17:46 +08:00
#517 Add more code LSP support which makes the tssserver linter behave more like the LSP linters
This commit is contained in:
@@ -3,12 +3,32 @@
|
||||
"
|
||||
" Messages in this movie will be returned in the format
|
||||
" [is_notification, method_name, params?]
|
||||
let g:ale_lsp_next_version_id = 1
|
||||
|
||||
function! ale#lsp#message#Initialize(root_uri) abort
|
||||
" The LSP protocols demands that we send every change to a document, including
|
||||
" undo, with incrementing version numbers, so we'll just use one incrementing
|
||||
" ID for everything.
|
||||
function! ale#lsp#message#GetNextVersionID() abort
|
||||
" Use the current ID
|
||||
let l:id = g:ale_lsp_next_version_id
|
||||
|
||||
" Increment the ID variable.
|
||||
let g:ale_lsp_next_version_id += 1
|
||||
|
||||
" When the ID overflows, reset it to 1. By the time we hit the initial ID
|
||||
" again, the messages will be long gone.
|
||||
if g:ale_lsp_next_version_id < 1
|
||||
let g:ale_lsp_next_version_id = 1
|
||||
endif
|
||||
|
||||
return l:id
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#Initialize(root_path) abort
|
||||
" TODO: Define needed capabilities.
|
||||
return [0, 'initialize', {
|
||||
\ 'processId': getpid(),
|
||||
\ 'rootUri': a:root_uri,
|
||||
\ 'rootPath': a:root_path,
|
||||
\ 'capabilities': {},
|
||||
\}]
|
||||
endfunction
|
||||
@@ -25,40 +45,44 @@ function! ale#lsp#message#Exit() abort
|
||||
return [1, 'exit']
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidOpen(uri, language_id, version, text) abort
|
||||
function! ale#lsp#message#DidOpen(buffer, language_id) abort
|
||||
let l:lines = getbufline(a:buffer, 1, '$')
|
||||
|
||||
return [1, 'textDocument/didOpen', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': a:uri,
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ 'languageId': a:language_id,
|
||||
\ 'version': a:version,
|
||||
\ 'text': a:text,
|
||||
\ 'version': ale#lsp#message#GetNextVersionID(),
|
||||
\ 'text': join(l:lines, "\n"),
|
||||
\ },
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidChange(uri, version, text) abort
|
||||
function! ale#lsp#message#DidChange(buffer) abort
|
||||
let l:lines = getbufline(a:buffer, 1, '$')
|
||||
|
||||
" For changes, we simply send the full text of the document to the server.
|
||||
return [1, 'textDocument/didChange', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': a:uri,
|
||||
\ 'version': a:version,
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ 'version': ale#lsp#message#GetNextVersionID(),
|
||||
\ },
|
||||
\ 'contentChanges': [{'text': a:text}]
|
||||
\ 'contentChanges': [{'text': join(l:lines, "\n")}]
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidSave(uri) abort
|
||||
function! ale#lsp#message#DidSave(buffer) abort
|
||||
return [1, 'textDocument/didSave', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': a:uri,
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidClose(uri) abort
|
||||
function! ale#lsp#message#DidClose(buffer) abort
|
||||
return [1, 'textDocument/didClose', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': a:uri,
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user