]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add test for "processDiagHandler"
authorAndreas Louv <andreas@louv.dk>
Sat, 20 May 2023 19:44:46 +0000 (21:44 +0200)
committerAndreas Louv <andreas@louv.dk>
Sat, 20 May 2023 21:15:23 +0000 (23:15 +0200)
test/clangd_tests.vim

index fe7c9474dbb4dcf57efb4342abf850c840b9906a..576086d6bd4e180554b55676795a6b7350f21389 100644 (file)
@@ -6,6 +6,8 @@ source common.vim
 var lspOpts = {autoComplete: false, highlightDiagInline: true}
 g:LspOptionsSet(lspOpts)
 
+g:LSPTest_modifyDiags = false
+
 var lspServers = [{
       filetype: ['c', 'cpp'],
       path: (exepath('clangd-15') ?? exepath('clangd')),
@@ -15,6 +17,16 @@ var lspServers = [{
         'textDocument/clangd.fileStatus': (lspserver: dict<any>, reply: dict<any>) => {
           g:LSPTest_customNotificationHandlerReplied = true
         }
+      },
+      processDiagHandler: (diags: list<dict<any>>) => {
+        if g:LSPTest_modifyDiags != true
+          return diags
+        endif
+
+        return diags->map((ix, diag) => {
+          diag.message = $'this is overridden'
+          return diag
+        })
       }
   }]
 call LspAddServer(lspServers)
@@ -314,6 +326,35 @@ def g:Test_LspDiag()
   :%bw!
 enddef
 
+# Test for LSP diagnostics handler
+def g:Test_LspProcessDiagHandler()
+  g:LSPTest_modifyDiags = true
+  g:LspOptionsSet({showDiagInPopup: false})
+
+  :silent! edit Xtest.c
+  sleep 200m
+  var lines: list<string> =<< trim END
+    void blueFunc()
+    {
+       int count, j:
+    }
+  END
+  setline(1, lines)
+  g:WaitForServerFileLoad(1)
+  :redraw!
+  normal gg
+
+  :LspDiagFirst
+  assert_equal([3, 14], [line('.'), col('.')])
+
+  var output = execute('LspDiagCurrent')->split("\n")
+  assert_equal("this is overridden", output[0])
+
+  g:LspOptionsSet({showDiagInPopup: true})
+  g:LSPTest_modifyDiags = false
+  :%bw!
+enddef
+
 # Test that the client have been able to configure the server to speak utf-32
 def g:Test_UnicodeColumnCalc()
   :silent! edit Xtest.c