From 61a5880747128dbf988a076e190ccb346500b5ff Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 19 Jul 2018 21:15:05 +0100 Subject: Capture server capabilities from LSP servers --- .../test_other_initialize_message_handling.vader | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) (limited to 'test/lsp') diff --git a/test/lsp/test_other_initialize_message_handling.vader b/test/lsp/test_other_initialize_message_handling.vader index 3a7c7f62..f9567ee0 100644 --- a/test/lsp/test_other_initialize_message_handling.vader +++ b/test/lsp/test_other_initialize_message_handling.vader @@ -9,6 +9,13 @@ Before: \ 'projects': { \ '/foo/bar': b:project, \ }, + \ 'capabilities': { + \ 'hover': 0, + \ 'references': 0, + \ 'completion': 0, + \ 'completion_trigger_characters': [], + \ 'definition': 0, + \ }, \} After: @@ -64,3 +71,107 @@ Execute(Other messages should not initialize projects): call ale#lsp#HandleOtherInitializeResponses(b:conn, {'result': {'x': {}}}) AssertEqual 0, b:project.initialized + +Execute(Capabilities should bet set up correctly): + call ale#lsp#HandleOtherInitializeResponses(b:conn, { + \ 'jsonrpc': '2.0', + \ 'id': 1, + \ 'result': { + \ 'capabilities': { + \ 'renameProvider': v:true, + \ 'executeCommandProvider': { + \ 'commands': [], + \ }, + \ 'hoverProvider': v:true, + \ 'documentSymbolProvider': v:true, + \ 'documentRangeFormattingProvider': v:true, + \ 'codeLensProvider': { + \ 'resolveProvider': v:false + \ }, + \ 'referencesProvider': v:true, + \ 'textDocumentSync': 2, + \ 'documentFormattingProvider': v:true, + \ 'codeActionProvider': v:true, + \ 'signatureHelpProvider': { + \ 'triggerCharacters': ['(', ','], + \ }, + \ 'completionProvider': { + \ 'triggerCharacters': ['.'], + \ 'resolveProvider': v:false + \ }, + \ 'definitionProvider': v:true, + \ 'experimental': {}, + \ 'documentHighlightProvider': v:true + \ }, + \ }, + \}) + + AssertEqual + \ { + \ 'capabilities': { + \ 'completion_trigger_characters': ['.'], + \ 'completion': 1, + \ 'references': 1, + \ 'hover': 1, + \ 'definition': 1, + \ }, + \ 'message_queue': [], + \ 'projects': { + \ '/foo/bar': { + \ 'initialized': 1, + \ 'message_queue': [], + \ 'init_request_id': 3, + \ }, + \ }, + \ }, + \ b:conn + +Execute(Disabled capabilities should be recognised correctly): + call ale#lsp#HandleOtherInitializeResponses(b:conn, { + \ 'jsonrpc': '2.0', + \ 'id': 1, + \ 'result': { + \ 'capabilities': { + \ 'renameProvider': v:true, + \ 'executeCommandProvider': { + \ 'commands': [], + \ }, + \ 'hoverProvider': v:false, + \ 'documentSymbolProvider': v:true, + \ 'documentRangeFormattingProvider': v:true, + \ 'codeLensProvider': { + \ 'resolveProvider': v:false + \ }, + \ 'referencesProvider': v:false, + \ 'textDocumentSync': 2, + \ 'documentFormattingProvider': v:true, + \ 'codeActionProvider': v:true, + \ 'signatureHelpProvider': { + \ 'triggerCharacters': ['(', ','], + \ }, + \ 'definitionProvider': v:false, + \ 'experimental': {}, + \ 'documentHighlightProvider': v:true + \ }, + \ }, + \}) + + AssertEqual + \ { + \ 'capabilities': { + \ 'completion_trigger_characters': [], + \ 'completion': 0, + \ 'references': 0, + \ 'hover': 0, + \ 'definition': 0, + \ }, + \ 'message_queue': [], + \ 'projects': { + \ '/foo/bar': { + \ 'initialized': 1, + \ 'message_queue': [], + \ 'init_request_id': 3, + \ }, + \ }, + \ }, + \ b:conn -- cgit v1.2.3 From 6dc737cda1d640d2067b417ec270fbb623e3f960 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 22 Jul 2018 19:04:45 +0100 Subject: Check LSP capabilities before using them --- test/lsp/test_did_save_event.vader | 6 +--- test/lsp/test_lsp_command_formatting.vader | 9 +++--- test/lsp/test_lsp_connections.vader | 34 ++++++++++++++-------- .../test_other_initialize_message_handling.vader | 6 ++++ 4 files changed, 33 insertions(+), 22 deletions(-) (limited to 'test/lsp') diff --git a/test/lsp/test_did_save_event.vader b/test/lsp/test_did_save_event.vader index b696ee4b..428135fb 100644 --- a/test/lsp/test_did_save_event.vader +++ b/test/lsp/test_did_save_event.vader @@ -14,7 +14,6 @@ Before: let g:ale_lsp_next_message_id = 1 let g:ale_run_synchronously = 1 let g:message_list = [] - let g:Callback = '' function! LanguageCallback() abort return 'foobar' @@ -34,9 +33,7 @@ Before: \ }) let g:ale_linters = {'foobar': ['dummy_linter']} - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -59,7 +56,6 @@ After: unlet! b:ale_enabled unlet! b:ale_linters - unlet! g:Callback unlet! g:message_list delfunction LanguageCallback diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader index f436397f..9d2c84ee 100644 --- a/test/lsp/test_lsp_command_formatting.vader +++ b/test/lsp/test_lsp_command_formatting.vader @@ -23,15 +23,14 @@ Execute(Command formatting should be applied correctly for LSP linters): \ 'executable': has('win32') ? 'cmd': 'true', \ 'command': '%e --foo', \ }, - \ {->0} \) if has('win32') AssertEqual - \ ['cmd', 'cmd /s/c "cmd --foo"', '/foo/bar'], - \ g:args[:2] + \ ['cmd', 'cmd /s/c "cmd --foo"', {}], + \ g:args else AssertEqual - \ ['true', [&shell, '-c', '''true'' --foo'], '/foo/bar'], - \ g:args[:2] + \ ['true', [&shell, '-c', '''true'' --foo'], {}], + \ g:args endif diff --git a/test/lsp/test_lsp_connections.vader b/test/lsp/test_lsp_connections.vader index 8651d801..ae64eadb 100644 --- a/test/lsp/test_lsp_connections.vader +++ b/test/lsp/test_lsp_connections.vader @@ -2,6 +2,10 @@ Before: let g:ale_lsp_next_message_id = 1 After: + if exists('b:conn') && has_key(b:conn, 'id') + call ale#lsp#RemoveConnectionWithID(b:conn.id) + endif + unlet! b:data unlet! b:conn @@ -223,17 +227,20 @@ Execute(ale#lsp#ReadMessageData() should handle a message with part of a second \ ) Execute(Projects with regular project roots should be registered correctly): - let b:conn = {'projects': {}} - - call ale#lsp#RegisterProject(b:conn, '/foo/bar') + let b:conn = ale#lsp#NewConnection({}) + call ale#lsp#RegisterProject(b:conn.id, '/foo/bar') AssertEqual \ { - \ 'projects': { - \ '/foo/bar': {'initialized': 0, 'message_queue': [], 'init_request_id': 0}, + \ '/foo/bar': { + \ 'root': '/foo/bar', + \ 'initialized': 0, + \ 'message_queue': [], + \ 'capabilities_queue': [], + \ 'init_request_id': 0, \ }, \ }, - \ b:conn + \ b:conn.projects Execute(Projects with regular project roots should be fetched correctly): let b:conn = { @@ -247,17 +254,20 @@ Execute(Projects with regular project roots should be fetched correctly): \ ale#lsp#GetProject(b:conn, '/foo/bar') Execute(Projects with empty project roots should be registered correctly): - let b:conn = {'projects': {}} - - call ale#lsp#RegisterProject(b:conn, '') + let b:conn = ale#lsp#NewConnection({}) + call ale#lsp#RegisterProject(b:conn.id, '') AssertEqual \ { - \ 'projects': { - \ '<>': {'initialized': 1, 'message_queue': [], 'init_request_id': 0}, + \ '<>': { + \ 'root': '', + \ 'initialized': 1, + \ 'message_queue': [], + \ 'capabilities_queue': [], + \ 'init_request_id': 0, \ }, \ }, - \ b:conn + \ b:conn.projects Execute(Projects with empty project roots should be fetched correctly): let b:conn = { diff --git a/test/lsp/test_other_initialize_message_handling.vader b/test/lsp/test_other_initialize_message_handling.vader index f9567ee0..45457979 100644 --- a/test/lsp/test_other_initialize_message_handling.vader +++ b/test/lsp/test_other_initialize_message_handling.vader @@ -3,6 +3,7 @@ Before: \ 'initialized': 0, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \} let b:conn = { @@ -34,6 +35,7 @@ Execute(publishDiagnostics messages with files inside project directories should \ 'initialized': 0, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -47,6 +49,7 @@ Execute(publishDiagnostics messages with files inside project directories should \ 'initialized': 1, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -60,6 +63,7 @@ Execute(Messages with no method and capabilities should initialize projects): \ 'initialized': 1, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -120,6 +124,7 @@ Execute(Capabilities should bet set up correctly): \ '/foo/bar': { \ 'initialized': 1, \ 'message_queue': [], + \ 'capabilities_queue': [], \ 'init_request_id': 3, \ }, \ }, @@ -170,6 +175,7 @@ Execute(Disabled capabilities should be recognised correctly): \ '/foo/bar': { \ 'initialized': 1, \ 'message_queue': [], + \ 'capabilities_queue': [], \ 'init_request_id': 3, \ }, \ }, -- cgit v1.2.3