Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use `ivy-configure' + display-transformer and undocumented ivy-update-candidates #32

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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