mirror of
https://github.com/amix/vimrc
synced 2025-08-07 06:05:00 +08:00
Removed syntastic and replaced it with ale
Read more here: https://github.com/w0rp/ale
This commit is contained in:
118
sources_non_forked/ale/autoload/ale/lsp/message.vim
Normal file
118
sources_non_forked/ale/autoload/ale/lsp/message.vim
Normal file
@ -0,0 +1,118 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Language Server Protocol message implementations
|
||||
"
|
||||
" Messages in this movie will be returned in the format
|
||||
" [is_notification, method_name, params?]
|
||||
let g:ale_lsp_next_version_id = 1
|
||||
|
||||
" 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(),
|
||||
\ 'rootPath': a:root_path,
|
||||
\ 'capabilities': {},
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#Initialized() abort
|
||||
return [1, 'initialized']
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#Shutdown() abort
|
||||
return [0, 'shutdown']
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#Exit() abort
|
||||
return [1, 'exit']
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidOpen(buffer, language_id) abort
|
||||
let l:lines = getbufline(a:buffer, 1, '$')
|
||||
|
||||
return [1, 'textDocument/didOpen', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ 'languageId': a:language_id,
|
||||
\ 'version': ale#lsp#message#GetNextVersionID(),
|
||||
\ 'text': join(l:lines, "\n") . "\n",
|
||||
\ },
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
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': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ 'version': ale#lsp#message#GetNextVersionID(),
|
||||
\ },
|
||||
\ 'contentChanges': [{'text': join(l:lines, "\n") . "\n"}]
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidSave(buffer) abort
|
||||
return [1, 'textDocument/didSave', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#DidClose(buffer) abort
|
||||
return [1, 'textDocument/didClose', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
let s:COMPLETION_TRIGGER_INVOKED = 1
|
||||
let s:COMPLETION_TRIGGER_CHARACTER = 2
|
||||
|
||||
function! ale#lsp#message#Completion(buffer, line, column, trigger_character) abort
|
||||
let l:message = [0, 'textDocument/completion', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\ 'position': {'line': a:line - 1, 'character': a:column},
|
||||
\}]
|
||||
|
||||
if !empty(a:trigger_character)
|
||||
let l:message[2].context = {
|
||||
\ 'triggerKind': s:COMPLETION_TRIGGER_CHARACTER,
|
||||
\ 'triggerCharacter': a:trigger_character,
|
||||
\}
|
||||
endif
|
||||
|
||||
return l:message
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#message#Definition(buffer, line, column) abort
|
||||
return [0, 'textDocument/definition', {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')),
|
||||
\ },
|
||||
\ 'position': {'line': a:line - 1, 'character': a:column},
|
||||
\}]
|
||||
endfunction
|
25
sources_non_forked/ale/autoload/ale/lsp/reset.vim
Normal file
25
sources_non_forked/ale/autoload/ale/lsp/reset.vim
Normal file
@ -0,0 +1,25 @@
|
||||
" Stop all LSPs and remove all of the data for them.
|
||||
function! ale#lsp#reset#StopAllLSPs() abort
|
||||
call ale#lsp#StopAll()
|
||||
|
||||
if exists('*ale#definition#ClearLSPData')
|
||||
" Clear the mapping for connections, etc.
|
||||
call ale#definition#ClearLSPData()
|
||||
endif
|
||||
|
||||
if exists('*ale#engine#ClearLSPData')
|
||||
" Clear the mapping for connections, etc.
|
||||
call ale#engine#ClearLSPData()
|
||||
|
||||
" Remove the problems for all of the LSP linters in every buffer.
|
||||
for l:buffer_string in keys(g:ale_buffer_info)
|
||||
let l:buffer = str2nr(l:buffer_string)
|
||||
|
||||
for l:linter in ale#linter#Get(getbufvar(l:buffer, '&filetype'))
|
||||
if !empty(l:linter.lsp)
|
||||
call ale#engine#HandleLoclist(l:linter.name, l:buffer, [])
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
74
sources_non_forked/ale/autoload/ale/lsp/response.vim
Normal file
74
sources_non_forked/ale/autoload/ale/lsp/response.vim
Normal file
@ -0,0 +1,74 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Parsing and transforming of LSP server responses.
|
||||
|
||||
" Constants for message severity codes.
|
||||
let s:SEVERITY_ERROR = 1
|
||||
let s:SEVERITY_WARNING = 2
|
||||
let s:SEVERITY_INFORMATION = 3
|
||||
let s:SEVERITY_HINT = 4
|
||||
|
||||
" Parse the message for textDocument/publishDiagnostics
|
||||
function! ale#lsp#response#ReadDiagnostics(response) abort
|
||||
let l:loclist = []
|
||||
|
||||
for l:diagnostic in a:response.params.diagnostics
|
||||
let l:severity = get(l:diagnostic, 'severity', 0)
|
||||
let l:loclist_item = {
|
||||
\ 'text': l:diagnostic.message,
|
||||
\ 'type': 'E',
|
||||
\ 'lnum': l:diagnostic.range.start.line + 1,
|
||||
\ 'col': l:diagnostic.range.start.character + 1,
|
||||
\ 'end_lnum': l:diagnostic.range.end.line + 1,
|
||||
\ 'end_col': l:diagnostic.range.end.character + 1,
|
||||
\}
|
||||
|
||||
if l:severity == s:SEVERITY_WARNING
|
||||
let l:loclist_item.type = 'W'
|
||||
elseif l:severity == s:SEVERITY_INFORMATION
|
||||
" TODO: Use 'I' here in future.
|
||||
let l:loclist_item.type = 'W'
|
||||
elseif l:severity == s:SEVERITY_HINT
|
||||
" TODO: Use 'H' here in future
|
||||
let l:loclist_item.type = 'W'
|
||||
endif
|
||||
|
||||
if has_key(l:diagnostic, 'code')
|
||||
let l:loclist_item.nr = l:diagnostic.code
|
||||
endif
|
||||
|
||||
call add(l:loclist, l:loclist_item)
|
||||
endfor
|
||||
|
||||
return l:loclist
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#response#ReadTSServerDiagnostics(response) abort
|
||||
let l:loclist = []
|
||||
|
||||
for l:diagnostic in a:response.body.diagnostics
|
||||
let l:loclist_item = {
|
||||
\ 'text': l:diagnostic.text,
|
||||
\ 'type': 'E',
|
||||
\ 'lnum': l:diagnostic.start.line,
|
||||
\ 'col': l:diagnostic.start.offset,
|
||||
\ 'end_lnum': l:diagnostic.end.line,
|
||||
\ 'end_col': l:diagnostic.end.offset,
|
||||
\}
|
||||
|
||||
if has_key(l:diagnostic, 'code')
|
||||
let l:loclist_item.nr = l:diagnostic.code
|
||||
endif
|
||||
|
||||
if get(l:diagnostic, 'category') is# 'warning'
|
||||
let l:loclist_item.type = 'W'
|
||||
endif
|
||||
|
||||
if get(l:diagnostic, 'category') is# 'suggestion'
|
||||
let l:loclist_item.type = 'I'
|
||||
endif
|
||||
|
||||
call add(l:loclist, l:loclist_item)
|
||||
endfor
|
||||
|
||||
return l:loclist
|
||||
endfunction
|
63
sources_non_forked/ale/autoload/ale/lsp/tsserver_message.vim
Normal file
63
sources_non_forked/ale/autoload/ale/lsp/tsserver_message.vim
Normal file
@ -0,0 +1,63 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: tsserver message implementations
|
||||
"
|
||||
" Messages in this movie will be returned in the format
|
||||
" [is_notification, command_name, params?]
|
||||
"
|
||||
" Every command must begin with the string 'ts@', which will be used to
|
||||
" detect the different message format for tsserver, and this string will
|
||||
" be removed from the actual command name,
|
||||
|
||||
function! ale#lsp#tsserver_message#Open(buffer) abort
|
||||
return [1, 'ts@open', {'file': expand('#' . a:buffer . ':p')}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#tsserver_message#Close(buffer) abort
|
||||
return [1, 'ts@close', {'file': expand('#' . a:buffer . ':p')}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#tsserver_message#Change(buffer) abort
|
||||
let l:lines = getbufline(a:buffer, 1, '$')
|
||||
|
||||
" We will always use a very high endLine number, so we can delete
|
||||
" lines from files. tsserver will gladly accept line numbers beyond the
|
||||
" end.
|
||||
return [1, 'ts@change', {
|
||||
\ 'file': expand('#' . a:buffer . ':p'),
|
||||
\ 'line': 1,
|
||||
\ 'offset': 1,
|
||||
\ 'endLine': 1073741824,
|
||||
\ 'endOffset': 1,
|
||||
\ 'insertString': join(l:lines, "\n") . "\n",
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#tsserver_message#Geterr(buffer) abort
|
||||
return [1, 'ts@geterr', {'files': [expand('#' . a:buffer . ':p')]}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#tsserver_message#Completions(buffer, line, column, prefix) abort
|
||||
return [0, 'ts@completions', {
|
||||
\ 'line': a:line,
|
||||
\ 'offset': a:column,
|
||||
\ 'file': expand('#' . a:buffer . ':p'),
|
||||
\ 'prefix': a:prefix,
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#tsserver_message#CompletionEntryDetails(buffer, line, column, entry_names) abort
|
||||
return [0, 'ts@completionEntryDetails', {
|
||||
\ 'line': a:line,
|
||||
\ 'offset': a:column,
|
||||
\ 'file': expand('#' . a:buffer . ':p'),
|
||||
\ 'entryNames': a:entry_names,
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! ale#lsp#tsserver_message#Definition(buffer, line, column) abort
|
||||
return [0, 'ts@definition', {
|
||||
\ 'line': a:line,
|
||||
\ 'offset': a:column,
|
||||
\ 'file': expand('#' . a:buffer . ':p'),
|
||||
\}]
|
||||
endfunction
|
Reference in New Issue
Block a user