Skip to content

Commit

Permalink
Add default handlers for showInputBox and showQuickPick (#3345)
Browse files Browse the repository at this point in the history
* add default handlers for showInputBox and showQuickPick

* address review comments
  • Loading branch information
timfel committed Feb 13, 2022
1 parent a3c1f18 commit 335ec44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lsp-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,27 @@ regex in IGNORED-FILES."
(indent 1))
`(when-let ((lsp--cur-workspace ,workspace)) ,@body))

(lsp-defun lsp--window-show-quick-pick (_workspace (&ShowQuickPickParams :place-holder :can-pick-many :items))
(if-let* ((selectfunc (if can-pick-many #'completing-read-multiple #'completing-read))
(itemLabels (seq-map (-lambda ((item &as &QuickPickItem :label)) (format "%s" label))
items))
(result (funcall-interactively
selectfunc
(format "%s%s " place-holder (if can-pick-many " (* for all)" "")) itemLabels))
(choices (if (listp result)
(if (equal result '("*"))
itemLabels
result)
(list result))))
(vconcat (seq-filter #'identity (seq-map (-lambda ((item &as &QuickPickItem :label :user-data))
(if (member label choices)
(lsp-make-quick-pick-item :label label :picked t :user-data user-data)
nil))
items)))))

(lsp-defun lsp--window-show-input-box (_workspace (&ShowInputBoxParams :prompt :value?))
(read-string (format "%s: " prompt) (or value? "")))

(lsp-defun lsp--window-show-message (_workspace (&ShowMessageRequestParams :message :type))
"Send the server's messages to log.
PARAMS - the data sent from _WORKSPACE."
Expand Down Expand Up @@ -6174,6 +6195,8 @@ textDocument/didOpen for the new file."
(defconst lsp--default-notification-handlers
(ht ("window/showMessage" #'lsp--window-show-message)
("window/logMessage" #'lsp--window-log-message)
("window/showInputBox" #'lsp--window-show-input-box)
("window/showQuickPick" #'lsp--window-show-quick-pick)
("textDocument/publishDiagnostics" #'lsp--on-diagnostics)
("textDocument/diagnosticsEnd" #'ignore)
("textDocument/diagnosticsBegin" #'ignore)
Expand Down
3 changes: 3 additions & 0 deletions lsp-protocol.el
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ See `-let' for a description of the destructuring mechanism."
(PrepareRenameParams (:textDocument :position) (:uri))
(PrepareRenameResult (:range :placeholder) nil)
(PublishDiagnosticsParams (:diagnostics :uri) (:version))
(QuickPickItem (:label :picked :userData) nil)
(ReferenceParams (:textDocument :context :position) (:uri))
(RegistrationParams (:registrations) nil)
(RenameFile (:kind :newUri :oldUri) (:options))
Expand All @@ -745,7 +746,9 @@ See `-let' for a description of the destructuring mechanism."
(SemanticHighlightingParams (:textDocument :lines) nil)
(ShowDocumentParams (:uri) (:external :takeFocus :selection))
(ShowDocumentResult (:success) nil)
(ShowInputBoxParams (:prompt) (:value))
(ShowMessageRequestParams (:type :message) (:actions))
(ShowQuickPickParams (:placeHolder :canPickMany :items) nil)
(SignatureHelpParams (:textDocument :position) (:context :uri))
(SignatureHelpRegistrationOptions nil (:documentSelector :triggerCharacters))
(SymbolInformation (:kind :name :location) (:containerName :deprecated))
Expand Down

0 comments on commit 335ec44

Please sign in to comment.