Skip to content

[Feature request] Support imenu #2

@theFool32

Description

@theFool32

Thanks for your effort on lspce. I wonder if there is any plan to support imenu.

I have made a simple try with the help of eglot as below (no robustness considered):

(defun lspce-imenu-create ()
       (mapcar
        (lambda (obj)
          (cons
           (cdr (assoc (car obj) lspce--symbol-kind-names))
           (mapcar
            (lambda (obj)
              (let ((content
                     (cons (gethash "name" obj)
                           (lspce--lsp-position-to-point
                            (gethash "start"
                                     (gethash "range"
                                              (gethash "location"
                                                       obj))))))
                    (container (gethash "containerName" obj)))
                (if container
                    (list container content)
                  content)))
            (cdr obj))))

        (seq-group-by
         (lambda (obj) (gethash "kind" obj))
         (lspce--request "textDocument/documentSymbol" (list :textDocument (lspce--textDocumentIdenfitier (lspce--uri)))))))
                              

(add-function :before-until (local 'imenu-create-index-function)  #'lspce-imenu-create)

It works like
image

However, it remains two problems:

  1. lspce--request returns range without selectRange (compared with eglot), which leads to jumping to "|class CLS" instead of "class |CLS" (| denotes for the cursor)
  2. containerName only includes the direct father node. So just fun::var instead of CLS::fun::var.

Do you have any suggestions for them? Or maybe the whole part can be written in the rust part? (Sorry I haven't learned the rust)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions