From e759d94253786ab623eb573e4b637ccb39bf620b Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Wed, 4 Nov 2020 14:50:20 +0100 Subject: [PATCH] Don't use `ivy-configure' + display-transformer and undocumented ivy-update-candidates --- lsp-ivy.el | 60 +++++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/lsp-ivy.el b/lsp-ivy.el index 5c5ad16..ff937cf 100644 --- a/lsp-ivy.el +++ b/lsp-ivy.el @@ -122,13 +122,7 @@ SymbolKind (defined in the LSP)." (cons string face) (cons string face))) -(eval-when-compile - (lsp-interface - (lsp-ivy:FormattedSymbolInformation - (:kind :name :location :textualRepresentation) - (:containerName :deprecated)))) - -(lsp-defun lsp-ivy--workspace-symbol-action +(lsp-defun lsp-ivy--goto-symbol ((&SymbolInformation :location (&Location :uri :range (&Range :start (&Position :line :character))))) "Jump to selected candidate." @@ -153,58 +147,46 @@ SymbolKind (defined in the LSP)." (lsp-defun lsp-ivy--transform-candidate ((symbol-information &as &SymbolInformation :kind) filter-regexps? workspace-root) - "Map candidate to nil if it should be excluded based on `lsp-ivy-filter-symbol-kind' or -FILTER-REGEXPS?, otherwise convert it to an `lsp-ivy:FormattedSymbolInformation' object." + "Map candidate to nil if it should be excluded based on +`lsp-ivy-filter-symbol-kind' or FILTER-REGEXPS?, otherwise convert it to a +textual representation with the original candidate as property." (unless (member kind lsp-ivy-filter-symbol-kind) (let ((textual-representation (lsp-ivy--format-symbol-match symbol-information workspace-root))) (when (--all? (string-match-p it textual-representation) filter-regexps?) - (lsp-put symbol-information :textualRepresentation textual-representation) - symbol-information)))) + (propertize textual-representation 'lsp-ivy-symbol symbol-information))))) + +(defun lsp-ivy--workspace-symbol-action (sym-string) + "Jump to the `&SymbolInformation' defined in SYM-STRING." + (lsp-ivy--goto-symbol (get-text-property 0 'lsp-ivy-symbol sym-string))) (defun lsp-ivy--workspace-symbol (workspaces prompt initial-input) "Search against WORKSPACES with PROMPT and INITIAL-INPUT." - (let* ((prev-query nil) + (let* ((non-essential t) + (prev-query nil) (unfiltered-candidates '()) - (filtered-candidates nil) - (workspace-root (lsp-workspace-root)) - (update-candidates - (lambda (all-candidates filter-regexps?) - (setq filtered-candidates - (--keep (lsp-ivy--transform-candidate it filter-regexps? workspace-root) - all-candidates)) - (ivy-update-candidates filtered-candidates)))) + (workspace-root (lsp-workspace-root))) (ivy-read prompt (lambda (user-input) (let* ((parts (split-string user-input)) (query (or (car parts) "")) (filter-regexps? (mapcar #'regexp-quote (cdr parts)))) - (when query - (if (string-equal prev-query query) - (funcall update-candidates unfiltered-candidates filter-regexps?) - (with-lsp-workspaces workspaces - (lsp-request-async - "workspace/symbol" - (lsp-make-workspace-symbol-params :query query) - (lambda (result) - (setq unfiltered-candidates result) - (funcall update-candidates unfiltered-candidates filter-regexps?)) - :mode 'detached - :cancel-token :workspace-symbol)))) - (setq prev-query query)) - (or filtered-candidates 0)) + (unless (string-equal prev-query query) + (setq unfiltered-candidates + (with-lsp-workspaces workspaces + (lsp-request-while-no-input + "workspace/symbol" + (lsp-make-workspace-symbol-params :query query))))) + (setq prev-query query) + (--keep (lsp-ivy--transform-candidate it filter-regexps? workspace-root) + unfiltered-candidates))) :dynamic-collection t :require-match t :initial-input initial-input :action #'lsp-ivy--workspace-symbol-action :caller 'lsp-ivy-workspace-symbol))) -(ivy-configure 'lsp-ivy-workspace-symbol - :display-transformer-fn - (-lambda ((&lsp-ivy:FormattedSymbolInformation :textual-representation)) - textual-representation)) - ;;;###autoload (defun lsp-ivy-workspace-symbol (arg) "`ivy' for lsp workspace/symbol.