#517 - Implement LSP chunked message parsing, sending messages to sockets, and callbacks

This commit is contained in:
w0rp
2017-05-08 22:18:28 +01:00
parent cd79ced839
commit 28c6ec9cad
7 changed files with 492 additions and 334 deletions
+21 -22
View File
@@ -1,65 +1,64 @@
" 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?]
function! ale#lsp#message#CancelRequest(id) abort
return ale#lsp#CreateMessage('$/cancelRequest', {'id': a:id})
endfunction
function! ale#lsp#message#Initialize(processId, rootUri) abort
function! ale#lsp#message#Initialize(root_uri) abort
" TODO: Define needed capabilities.
return ale#lsp#CreateMessage('initialize', {
\ 'processId': a:processId,
\ 'rootUri': a:rootUri,
return [0, 'initialize', {
\ 'processId': getpid(),
\ 'rootUri': a:root_uri,
\ 'capabilities': {},
\})
\}]
endfunction
function! ale#lsp#message#Initialized() abort
return ale#lsp#CreateMessage('initialized')
return [1, 'initialized']
endfunction
function! ale#lsp#message#Shutdown() abort
return ale#lsp#CreateMessage('shutdown')
return [0, 'shutdown']
endfunction
function! ale#lsp#message#Exit() abort
return ale#lsp#CreateMessage('exit')
return [1, 'exit']
endfunction
function! ale#lsp#message#DidOpen(uri, languageId, version, text) abort
return ale#lsp#CreateMessage('textDocument/didOpen', {
function! ale#lsp#message#DidOpen(uri, language_id, version, text) abort
return [1, 'textDocument/didOpen', {
\ 'textDocument': {
\ 'uri': a:uri,
\ 'languageId': a:languageId,
\ 'languageId': a:language_id,
\ 'version': a:version,
\ 'text': a:text,
\ },
\})
\}]
endfunction
function! ale#lsp#message#DidChange(uri, version, text) abort
" For changes, we simply send the full text of the document to the server.
return ale#lsp#CreateMessage('textDocument/didChange', {
return [1, 'textDocument/didChange', {
\ 'textDocument': {
\ 'uri': a:uri,
\ 'version': a:version,
\ },
\ 'contentChanges': [{'text': a:text}]
\})
\}]
endfunction
function! ale#lsp#message#DidSave(uri) abort
return ale#lsp#CreateMessage('textDocument/didSave', {
return [1, 'textDocument/didSave', {
\ 'textDocument': {
\ 'uri': a:uri,
\ },
\})
\}]
endfunction
function! ale#lsp#message#DidClose(uri) abort
return ale#lsp#CreateMessage('textDocument/didClose', {
return [1, 'textDocument/didClose', {
\ 'textDocument': {
\ 'uri': a:uri,
\ },
\})
\}]
endfunction