From aafe7ffcaf1fa391f4f5573ece563d337c7fbb2a Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 28 Sep 2022 18:40:06 +1000 Subject: improving completion in hcel-ids --- hcel-client.el | 10 ++++++ hcel-results.el | 100 ++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 78 insertions(+), 32 deletions(-) diff --git a/hcel-client.el b/hcel-client.el index 532fc88..1e30167 100644 --- a/hcel-client.el +++ b/hcel-client.el @@ -68,6 +68,16 @@ (name (alist-get 'name approx-location-info))) (hcel-api-definition-site package-id component-id module-name entity name))) +(defun hcel-definition-site-external-id (external-id) + "Call definitionSite using external id." + (let* ((splitted (split-string external-id "|")) + (package-id (hcel-parse-package-id (car splitted) "-")) + (module-name (cadr splitted)) + (entity (caddr splitted)) + (name (cadddr splitted))) + (hcel-api-definition-site + package-id "lib" module-name entity name))) + (defun hcel-approx-to-exact-location (approx-location-info) "Fetch exact location given approximate location. diff --git a/hcel-results.el b/hcel-results.el index 3ebee43..be8e6cb 100644 --- a/hcel-results.el +++ b/hcel-results.el @@ -320,44 +320,80 @@ Start by choosing a package." (defvar hcel-ids--minibuffer-saved-query nil) (defvar hcel-ids--minibuffer-saved-results nil) -(defun hcel-ids-minibuffer-collection (scope query &optional package-id) +(defun hcel-ids--affixation-internal (scope items) + (mapcar + (lambda (item) + (let* ((location-info (get-text-property 0 'location-info item)) + (suffix + (propertize + (format + " :: %s" + (hcel-render-components (get-text-property 0 'components item))) + 'face 'completions-annotations)) + (prefix + (propertize + (if (eq scope 'global) + (format "(%s %s) " + (alist-get 'moduleName location-info) + (hcel-format-package-id + (alist-get 'packageId location-info) "-")) + (format "(%s) " + (alist-get 'moduleName location-info))) + 'face 'completions-annotations))) + (list (car (split-string item " ")) prefix suffix))) + items)) + +(defun hcel-ids--affixation-function (scope) + (lambda (items) + (hcel-ids--affixation-internal scope items))) + +(defun hcel-ids-minibuffer-collection (scope query action &optional package-id) (when (and (eq scope 'package) (not package-id)) (error "No package-id supplied for identifiers call!")) - (unless (length= query 0) - (if (string= hcel-ids--minibuffer-saved-query query) - hcel-ids--minibuffer-saved-results - (setq hcel-ids--minibuffer-saved-query query - hcel-ids--minibuffer-saved-results - (mapcar - (lambda (result) - (propertize - (alist-get 'demangledOccName result) - 'location-info (alist-get 'locationInfo result))) - (hcel-api-identifiers - scope query package-id nil - (number-to-string hcel-ids-live-per-page)))) - hcel-ids--minibuffer-saved-results))) - -(defun hcel-global-ids-minibuffer-collection (query &rest _) - (hcel-ids-minibuffer-collection 'global query)) + (if (eq action 'metadata) + (list 'metadata (cons 'affixation-function + (hcel-ids--affixation-function scope))) + (unless (length= query 0) + (if (string= hcel-ids--minibuffer-saved-query query) + hcel-ids--minibuffer-saved-results + (setq hcel-ids--minibuffer-saved-query query + hcel-ids--minibuffer-saved-results + (mapcar + (lambda (result) + (propertize + (format "%s %s" + (alist-get 'demangledOccName result) + (alist-get 'externalId result)) + 'location-info (alist-get 'locationInfo result) + 'components (alist-get 'components + (alist-get 'idType result)))) + (hcel-api-identifiers + scope query package-id nil + (number-to-string hcel-ids-live-per-page)))) + hcel-ids--minibuffer-saved-results)))) + +(defvar hcel-ids-selected-ids-location-info nil) + +(defun hcel-global-ids-minibuffer-collection (query pred action) + (hcel-ids-minibuffer-collection 'global query action)) (defun hcel-package-ids-minibuffer-collection (package-id) - (lambda (query &rest _) - (hcel-ids-minibuffer-collection 'package query package-id))) + (lambda (query pred action) + (hcel-ids-minibuffer-collection 'package query action package-id))) (defun hcel-ids (scope query &optional package-id) - (if (length= hcel-ids--minibuffer-saved-results 1) - (hcel-load-module-location-info - (with-temp-buffer - (insert (car hcel-ids--minibuffer-saved-results)) - (get-text-property (point-min) 'location-info))) - (let ((buffer-name (hcel-ids-buffer-name scope query))) - (with-current-buffer (get-buffer-create buffer-name) - (hcel-ids-mode) - (setq hcel-ids-scope scope - hcel-ids-package-id package-id) - (hcel-ids-update-query query)) - (switch-to-buffer buffer-name)))) + (let ((splitted (split-string query " "))) + (if (length= splitted 2) + (hcel-load-module-location-info + (alist-get 'location + (hcel-definition-site-external-id (cadr splitted)))) + (let ((buffer-name (hcel-ids-buffer-name scope query))) + (with-current-buffer (get-buffer-create buffer-name) + (hcel-ids-mode) + (setq hcel-ids-scope scope + hcel-ids-package-id package-id) + (hcel-ids-update-query (car splitted))) + (switch-to-buffer buffer-name))))) (defun hcel-global-ids (query) (interactive (list -- cgit v1.2.3