]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add proper support for the 'window/showMessageRequest' message
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 3 Oct 2024 05:47:09 +0000 (22:47 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 3 Oct 2024 05:47:09 +0000 (22:47 -0700)
autoload/lsp/handlers.vim

index dd597ed5ddcd86be3dfc797b2a3b7fc8645844be..f110d0400b89efdab27e289fc7bf085396618707 100644 (file)
@@ -205,11 +205,38 @@ enddef
 # process the window/showMessageRequest LSP server request
 # Request: "window/showMessageRequest"
 # Param: ShowMessageRequestParams
-def ProcessShowMessageRequest(lspserver: dict<any>, request: dict<any>)
-  # TODO: for now 'showMessageRequest' handled same like 'showMessage'
-  # regardless 'actions'
-  ProcessShowMsgNotif(lspserver, request)
-  lspserver.sendResponse(request, null, {})
+def ProcessShowMessageRequest(lspserver: dict<any>, req: dict<any>)
+  var params: dict<any> = req.params
+  if params->has_key('actions')
+    var actions: list<dict<any>> = params.actions
+    if actions->empty()
+      util.WarnMsg($'Empty actions in showMessage request {params.message}')
+      lspserver.sendResponse(req, null, {})
+      return
+    endif
+
+    # Generate a list of strings from the action titles
+    var text: list<string> = []
+    var act: dict<any>
+    for i in actions->len()->range()
+      act = actions[i]
+      var t: string = act.title->substitute('\r\n', '\\r\\n', 'g')
+      t = t->substitute('\n', '\\n', 'g')
+      text->add(printf(" %d. %s ", i + 1, t))
+    endfor
+
+    # Ask the user to choose one of the actions
+    var choice: number = inputlist([params.message] + text)
+    if choice < 1 || choice > text->len()
+      lspserver.sendResponse(req, null, {})
+      return
+    endif
+    lspserver.sendResponse(req, actions[choice - 1], {})
+  else
+    # No actions in the message. Simply display the message.
+    ProcessShowMsgNotif(lspserver, req)
+    lspserver.sendResponse(req, null, {})
+  endif
 enddef
 
 # process the client/registerCapability LSP server request