GithubHelp home page GithubHelp logo

Comments (8)

DamienCassou avatar DamienCassou commented on April 26, 2024 3

Imenu support would be really great

from elisp-tree-sitter.

ubolonton avatar ubolonton commented on April 26, 2024 3

I still haven't looked into #199 in details, but like @mohkale noted in that issue, I think arbitrary recursion is the single biggest challenge, specifically capturing the full paths of all nested items, not just the leaf identifiers. Queries alone are probably not expressive enough, so some sort of principled extension would be needed. On that front, I think it's worth exploring the newly introduced stack graphs, and the related graph DSL:

(function_definition
  name: (identifier) @name) @function
{
    node @function.def
    attr (@function.def) kind = "definition"
    attr (@function.def) symbol = @name
    edge @function.containing_scope -> @function.def
}

I went through associated StrangeLoop talk. @dcreager illustrated the concepts very well.

from elisp-tree-sitter.

jakejx avatar jakejx commented on April 26, 2024

Hi! I was playing around with this to try and see what kind of imenu integration I can get going, but I am getting a (wrong-type-argument user-ptrp nil) when running a test function, with the following stacktrace:

  ts-make-query(nil [(function_item (identifier) @name)])
  tree-sitter-query([(function_item (identifier) @name)])
  (seq-map #'(lambda (capture) (let* ((x474 (car capture)) (x475 (cdr capture))) (let ((node x475)) (progn (print ts-node-text node) (cons (ts-node-text node) (ts-node-start-position node)))))) (tree-sitter-query [(function_item (identifier) @name)]))
  (save-current-buffer (set-buffer (current-buffer)) (seq-map #'(lambda (capture) (let* ((x474 (car capture)) (x475 (cdr capture))) (let ((node x475)) (progn (print ts-node-text node) (cons ... ...))))) (tree-sitter-query [(function_item (identifier) @name)])))
  ts-identifiers()

It seems that the error is coming from within the Rust module? So I am not sure how I should go about to debug.

For reference, this is what the function I'm testing looks like:

  (defun ts-identifiers()
    (interactive)
    (with-current-buffer (current-buffer)
      (seq-map (lambda (capture)
                 (pcase-let ((`(_ . ,node) capture))
                   (print ts-node-text node)
                   (cons (ts-node-text node) (ts-node-start-position node))))
               (tree-sitter-query [(function_item (identifier) @name)])))
    )

from elisp-tree-sitter.

ubolonton avatar ubolonton commented on April 26, 2024

This line ts-make-query(nil [(function_item (identifier) @name)]) means that tree-sitter-language was nil when tree-sitter-query called ts-make-query .

It probably means tree-sitter-mode was not turned on in that buffer.

Also note that tree-sitter-query is more like a debugging aid currently. It creates a new query object every time. You'd better off create a query object once, and use ts-query-matches or ts-query-captures instead.

from elisp-tree-sitter.

jakejx avatar jakejx commented on April 26, 2024

I see. Got it working again, thanks! Will start experimenting and move towards using tree-query-matches to get imenu integration working.

from elisp-tree-sitter.

mohkale avatar mohkale commented on April 26, 2024

I'm interested in implementing this. Do you have any tips for how to approach it? I was thinking maybe reusing the queries we use for highlighting (in emacs-tree-sitter/tree-sitter-langs) or adding a new file in the same place for imenu queries.

from elisp-tree-sitter.

mohkale avatar mohkale commented on April 26, 2024

@DamienCassou See #199. It's still at the draft stage and I'm not sure what the best approach moving forward should be :/.

from elisp-tree-sitter.

lshnmoptim avatar lshnmoptim commented on April 26, 2024

Hi! Is there any update on this feature? Thanks :)

from elisp-tree-sitter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.