From: Andreas Louv <andreas@louv.dk>
Date: Mon, 10 Apr 2023 17:56:07 +0000 (+0200)
Subject: Add ":LspShowServer initializeRequest"
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f5fea6ec61d2266e38924c679babf3aefc3724bb;p=vim-lsp.git

Add ":LspShowServer initializeRequest"

Since it's now possible to add "rootSearch" which changes the rootUri
that is being send to the server I think it makes sense to be able to
easily get to this information. I imagine it will be useful when people
are reporting issues.

It might make sense to request people, that are doing bug reports, to
include the information from:

	:LspShowServer status
	:LspShowServer initializeRequest
	:LspShowServer capabilities
---

diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim
index ca36ae4..8d9c65c 100644
--- a/autoload/lsp/lsp.vim
+++ b/autoload/lsp/lsp.vim
@@ -172,6 +172,8 @@ export def ShowServer(arg: string)
     :echomsg msg
   elseif arg ==? 'capabilities'
     lspserver.showCapabilities()
+  elseif arg ==? 'initializeRequest'
+    lspserver.showInitializeRequest()
   elseif arg ==? 'messages'
     lspserver.showMessages()
   else
diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim
index 20e00fd..576ba90 100644
--- a/autoload/lsp/lspserver.vim
+++ b/autoload/lsp/lspserver.vim
@@ -189,6 +189,8 @@ def InitServer(lspserver: dict<any>, bnr: number)
     initparams.initializationOptions = lspserver.initializationOptions
   endif
 
+  lspserver.rpcInitializeRequest = initparams
+
   lspserver.rpc_a('initialize', initparams, ServerInitReply)
 enddef
 
@@ -1416,6 +1418,23 @@ def ShowCapabilities(lspserver: dict<any>)
   :setlocal nomodifiable
 enddef
 
+# Display the LSP server initialize request and result
+def ShowInitializeRequest(lspserver: dict<any>)
+  OpenScratchWindow($'LangServer-{lspserver.name}-Initialize-Request')
+  var l = []
+  var heading = $"'{lspserver.path}' Language Server Initialize Requst"
+  var underlines = repeat('=', heading->len())
+  l->extend([heading, underlines])
+  if lspserver->has_key('rpcInitializeRequest')
+    for k in lspserver.rpcInitializeRequest->keys()->sort()
+      l->add($'{k}: {lspserver.rpcInitializeRequest[k]->string()}')
+    endfor
+  endif
+  setline(1, l)
+  :setlocal nomodified
+  :setlocal nomodifiable
+enddef
+
 # Display the log messages received from the LSP server (window/logMessage)
 def ShowMessages(lspserver: dict<any>)
   if lspserver.messages->empty()
@@ -1562,6 +1581,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list<string>,
     executeCommand: function(ExecuteCommand, [lspserver]),
     workspaceConfigGet: function(WorkspaceConfigGet, [lspserver]),
     showCapabilities: function(ShowCapabilities, [lspserver]),
+    showInitializeRequest: function(ShowInitializeRequest, [lspserver]),
     showMessages: function(ShowMessages, [lspserver])
   })
 
diff --git a/plugin/lsp.vim b/plugin/lsp.vim
index d70cc80..37636e3 100644
--- a/plugin/lsp.vim
+++ b/plugin/lsp.vim
@@ -66,7 +66,7 @@ enddef
 
 # Command line completion function for the LspShowServer command.
 def LspShowServerComplete(arglead: string, cmdline: string, cursorpos: number): list<string>
-  var l = ['capabilities', 'messages', 'status']
+  var l = ['capabilities', 'initializeRequest', 'messages', 'status']
   if arglead->empty()
     return l
   else