]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Convert another flaky typescript test to a go test
authorAndreas Louv <andreas@louv.dk>
Sun, 2 Apr 2023 21:24:14 +0000 (23:24 +0200)
committerAndreas Louv <andreas@louv.dk>
Sun, 2 Apr 2023 21:38:51 +0000 (23:38 +0200)
The TypeScript tests are flaky as soon as they require diagnostics, as
the diagnostic notification takes to long to be send by the server.

test/gopls_tests.vim
test/tsserver_tests.vim

index a574009a1dbd1737790b99f755a0514f88683e5e..00fb2c2d06988339c57ea18b6035c0732e8cbe8f 100644 (file)
@@ -12,6 +12,8 @@ call LspAddServer(lspServers)
 echomsg systemlist($'{lspServers[0].path} version')
 
 # Test for :LspGotoDefinition, :LspGotoDeclaration, etc.
+# This test also tests that multiple locations will be
+# shown in a list or popup
 def g:Test_LspGoto()
   :silent! edit Xtest.go
   sleep 200m
@@ -19,11 +21,19 @@ def g:Test_LspGoto()
   var lines =<< trim END
     package main
 
-    func foo() {
+    type A/*goto implementation*/ interface {
+            Hello()
     }
 
-    func bar() {
-       foo();
+    type B struct{}
+
+    func (b *B) Hello() {}
+
+    type C struct{}
+
+    func (c *C) Hello() {}
+
+    func main() {
     }
   END
   
@@ -31,11 +41,62 @@ def g:Test_LspGoto()
   :redraw!
   g:WaitForServerFileLoad(0)
 
-  cursor(7, 1)
+  cursor(9, 10)
   :LspGotoDefinition
-  assert_equal([3, 6], [line('.'), col('.')])
+  assert_equal([7, 6], [line('.'), col('.')])
   exe "normal! \<C-t>"
-  assert_equal([7, 1], [line('.'), col('.')])
+  assert_equal([9, 10], [line('.'), col('.')])
+
+  cursor(9, 13)
+  :LspGotoImpl
+  assert_equal([4, 9], [line('.'), col('.')])
+
+  cursor(13, 13)
+  :LspGotoImpl
+  assert_equal([4, 9], [line('.'), col('.')])
+
+  # Two implementions needs to be shown in a location list
+  cursor(4, 9)
+  assert_equal('', execute('LspGotoImpl'))
+  sleep 200m
+  var loclist: list<dict<any>> = getloclist(0)
+  assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
+  assert_equal(2, loclist->len())
+  assert_equal(bufnr(), loclist[0].bufnr)
+  assert_equal([9, 13, ''], [loclist[0].lnum, loclist[0].col, loclist[0].type])
+  assert_equal([13, 13, ''], [loclist[1].lnum, loclist[1].col, loclist[1].type])
+  lclose
+
+  # Two implementions needs to be shown in a quickfix list
+  g:LspOptionsSet({ useQuickfixForLocations: true })
+  cursor(4, 9)
+  assert_equal('', execute('LspGotoImpl'))
+  sleep 200m
+  var qfl: list<dict<any>> = getqflist()
+  assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
+  assert_equal(2, qfl->len())
+  assert_equal(bufnr(), qfl[0].bufnr)
+  assert_equal([9, 13, ''], [qfl[0].lnum, qfl[0].col, qfl[0].type])
+  assert_equal([13, 13, ''], [qfl[1].lnum, qfl[1].col, qfl[1].type])
+  cclose
+  g:LspOptionsSet({ useQuickfixForLocations: false })
+
+  # Two implementions needs to be peeked in a popup
+  cursor(4, 9)
+  :LspPeekImpl
+  sleep 10m
+  var ids = popup_list()
+  assert_equal(2, ids->len())
+  var filePopupAttrs = ids[0]->popup_getoptions()
+  var refPopupAttrs = ids[1]->popup_getoptions()
+  assert_match('Xtest', filePopupAttrs.title)
+  assert_match('Implementation', refPopupAttrs.title)
+  assert_equal(9, line('.', ids[0])) # current line in left panel
+  assert_equal(2, line('$', ids[1])) # last line in right panel
+  feedkeys("j\<CR>", 'xt')
+  assert_equal(13, line('.'))
+  assert_equal([], popup_list())
+  popup_clear()
 
   bw!
 enddef
index c286d86790dc227461ae7d9e8b61c1031ba34fed..99e28368beeba952da377a3d0d0f28582ef8ff14 100644 (file)
@@ -13,88 +13,6 @@ var lspServers = [{
 call LspAddServer(lspServers)
 echomsg systemlist($'{lspServers[0].path} --version')
 
-# Test for :LspGotoDefinition, :LspGotoDeclaration, etc.
-def g:Test_LspGoto()
-  :silent! edit Xtest.ts
-  sleep 200m
-
-  var lines: list<string> = [
-    'function B(val: number): void;',
-    'function B(val: string): void;',
-    'function B(val: string | number) {',
-    '  console.log(val);',
-    '  return void 0;',
-    '}',
-    'typeof B;',
-    'B(1);',
-    'B("1");'
-  ]
-
-  setline(1, lines)
-  :redraw!
-  g:WaitForServerFileLoad(0)
-
-  cursor(8, 1)
-  assert_equal('', execute('LspGotoDefinition'))
-  assert_equal([1, 10], [line('.'), col('.')])
-
-  cursor(9, 1)
-  assert_equal('', execute('LspGotoDefinition'))
-  assert_equal([2, 10], [line('.'), col('.')])
-
-  cursor(9, 1)
-  assert_equal('', execute('LspGotoDefinition'))
-  assert_equal([2, 10], [line('.'), col('.')])
-
-  cursor(7, 8)
-  assert_equal('', execute('LspGotoDefinition'))
-  sleep 200m
-  var loclist: list<dict<any>> = getloclist(0)
-  assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
-  assert_equal(3, loclist->len())
-  assert_equal(bufnr(), loclist[0].bufnr)
-  assert_equal([1, 10, ''], [loclist[0].lnum, loclist[0].col, loclist[0].type])
-  assert_equal([2, 10, ''], [loclist[1].lnum, loclist[1].col, loclist[1].type])
-  assert_equal([3, 10, ''], [loclist[2].lnum, loclist[2].col, loclist[2].type])
-  lclose
-
-  g:LspOptionsSet({ useQuickfixForLocations: true })
-  cursor(7, 8)
-  assert_equal('', execute('LspGotoDefinition'))
-  sleep 200m
-  var qfl: list<dict<any>> = getqflist()
-  assert_equal('quickfix', getwinvar(winnr('$'), '&buftype'))
-  assert_equal(3, qfl->len())
-  assert_equal(bufnr(), qfl[0].bufnr)
-  assert_equal([1, 10, ''], [qfl[0].lnum, qfl[0].col, qfl[0].type])
-  assert_equal([2, 10, ''], [qfl[1].lnum, qfl[1].col, qfl[1].type])
-  assert_equal([3, 10, ''], [qfl[2].lnum, qfl[2].col, qfl[2].type])
-  cclose
-  g:LspOptionsSet({ useQuickfixForLocations: false })
-
-  # Opening the preview window with an unsaved buffer displays the "E37: No
-  # write since last change" error message.  To disable this message, mark the
-  # buffer as not modified.
-  setlocal nomodified
-  cursor(7, 8)
-  :LspPeekDefinition
-  sleep 10m
-  var ids = popup_list()
-  assert_equal(2, ids->len())
-  var filePopupAttrs = ids[0]->popup_getoptions()
-  var refPopupAttrs = ids[1]->popup_getoptions()
-  assert_match('Xtest', filePopupAttrs.title)
-  assert_match('Definitions', refPopupAttrs.title)
-  assert_equal(1, line('.', ids[0]))
-  assert_equal(3, line('$', ids[1]))
-  feedkeys("jj\<CR>", 'xt')
-  assert_equal(3, line('.'))
-  assert_equal([], popup_list())
-  popup_clear()
-
-  bw!
-enddef
-
 # Test for auto-completion.  Make sure that only keywords that matches with the
 # keyword before the cursor are shown.
 # def g:Test_LspCompletion1()