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
[LFX] [Track] Provide Quick Fix for Parse Errors #1125
Comments
please assign @Peefy |
I have some doubts on how to implement this:
cc @He1pa |
I'm not sure if all fixes can be expressed just in suggestions. and whether there is enough information to generate suggestions when the error is generated. Like I said before, you may be able to determine the fix solution after parsing the entire expr or stmt.
|
Thanks for clarifying. I'm working on refining this also I've already classified some fixes. Once I refine this approach further, I plan to open a PR with the refactoring changes and then start working on each fix individually. I'll update here with any further developments. |
Hey @He1pa #[derive(Debug, Clone)]
pub enum ParseError {
UnexpectedToken {
expected: Vec<String>,
got: String,
span: Span,
},
Message {
message: String,
span: Span,
fix_info: Option<FixInfo>,
},
}
#[derive(Debug, Clone)]
pub struct FixInfo {
pub error_kind: ErrorKind, // or something specific to particular error.
pub code_snippet: String,
} Is this approach fine? or just simply this: Message {
message: String,
span: Span,
error_kind: ErrorKind, // or something specific to particular error.
code_snippet: String,
}, |
Need some help with this on how to implement quick fixes for these kind of errors: cc @Peefy @He1pa
|
Here I am listing a few Parse errors for which quick fixes can be made with simple text replacements Quick fixes that can be implemented by simple text replacements
Reprduced by:
Quick fix: Replace
Quick fix: Replace whitespaces with
Quick Fix: Remove unexpected character after line continuation character.
Quick Fix: Remove semi colon from the suggested replacement.
Quick fix: Replace |
I don't understand your question. Here, only need to replace the mismatched parentheses, brackets and braces, and |
Enhancement
Add Quick fixes for Parser errors.
Framework:
Changes:
ParseError
enum to include a field forsuggestions
in both variantsUnexpectedToken
andMessage
.struct_span_error
function is modified to includegenerate_suggestion
to generate the appropriate suggestion.struct_span_error
andstruct_token_error
to provide suggestion for quick fix.generate_suggestion
function takesmsg
andspan
as parameters and uses a match statement to generate a specific suggestion based on the message string.add_parse_err
function to includeerror_kind
parameter and convertParseError
into a diagnostic based on theErrorKind
:impl ParseError
to have functions for convertingParseError
into a diagnostic based on theErrorKind
.CodeSnippet
and returns it as aString
.suggestion
is passed as aOption<Vec<String>>
to diagnostic which is then stored in the data field of LSP diagnostic into_lsp.rs
quick_fix.rs
handle quick_fix for each error kind.The text was updated successfully, but these errors were encountered: