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

Finding function declarations #57

Open
iulian3144 opened this issue Apr 20, 2022 · 4 comments
Open

Finding function declarations #57

iulian3144 opened this issue Apr 20, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@iulian3144
Copy link

I would like to find function declarations only but it seems that weggli does not support this at the moment.

What I have tried:
$ weggli -R func=myFoo '_ $func(_);' .

If this is indeed not supported, an enhancement would be nice even though this may be a little out of scope for the tool (based on its description).

@arizvisa
Copy link

If you run weggli with verbosity turned on, your query is probably getting normalized into a compound_statement. If you're looking for content outside of a compound_statement, you might be able to trim out that logic in parse_search_pattern (src/main.rs).

I'm not sure, but you also might need to anchor to a different tree-sitter-c rule which are those things listed in VALID_NODE_KINDS (src/main.rs). Weggli is anchoring to the definitions themselves, so declarations might be out of scope.

@iulian3144
Copy link
Author

Just adding "declaration" in the VALID_NODE_KINDS makes it work. Thanks a lot for the hint, @arizvisa.
I can see why this behavior would not be desired by default but maybe it would be nice to at least have a flag that enables this.
I think that something like --list-kinds / --kinds (similar to ctags) would work great.

$ weggli --list-kinds
d declaration         [off]
p compound_statement  [on]
f function_definition [on]
s struct_specifier    [on]
e enum_specifier      [on]
u union_specifier     [on]
c class_specifier     [on]

$ weggli --kinds=+d-u --list-kinds
d declaration         [on]
p compound_statement  [on]
f function_definition [on]
s struct_specifier    [on]
e enum_specifier      [on]
u union_specifier     [off]
c class_specifier     [on]

@arizvisa
Copy link

arizvisa commented Jul 22, 2022

Yeah, agreed. Having variable granularity on what's considered an anchor point when filtering your query is pretty useful.

Very cool that it worked out. I've had to patch it similarly so that I could chain queries together via sh pipeline ([definition|specifier] -> [declaration|expression]). Something like that anyways.

@felixwilhelm felixwilhelm added the enhancement New feature or request label Jul 28, 2022
@felixwilhelm
Copy link
Collaborator

Thanks for the bug report and sorry for the slow response. I didn't have much time to work on weggli in the last weeks.

I think disabling the VALID_NODE_KINDS check + anchoring based on a flag would solve this. I'll take a stab at this, but it might take a bit before I find the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants