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

Cannot detect declarations in other files #10

Open
Elsie19 opened this issue May 11, 2024 · 4 comments
Open

Cannot detect declarations in other files #10

Elsie19 opened this issue May 11, 2024 · 4 comments

Comments

@Elsie19
Copy link

Elsie19 commented May 11, 2024

I have the following tree:

.
├── Cargo.lock
├── Cargo.toml
└── src
    ├── main.rs
    ├── parse
    │   ├── grammar.rs
    │   └── internals
    │       ├── base.pest
    │       ├── command_substitution.pest
    │       ├── strings.pest
    │       └── variables.pest
    └── parse.rs

In src/parse/grammar.rs I have the following code:

use pest_derive::Parser;

#[derive(Parser)]
#[grammar = "parse/internals/strings.pest"]
#[grammar = "parse/internals/variables.pest"]
#[grammar = "parse/internals/command_substitution.pest"]
#[grammar = "parse/internals/base.pest"]
pub struct ElviParser;

Notice the placement of strings.pest and variables.pest: how variables.pest is defined after strings.pest.

If I edit variables.pest, I get the following error:

// Main rules
normalVariable = @{ variableIdent ~ "=" ~ anyString }   ■ Rule anyString is undefined

variableIdent = { !ASCII_DIGIT ~ (ASCII_ALPHANUMERIC | "_")+ }

Where anyString is defined in strings.pest. It compiles correctly, it's just the LSP not understanding this.

@tomtau
Copy link

tomtau commented May 12, 2024

I think this is due to pest-parser/pest-ide-tools#24 ?
@Jamalam360

@Jamalam360
Copy link

Yeah, the language server does not support split grammars. There is a comment on the issue that tomtau mentioned that explains why.

The solution for this would be for Pest files themselves to contain 'import' statements; something which I think is planned for Pest 3?

@Elsie19
Copy link
Author

Elsie19 commented May 12, 2024

Would you be able to put together something where if I put:

// import: from/src/grammar.pest

it would import from there or is that out of scope?

@Jamalam360
Copy link

It would need support on Pest's side - the LSP calls the Pest meta grammar and uses it's returned Pairs to get the location of symbols in the document.

It's doable on the LSP side with some refactoring, but the feature doesn't seem to be used all that often and if Pest 3 is around the corner it seems like a waste of time to be honest.

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

No branches or pull requests

3 participants