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

Unrecognised rules with grammars split across multiple files #24

Open
tomtau opened this issue Apr 24, 2023 · 11 comments
Open

Unrecognised rules with grammars split across multiple files #24

tomtau opened this issue Apr 24, 2023 · 11 comments
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@tomtau
Copy link

tomtau commented Apr 24, 2023

When rules defined in one pest file are used in a different pest file, as per https://pest.rs/book/grammars/grammars.html#load-multiple-grammars
( e.g. https://github.com/pest-parser/pest/blob/master/derive/examples/base.pest which is then used in https://github.com/pest-parser/pest/blob/master/derive/examples/calc.pest ), the extension will report errors of undefined rules for the names defined in a different file (even though there is no problem when building it thanks to pest-parser/pest#758 )

@tomtau tomtau added the bug Something isn't working label Apr 24, 2023
@Jamalam360
Copy link
Contributor

This is hard because there isn't an import statement in the pest files, it is defined in the attribute in Rust...hmm. It is a similar issue as the inline grammar problem - we don't have infrastructure to communicate with Rust Analyzer and iirc there are open issues for that on the RA repo.

If I did remember that correctly, we might have to put in a temporary solution like adding a //@pest-ls include <file path> but that's not ideal :/

@tomtau
Copy link
Author

tomtau commented Apr 26, 2023

Can there be a plugin config for users to specify whether or which grammars to load together?

@Jamalam360
Copy link
Contributor

Maybe yeah

@tomtau
Copy link
Author

tomtau commented Apr 26, 2023

@Jamalam360
Copy link
Contributor

We already have some config so this will be fine.

I'd like to keep a track of those RA issues that might allow a kind of plugin system though

@Jamalam360
Copy link
Contributor

Jamalam360 commented Apr 28, 2023

As far as I can tell, linked grammars work by just doing grammar_one_string + grammar_two_string. This is difficult for the LS:

// one
test = { "a" ~ test_two }
// two
test_two = { "b" }

Result:

// one
test = { "a" ~ test_two }
// two
test_two = { "b" }

Imagine we want to rename test_two. This will cause edits in file one like this:

// one
test = { "a" ~ test_two }
renamed_name

Since the LSP thinks that test_two is there. I'm not sure how we want to handle this.

We might need to rethink the pest_meta parser API (to take a Vec<Pairs<_>>?) and/or the way linked grammars work, unless someone has a suggestion.

@tomtau
Copy link
Author

tomtau commented Apr 28, 2023

Would the meta-grammar extension ("use base") help? One issue for that is how to interpret it in the file-less pest_vm environments.

@Jamalam360
Copy link
Contributor

If there was an explicit import statement, the LSP would probably not require any modifications for this issue to be fixed. I'm not sure what the best way forward is. Maybe a poll in the server again

@tomtau
Copy link
Author

tomtau commented Apr 28, 2023

@huacnlee any thoughts?

@Jamalam360
Copy link
Contributor

Jamalam360 commented Apr 28, 2023

It would also make more semantic sense to have a dedicated statement arguably

@Jamalam360
Copy link
Contributor

This should probably be revisited with Pest V3, it seems too awkward to fix for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants