Skip to content

Commit

Permalink
Add proper support for the 'window/showMessageRequest' message
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Oct 3, 2024
1 parent 94177b3 commit e34c17e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions autoload/lsp/handlers.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e34c17e

Please sign in to comment.