sourcegraph / doctree

First-class library documentation for every language (based on tree-sitter), with symbol search & more. Lightweight single binary, run locally or self-host. Surfaces usage examples via Sourcegraph.
https://doctree.org
Apache License 2.0
872 stars 25 forks source link

WIP: Still failed trying to capture @class_docs #51

Closed joshuabezaleel closed 2 years ago

joshuabezaleel commented 2 years ago
joshuabezaleel commented 2 years ago

This was still really much of a work in progress so I am really sorry in advance for all of the commented code and log print 😞 @slimsag

slimsag commented 2 years ago

OK cool, this helped a lot. Here's what I did:

First, I ran this on a Java repo - and it error'd out, as you said it would.

Then I tried removing parts of the query, and it worked, like I thought:

image

So why do those parts of the query not work? I added some code to capture the full @doc and print that capture to see what nodes are available, my full changes looked like this:

image

This spammed my terminal with a ton of nodes, but one thing I noticed was that some of the nodes look like this:

nsequence: (block (comment) (comment) (comment) (comment) (comment) (comment) (return_statement (true)))))) (return_statement (false))))))]

I thought it was strange that (comment) differed from our original query for (block_comment), and so I thought maybe the grammar was outdated: I found the Java grammar here and searched for block_comment to see if that node exists, and it does here:

image

Now it starts to look a bit more clear: comment can describe either a line_comment or a block_comment, so if a block_comment doesn't exist..? Well, then we'd get that error. I tried that change, and it works! 🥳

image

Hope that helps @joshuabezaleel ! Let me know if you have any questions, I'll close this PR - feel free to create a new one whenever

slimsag commented 2 years ago

As for why this worked on the playground.. I suspect the playground is out of date, and the Java grammar used by tree-sitter-go is more recent, but I'm not 100% sure :)