Skip to content

Commit

Permalink
Merge pull request #33 from kiennq/bug/dont-use-ivy-update
Browse files Browse the repository at this point in the history
Don't use `ivy-configure' + display-transformer and undocumented ivy-update-candidates
  • Loading branch information
sebastiansturm authored May 18, 2021
2 parents 4dcb635 + e759d94 commit bccd860
Showing 1 changed file with 21 additions and 39 deletions.
60 changes: 21 additions & 39 deletions lsp-ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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.
Expand Down

0 comments on commit bccd860

Please sign in to comment.