All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: Language Server Protocol message implementations
4 " Messages in this movie will be returned in the format
5 " [is_notification, method_name, params?]
7 " All functions which accept line and column arguments expect them to be 1-based
8 " (the same format as being returned by getpos() and friends), those then
9 " will be converted to 0-based as specified by LSP.
10 let g:ale_lsp_next_version_id = 1
12 " The LSP protocols demands that we send every change to a document, including
13 " undo, with incrementing version numbers, so we'll just use one incrementing
15 function! ale#lsp#message#GetNextVersionID() abort
17 let l:id = g:ale_lsp_next_version_id
19 " Increment the ID variable.
20 let g:ale_lsp_next_version_id += 1
22 " When the ID overflows, reset it to 1. By the time we hit the initial ID
23 " again, the messages will be long gone.
24 if g:ale_lsp_next_version_id < 1
25 let g:ale_lsp_next_version_id = 1
31 function! ale#lsp#message#Initialize(root_path, options, capabilities) abort
32 " NOTE: rootPath is deprecated in favour of rootUri
33 return [0, 'initialize', {
34 \ 'processId': getpid(),
35 \ 'rootPath': a:root_path,
36 \ 'capabilities': a:capabilities,
37 \ 'initializationOptions': a:options,
38 \ 'rootUri': ale#util#ToURI(a:root_path),
42 function! ale#lsp#message#Initialized() abort
43 return [1, 'initialized', {}]
46 function! ale#lsp#message#Shutdown() abort
47 return [0, 'shutdown']
50 function! ale#lsp#message#Exit() abort
54 function! ale#lsp#message#DidOpen(buffer, language_id) abort
55 return [1, 'textDocument/didOpen', {
57 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
58 \ 'languageId': a:language_id,
59 \ 'version': ale#lsp#message#GetNextVersionID(),
60 \ 'text': ale#util#GetBufferContents(a:buffer),
65 function! ale#lsp#message#DidChange(buffer) abort
66 " For changes, we simply send the full text of the document to the server.
67 return [1, 'textDocument/didChange', {
69 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
70 \ 'version': ale#lsp#message#GetNextVersionID(),
72 \ 'contentChanges': [{'text': ale#util#GetBufferContents(a:buffer)}]
76 function! ale#lsp#message#DidSave(buffer, include_text) abort
77 let l:response = [1, 'textDocument/didSave', {
79 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
84 let l:response[2].textDocument.version = ale#lsp#message#GetNextVersionID()
85 let l:response[2].text = ale#util#GetBufferContents(a:buffer)
91 function! ale#lsp#message#DidClose(buffer) abort
92 return [1, 'textDocument/didClose', {
94 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
99 let s:COMPLETION_TRIGGER_INVOKED = 1
100 let s:COMPLETION_TRIGGER_CHARACTER = 2
102 function! ale#lsp#message#Completion(buffer, line, column, trigger_character) abort
103 let l:message = [0, 'textDocument/completion', {
105 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
107 \ 'position': {'line': a:line - 1, 'character': a:column - 1},
110 if !empty(a:trigger_character)
111 let l:message[2].context = {
112 \ 'triggerKind': s:COMPLETION_TRIGGER_CHARACTER,
113 \ 'triggerCharacter': a:trigger_character,
120 function! ale#lsp#message#Definition(buffer, line, column) abort
121 return [0, 'textDocument/definition', {
123 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
125 \ 'position': {'line': a:line - 1, 'character': a:column - 1},
129 function! ale#lsp#message#TypeDefinition(buffer, line, column) abort
130 return [0, 'textDocument/typeDefinition', {
132 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
134 \ 'position': {'line': a:line - 1, 'character': a:column - 1},
138 function! ale#lsp#message#Implementation(buffer, line, column) abort
139 return [0, 'textDocument/implementation', {
141 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
143 \ 'position': {'line': a:line - 1, 'character': a:column - 1},
147 function! ale#lsp#message#References(buffer, line, column) abort
148 return [0, 'textDocument/references', {
150 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
152 \ 'position': {'line': a:line - 1, 'character': a:column - 1},
153 \ 'context': {'includeDeclaration': v:false},
157 function! ale#lsp#message#Symbol(query) abort
158 return [0, 'workspace/symbol', {
163 function! ale#lsp#message#Hover(buffer, line, column) abort
164 return [0, 'textDocument/hover', {
166 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
168 \ 'position': {'line': a:line - 1, 'character': a:column - 1},
172 function! ale#lsp#message#DidChangeConfiguration(buffer, config) abort
173 return [1, 'workspace/didChangeConfiguration', {
174 \ 'settings': a:config,
178 function! ale#lsp#message#Rename(buffer, line, column, new_name) abort
179 return [0, 'textDocument/rename', {
181 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
183 \ 'position': {'line': a:line - 1, 'character': a:column - 1},
184 \ 'newName': a:new_name,
188 function! ale#lsp#message#CodeAction(buffer, line, column, end_line, end_column, diagnostics) abort
189 return [0, 'textDocument/codeAction', {
191 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
194 \ 'start': {'line': a:line - 1, 'character': a:column - 1},
195 \ 'end': {'line': a:end_line - 1, 'character': a:end_column},
198 \ 'diagnostics': a:diagnostics
203 function! ale#lsp#message#Diagnostic(buffer) abort
204 return [0, 'textDocument/diagnostic', {
206 \ 'uri': ale#util#ToURI(expand('#' . a:buffer . ':p')),
211 function! ale#lsp#message#ExecuteCommand(command, arguments) abort
212 return [0, 'workspace/executeCommand', {
213 \ 'command': a:command,
214 \ 'arguments': a:arguments,