Created
June 30, 2017 22:28
-
-
Save Firehed/73a9045a37b75c1629405be97a0758f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim | |
index f7c25b0..f541878 100644 | |
--- a/autoload/ale/engine.vim | |
+++ b/autoload/ale/engine.vim | |
@@ -195,6 +195,19 @@ function! s:HandleExit(job_id, exit_code) abort | |
endfunction | |
function! s:HandleLSPResponse(response) abort | |
+ let l:is_diag_response = get(a:response, 'method', '') ==# 'textDocument/publishDiagnostics' | |
+ | |
+ if !l:is_diag_response | |
+ return | |
+ endif | |
+ | |
+ let l:diag_params = get(a:response, 'params', '') | |
+ | |
+ echo l:diag_params | |
+endfunction | |
+ | |
+ | |
+function! s:HandleTSServerResponse(response) abort | |
let l:is_diag_response = get(a:response, 'type', '') ==# 'event' | |
\ && get(a:response, 'event', '') ==# 'semanticDiag' | |
@@ -561,7 +574,7 @@ function! ale#engine#StopCurrentJobs(buffer, include_lint_file_jobs) abort | |
let l:info.lsp_command_list = [] | |
endfunction | |
-function! s:CheckWithTSServer(buffer, linter, executable) abort | |
+function! s:CheckWithLSPServer(buffer, linter, executable) abort | |
let l:info = g:ale_buffer_info[a:buffer] | |
let l:open_documents = l:info.open_lsp_documents | |
let l:is_open = index(l:open_documents, a:linter.name) >= 0 | |
@@ -583,6 +596,45 @@ function! s:CheckWithTSServer(buffer, linter, executable) abort | |
endif | |
call add(l:open_documents, a:linter.name) | |
+ | |
+ " Do something to track initilization message | |
+ let l:initmsg = ale#lsp#message#Initialize('/Users/ericstern/dev/php-lsp-testing') | |
+ call ale#lsp#SendMessageToProgram( | |
+ \ a:executable, | |
+ \ l:initmsg | |
+ \) | |
+ endif | |
+ | |
+ call ale#lsp#SendMessageToProgram( | |
+ \ a:executable, | |
+ \ ale#lsp#message#DidOpen(a:buffer, 'php', '1', a:buffer) | |
+ \) | |
+ | |
+ | |
+endfunction | |
+ | |
+function! s:CheckWithTSServer(buffer, linter, executable) abort | |
+ let l:info = g:ale_buffer_info[a:buffer] | |
+ let l:open_documents = l:info.open_lsp_documents | |
+ let l:is_open = index(l:open_documents, a:linter.name) >= 0 | |
+ | |
+ let l:command = ale#job#PrepareCommand(a:executable) | |
+ let l:job_id = ale#lsp#StartProgram(a:executable, l:command, function('s:HandleTSServerResponse')) | |
+ | |
+ if !l:job_id | |
+ if g:ale_history_enabled | |
+ call ale#history#Add(a:buffer, 'failed', l:job_id, l:command) | |
+ endif | |
+ | |
+ return | |
+ endif | |
+ | |
+ if !l:is_open | |
+ if g:ale_history_enabled | |
+ call ale#history#Add(a:buffer, 'started', l:job_id, l:command) | |
+ endif | |
+ | |
+ call add(l:open_documents, a:linter.name) | |
call ale#lsp#SendMessageToProgram( | |
\ a:executable, | |
\ ale#lsp#tsserver_message#Open(a:buffer), | |
@@ -605,7 +657,7 @@ function! s:CheckWithTSServer(buffer, linter, executable) abort | |
endfunction | |
function! ale#engine#Invoke(buffer, linter) abort | |
- if empty(a:linter.lsp) || a:linter.lsp ==# 'tsserver' | |
+ if empty(a:linter.lsp) || a:linter.lsp ==# 'tsserver' || a:linter.lsp ==# 'lsp' | |
let l:executable = has_key(a:linter, 'executable_callback') | |
\ ? ale#util#GetFunction(a:linter.executable_callback)(a:buffer) | |
\ : a:linter.executable | |
@@ -614,6 +666,8 @@ function! ale#engine#Invoke(buffer, linter) abort | |
if s:IsExecutable(l:executable) | |
if a:linter.lsp ==# 'tsserver' | |
call s:CheckWithTSServer(a:buffer, a:linter, l:executable) | |
+ elseif a:linter.lsp ==# 'lsp' | |
+ call s:CheckWithLSPServer(a:buffer, a:linter, l:executable) | |
else | |
call s:InvokeChain(a:buffer, a:linter, 0, []) | |
endif | |
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim | |
index 3c2ddd3..ce33867 100644 | |
--- a/autoload/ale/linter.vim | |
+++ b/autoload/ale/linter.vim | |
@@ -65,12 +65,13 @@ function! ale#linter#PreProcess(linter) abort | |
let l:needs_executable = 0 | |
let l:needs_address = 0 | |
+ let l:needs_address_or_executable = 0 | |
let l:needs_command = 0 | |
if l:obj.lsp ==# 'tsserver' | |
let l:needs_executable = 1 | |
elseif l:obj.lsp ==# 'lsp' | |
- let l:needs_address = 1 | |
+ let l:needs_address_or_executable = 1 | |
elseif !empty(l:obj.lsp) | |
throw '`lsp` must be either `''lsp''` or `''tsserver''` if defined' | |
else | |
@@ -78,7 +79,7 @@ function! ale#linter#PreProcess(linter) abort | |
let l:needs_command = 1 | |
endif | |
- if !l:needs_executable | |
+ if !l:needs_executable && !l:needs_address_or_executable | |
if has_key(a:linter, 'executable') | |
\|| has_key(a:linter, 'executable_callback') | |
throw '`executable` and `executable_callback` cannot be used when lsp == ''lsp''' | |
diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim | |
index ce7efd1..d20fcef 100644 | |
--- a/autoload/ale/lsp.vim | |
+++ b/autoload/ale/lsp.vim | |
@@ -111,11 +111,11 @@ function! ale#lsp#ReadMessageData(data) abort | |
\ '\vContent-Length: *(\d+)' | |
\) | |
- if empty(l:length_match) | |
- throw "Invalid JSON-RPC header:\n" . l:header_data | |
- endif | |
+ if empty(l:length_match) | |
+ throw "Invalid JSON-RPC header:\n" . l:header_data | |
+ endif | |
- " Split the body and the remainder of the text. | |
+ " Split the body and the remainder of the text. | |
let l:remainder_start_index = l:body_start_index + str2nr(l:length_match[1]) | |
if len(l:remainder) < l:remainder_start_index | |
diff --git a/autoload/ale/lsp/message.vim b/autoload/ale/lsp/message.vim | |
index 937e4f4..7eae1d2 100644 | |
--- a/autoload/ale/lsp/message.vim | |
+++ b/autoload/ale/lsp/message.vim | |
@@ -8,7 +8,7 @@ function! ale#lsp#message#Initialize(root_uri) abort | |
" TODO: Define needed capabilities. | |
return [0, 'initialize', { | |
\ 'processId': getpid(), | |
- \ 'rootUri': a:root_uri, | |
+ \ 'rootPath': a:root_uri, | |
\ 'capabilities': {}, | |
\}] | |
endfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Author: Eric Stern <[email protected]> | |
" Description: PHP Language server integration for ALE | |
call ale#Set('php_langserver_executable', 'vendor/bin/php-language-server.php') | |
call ale#Set('php_langserver_config_path', '') | |
call ale#Set('php_langserver_use_global', 0) | |
function! ale_linters#php#langserver#GetExecutable(buffer) abort | |
return ale#node#FindExecutable(a:buffer, 'php_langserver', [ | |
\ 'fake.php', | |
\ 'vendor/bin/php-language-server.php', | |
\]) | |
endfunction | |
function! ale_linters#php#langserver#Handle(buffer, lines) abort | |
put =a: | |
endfunction | |
call ale#linter#Define('php', { | |
\ 'name': 'langserver', | |
\ 'lsp': 'lsp', | |
\ 'executable_callback': 'ale_linters#php#langserver#GetExecutable', | |
\ 'callback': 'ale_linters#php#langserver#Handle', | |
\}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
sleep(1); | |
$json = '{"id":0,"result":{"capabilities":{"textDocumentSync":1,"hoverProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":["$",">"]},"signatureHelpProvider":null,"definitionProvider":true,"referencesProvider":true,"documentHighlightProvider":null,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":null,"codeLensProvider":null,"documentFormattingProvider":true,"documentRangeFormattingProvider":null,"documentOnTypeFormattingProvider":null,"renameProvider":null,"xworkspaceReferencesProvider":true,"xdefinitionProvider":true,"dependenciesProvider":null,"xdependenciesProvider":true}},"error":null,"jsonrpc":"2.0"}'; | |
$initial = json_decode($json, true); | |
showData($initial); | |
sleep(2); | |
while (true) { | |
$data = [ | |
"method" => "window/logMessage", | |
"params" => [ | |
"type" => 4, | |
"message" => "Parsing file:///Users/firehed/dev/php-lsp-testing/run.php", | |
], | |
"jsonrpc" => "2.0", | |
]; | |
showData($data); | |
sleep(5); | |
} | |
function showData(array $data) { | |
$json = json_encode($data); | |
echo sprintf("Content-Length: %d\r\n", strlen($json)); | |
echo sprintf("Content-Type: application/vscode-jsonrpc; charset=utf-8\r\n"); | |
echo sprintf("\r\n"); | |
echo $json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment