#517 Add more code LSP support which makes the tssserver linter behave more like the LSP linters
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
Before:
|
||||
silent! cd /testplugin/test/lsp
|
||||
let b:dir = getcwd()
|
||||
let g:dir = getcwd()
|
||||
let g:ale_lsp_next_version_id = 1
|
||||
|
||||
call ale#test#SetFilename('foo/bar.ts')
|
||||
|
||||
After:
|
||||
silent execute 'cd ' . fnameescape(b:dir)
|
||||
unlet! b:dir
|
||||
silent execute 'cd ' . fnameescape(g:dir)
|
||||
unlet! g:dir
|
||||
|
||||
Execute(ale#lsp#message#Initialize() should return correct messages):
|
||||
AssertEqual
|
||||
@@ -13,7 +16,7 @@ Execute(ale#lsp#message#Initialize() should return correct messages):
|
||||
\ 'initialize',
|
||||
\ {
|
||||
\ 'processId': getpid(),
|
||||
\ 'rootUri': '/foo/bar',
|
||||
\ 'rootPath': '/foo/bar',
|
||||
\ 'capabilities': {},
|
||||
\ }
|
||||
\ ],
|
||||
@@ -28,36 +31,51 @@ Execute(ale#lsp#message#Shutdown() should return correct messages):
|
||||
Execute(ale#lsp#message#Exit() should return correct messages):
|
||||
AssertEqual [1, 'exit'], ale#lsp#message#Exit(),
|
||||
|
||||
Given typescript(A TypeScript file with 3 lines):
|
||||
foo()
|
||||
bar()
|
||||
baz()
|
||||
|
||||
Execute(ale#lsp#message#DidOpen() should return correct messages):
|
||||
let g:ale_lsp_next_version_id = 12
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 1,
|
||||
\ 'textDocument/didOpen',
|
||||
\ {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': '/foo/bar',
|
||||
\ 'uri': 'file://' . g:dir . '/foo/bar.ts',
|
||||
\ 'languageId': 'typescript',
|
||||
\ 'version': 123,
|
||||
\ 'text': 'foobar',
|
||||
\ 'version': 12,
|
||||
\ 'text': "foo()\nbar()\nbaz()",
|
||||
\ },
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#message#DidOpen('/foo/bar', 'typescript', 123, 'foobar')
|
||||
\ ale#lsp#message#DidOpen(bufnr(''), 'typescript')
|
||||
|
||||
Execute(ale#lsp#message#DidChange() should return correct messages):
|
||||
let g:ale_lsp_next_version_id = 34
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 1,
|
||||
\ 'textDocument/didChange',
|
||||
\ {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': '/foo/bar',
|
||||
\ 'version': 123,
|
||||
\ 'uri': 'file://' . g:dir . '/foo/bar.ts',
|
||||
\ 'version': 34,
|
||||
\ },
|
||||
\ 'contentChanges': [{'text': 'foobar'}],
|
||||
\ 'contentChanges': [{'text': "foo()\nbar()\nbaz()"}],
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#message#DidChange('/foo/bar', 123, 'foobar')
|
||||
\ ale#lsp#message#DidChange(bufnr(''))
|
||||
" The version numbers should increment.
|
||||
AssertEqual
|
||||
\ 35,
|
||||
\ ale#lsp#message#DidChange(bufnr(''))[2].textDocument.version
|
||||
AssertEqual
|
||||
\ 36,
|
||||
\ ale#lsp#message#DidChange(bufnr(''))[2].textDocument.version
|
||||
|
||||
Execute(ale#lsp#message#DidSave() should return correct messages):
|
||||
AssertEqual
|
||||
@@ -66,11 +84,11 @@ Execute(ale#lsp#message#DidSave() should return correct messages):
|
||||
\ 'textDocument/didSave',
|
||||
\ {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': '/foo/bar',
|
||||
\ 'uri': 'file://' . g:dir . '/foo/bar.ts',
|
||||
\ },
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#message#DidSave('/foo/bar')
|
||||
\ ale#lsp#message#DidSave(bufnr(''))
|
||||
|
||||
Execute(ale#lsp#message#DidClose() should return correct messages):
|
||||
AssertEqual
|
||||
@@ -79,52 +97,41 @@ Execute(ale#lsp#message#DidClose() should return correct messages):
|
||||
\ 'textDocument/didClose',
|
||||
\ {
|
||||
\ 'textDocument': {
|
||||
\ 'uri': '/foo/bar',
|
||||
\ 'uri': 'file://' . g:dir . '/foo/bar.ts',
|
||||
\ },
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#message#DidClose('/foo/bar')
|
||||
\ ale#lsp#message#DidClose(bufnr(''))
|
||||
|
||||
Execute(ale#lsp#tsserver_message#Open() should return correct messages):
|
||||
silent! noautocmd file foo.ts
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 1,
|
||||
\ 'ts@open',
|
||||
\ {
|
||||
\ 'file': b:dir . '/foo.ts',
|
||||
\ 'file': g:dir . '/foo/bar.ts',
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#tsserver_message#Open(bufnr(''))
|
||||
|
||||
Execute(ale#lsp#tsserver_message#Close() should return correct messages):
|
||||
silent! noautocmd file foo.ts
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 1,
|
||||
\ 'ts@close',
|
||||
\ {
|
||||
\ 'file': b:dir . '/foo.ts',
|
||||
\ 'file': g:dir . '/foo/bar.ts',
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#tsserver_message#Close(bufnr(''))
|
||||
|
||||
Given typescript(A TypeScript file with 3 lines):
|
||||
foo()
|
||||
bar()
|
||||
baz()
|
||||
|
||||
Execute(ale#lsp#tsserver_message#Change() should return correct messages):
|
||||
silent! noautocmd file foo.ts
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 1,
|
||||
\ 'ts@change',
|
||||
\ {
|
||||
\ 'file': b:dir . '/foo.ts',
|
||||
\ 'file': g:dir . '/foo/bar.ts',
|
||||
\ 'line': 1,
|
||||
\ 'offset': 1,
|
||||
\ 'endLine': 1073741824,
|
||||
@@ -135,27 +142,23 @@ Execute(ale#lsp#tsserver_message#Change() should return correct messages):
|
||||
\ ale#lsp#tsserver_message#Change(bufnr(''))
|
||||
|
||||
Execute(ale#lsp#tsserver_message#Geterr() should return correct messages):
|
||||
silent! noautocmd file foo.ts
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 1,
|
||||
\ 'ts@geterr',
|
||||
\ {
|
||||
\ 'files': [b:dir . '/foo.ts'],
|
||||
\ 'files': [g:dir . '/foo/bar.ts'],
|
||||
\ }
|
||||
\ ],
|
||||
\ ale#lsp#tsserver_message#Geterr(bufnr(''))
|
||||
|
||||
Execute(ale#lsp#tsserver_message#Completions() should return correct messages):
|
||||
silent! noautocmd file foo.ts
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 0,
|
||||
\ 'ts@completions',
|
||||
\ {
|
||||
\ 'file': b:dir . '/foo.ts',
|
||||
\ 'file': g:dir . '/foo/bar.ts',
|
||||
\ 'line': 347,
|
||||
\ 'offset': 12,
|
||||
\ 'prefix': 'abc',
|
||||
@@ -164,14 +167,12 @@ Execute(ale#lsp#tsserver_message#Completions() should return correct messages):
|
||||
\ ale#lsp#tsserver_message#Completions(bufnr(''), 347, 12, 'abc')
|
||||
|
||||
Execute(ale#lsp#tsserver_message#CompletionEntryDetails() should return correct messages):
|
||||
silent! noautocmd file foo.ts
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 0,
|
||||
\ 'ts@completionEntryDetails',
|
||||
\ {
|
||||
\ 'file': b:dir . '/foo.ts',
|
||||
\ 'file': g:dir . '/foo/bar.ts',
|
||||
\ 'line': 347,
|
||||
\ 'offset': 12,
|
||||
\ 'entryNames': ['foo', 'bar'],
|
||||
|
||||
@@ -10,7 +10,7 @@ After:
|
||||
delfunction Range
|
||||
|
||||
Execute(ale#lsp#response#ReadDiagnostics() should handle errors):
|
||||
AssertEqual ['filename.ts', [
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Something went wrong!',
|
||||
@@ -20,18 +20,18 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle errors):
|
||||
\ 'end_col': 16,
|
||||
\ 'nr': 'some-error',
|
||||
\ }
|
||||
\ ]],
|
||||
\ ale#lsp#response#ReadDiagnostics({'uri': 'filename.ts', 'diagnostics': [
|
||||
\ ],
|
||||
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
|
||||
\ {
|
||||
\ 'severity': 1,
|
||||
\ 'range': Range(2, 10, 4, 15),
|
||||
\ 'code': 'some-error',
|
||||
\ 'message': 'Something went wrong!',
|
||||
\ },
|
||||
\ ]})
|
||||
\ ]}})
|
||||
|
||||
Execute(ale#lsp#response#ReadDiagnostics() should handle warnings):
|
||||
AssertEqual ['filename.ts', [
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'type': 'W',
|
||||
\ 'text': 'Something went wrong!',
|
||||
@@ -41,18 +41,18 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle warnings):
|
||||
\ 'end_col': 4,
|
||||
\ 'nr': 'some-warning',
|
||||
\ }
|
||||
\ ]],
|
||||
\ ale#lsp#response#ReadDiagnostics({'uri': 'filename.ts', 'diagnostics': [
|
||||
\ ],
|
||||
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
|
||||
\ {
|
||||
\ 'severity': 2,
|
||||
\ 'range': Range(1, 3, 1, 3),
|
||||
\ 'code': 'some-warning',
|
||||
\ 'message': 'Something went wrong!',
|
||||
\ },
|
||||
\ ]})
|
||||
\ ]}})
|
||||
|
||||
Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing severity as errors):
|
||||
AssertEqual ['filename.ts', [
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Something went wrong!',
|
||||
@@ -62,17 +62,17 @@ Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing se
|
||||
\ 'end_col': 16,
|
||||
\ 'nr': 'some-error',
|
||||
\ }
|
||||
\ ]],
|
||||
\ ale#lsp#response#ReadDiagnostics({'uri': 'filename.ts', 'diagnostics': [
|
||||
\ ],
|
||||
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
|
||||
\ {
|
||||
\ 'range': Range(2, 10, 4, 15),
|
||||
\ 'code': 'some-error',
|
||||
\ 'message': 'Something went wrong!',
|
||||
\ },
|
||||
\ ]})
|
||||
\ ]}})
|
||||
|
||||
Execute(ale#lsp#response#ReadDiagnostics() should handle messages without codes):
|
||||
AssertEqual ['filename.ts', [
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Something went wrong!',
|
||||
@@ -81,16 +81,16 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle messages without codes)
|
||||
\ 'end_lnum': 5,
|
||||
\ 'end_col': 16,
|
||||
\ }
|
||||
\ ]],
|
||||
\ ale#lsp#response#ReadDiagnostics({'uri': 'filename.ts', 'diagnostics': [
|
||||
\ ],
|
||||
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
|
||||
\ {
|
||||
\ 'range': Range(2, 10, 4, 15),
|
||||
\ 'message': 'Something went wrong!',
|
||||
\ },
|
||||
\ ]})
|
||||
\ ]}})
|
||||
|
||||
Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
|
||||
AssertEqual ['filename.ts', [
|
||||
AssertEqual [
|
||||
\ {
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'Something went wrong!',
|
||||
@@ -107,8 +107,8 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
|
||||
\ 'end_lnum': 2,
|
||||
\ 'end_col': 5,
|
||||
\ },
|
||||
\ ]],
|
||||
\ ale#lsp#response#ReadDiagnostics({'uri': 'filename.ts', 'diagnostics': [
|
||||
\ ],
|
||||
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
|
||||
\ {
|
||||
\ 'range': Range(0, 2, 0, 2),
|
||||
\ 'message': 'Something went wrong!',
|
||||
@@ -118,7 +118,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
|
||||
\ 'range': Range(1, 4, 1, 4),
|
||||
\ 'message': 'A warning',
|
||||
\ },
|
||||
\ ]})
|
||||
\ ]}})
|
||||
|
||||
Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver responses):
|
||||
AssertEqual [
|
||||
|
||||
@@ -372,6 +372,8 @@ Execute(PreProcess should accept tsserver LSP configuration):
|
||||
\ 'executable': 'x',
|
||||
\ 'command': 'x',
|
||||
\ 'lsp': 'tsserver',
|
||||
\ 'language_callback': 'x',
|
||||
\ 'project_root_callback': 'x',
|
||||
\}
|
||||
|
||||
AssertEqual 'tsserver', ale#linter#PreProcess(g:linter).lsp
|
||||
@@ -392,6 +394,8 @@ Execute(PreProcess should accept stdio LSP configuration):
|
||||
\ 'executable': 'x',
|
||||
\ 'command': 'x',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'language_callback': 'x',
|
||||
\ 'project_root_callback': 'x',
|
||||
\}
|
||||
|
||||
AssertEqual 'stdio', ale#linter#PreProcess(g:linter).lsp
|
||||
@@ -411,6 +415,8 @@ Execute(PreProcess should accept LSP server configurations):
|
||||
\ 'name': 'x',
|
||||
\ 'lsp': 'socket',
|
||||
\ 'address_callback': 'X',
|
||||
\ 'language_callback': 'x',
|
||||
\ 'project_root_callback': 'x',
|
||||
\}
|
||||
|
||||
AssertEqual 'socket', ale#linter#PreProcess(g:linter).lsp
|
||||
|
||||
16
test/test_path_uri.vader
Normal file
16
test/test_path_uri.vader
Normal file
@@ -0,0 +1,16 @@
|
||||
Execute(ale#path#ToURI should work for Windows paths):
|
||||
AssertEqual 'file:///C:/foo/bar/baz.tst', ale#path#ToURI('C:\foo\bar\baz.tst')
|
||||
AssertEqual 'foo/bar/baz.tst', ale#path#ToURI('foo\bar\baz.tst')
|
||||
|
||||
Execute(ale#path#ToURI should work for Unix paths):
|
||||
AssertEqual 'file:///foo/bar/baz.tst', ale#path#ToURI('/foo/bar/baz.tst')
|
||||
AssertEqual 'foo/bar/baz.tst', ale#path#ToURI('foo/bar/baz.tst')
|
||||
|
||||
Execute(ale#path#ToURI should keep safe characters):
|
||||
AssertEqual '//a-zA-Z0-9$-_.!*''(),', ale#path#ToURI('\/a-zA-Z0-9$-_.!*''(),')
|
||||
|
||||
Execute(ale#path#ToURI should percent encode unsafe characters):
|
||||
AssertEqual '%20%2b%3a%3f%26%3d', ale#path#ToURI(' +:?&=')
|
||||
|
||||
Execute(ale#path#FromURI should decode percent encodings):
|
||||
AssertEqual ' +:?&=', ale#path#FromURI('%20%2b%3a%3f%26%3d')
|
||||
@@ -1,8 +1,15 @@
|
||||
Before:
|
||||
silent! cd /testplugin/test/util
|
||||
let g:dir = getcwd()
|
||||
|
||||
After:
|
||||
silent execute 'cd ' . fnameescape(g:dir)
|
||||
unlet! g:dir
|
||||
|
||||
Execute(CdString should output the correct command string):
|
||||
AssertEqual 'cd ''/foo bar/baz'' && ', ale#path#CdString('/foo bar/baz')
|
||||
|
||||
Execute(BufferCdString should output the correct command string):
|
||||
AssertEqual 'cd ' . shellescape(getcwd()) . ' && ', ale#path#BufferCdString(bufnr(''))
|
||||
call ale#test#SetFilename('foo.txt')
|
||||
|
||||
AssertEqual 'cd ' . shellescape(g:dir) . ' && ', ale#path#BufferCdString(bufnr(''))
|
||||
|
||||
Reference in New Issue
Block a user