-
Notifications
You must be signed in to change notification settings - Fork 120
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
Provide quick fix for invalid syntax error #1133
Provide quick fix for invalid syntax error #1133
Conversation
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
…-for-InvalidSyntaxError
The quick fix functionality is working fine with this approach. @Peefy, how should I proceed with this? Should I introduce a new field cc @He1pa |
I think this should be done through parser specific error generation expression instead of passing code snippets to LSP and then handing them over to LSP for judgment. cc @He1pa Can you help review this PR? Besides, I think we need to first clarify the list of syntax error recovery and the specific syntax recovery framework. cc @He1pa @shashank-iitbhu |
some advices:
|
Thank you for the feedback! @He1pa
|
Regarding this: let mut sb = StyledBuffer::<DiagnosticStyle>::new();
let mut errs = vec![];
let code_snippet = CodeSnippet::new(span, Arc::clone(&sess.sm));
code_snippet.format(&mut sb, &mut errs);
let code_line = extract_code_line(&sb); had to write a separate function to extract the code line from styled buffer: // Extract code line from styled buffer
fn extract_code_line(sb: &StyledBuffer<DiagnosticStyle>) -> String {
let rendered_lines = sb.render();
if let Some(line) = rendered_lines.get(0) {
if let Some(code_snippet) = line.get(1) {
code_snippet.text.clone()
} else {
String::new()
}
} else {
String::new()
}
} This was the output of
|
sorry,I just checked it, it should be this two functions: |
The |
This is how i was getting the fn get_line_content_from_span(&self, span: Span) -> String {
let source_file = self.0.sm.lookup_source_file(span.lo());
let line_index = source_file.lookup_line(span.lo()).unwrap(); But later @Peefy mentioned that we can use |
#1125 (comment) |
…-for-InvalidSyntaxError
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Hello @shashank-iitbhu Kind reminder, LXF 1 Term is one week away, are you still working on this PR? |
Yes, I am still working on this. Will complete the work before final evaluation. |
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Made some changes in the latest commit, and will let you know when it is ready for review. |
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Screen.Recording.2024-05-22.at.8.55.37.PM.movScreen.Recording.2024-05-22.at.9.07.08.PM.mov@Peefy need some reviews whenever you get time. |
Pull Request Test Coverage Report for Build 9194381538Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
@shashank-iitbhu Hello, I've added some comments. @He1pa Could you please add more comments. |
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Screen.Recording.2024-05-24.at.8.05.23.PM.movWill be adding more to this PR. |
Thank you. Besides, I think the position information in the quick fix msg can be ommitted. |
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
@shashank-iitbhu
|
1. Does this PR affect any open issues?(Y/N) and add issue references:
fix #1125
2. What is the scope of this PR (e.g. component or file name):
kclvm/parser/src/session/mod.rs
kclvm/tools/src/LSP/src/quick_fix.rs
kclvm/tools/src/LSP/src/to_lsp.rs
kclvm/error/src/lib.rs
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
Screen.Recording.2024-03-14.at.12.23.45.AM.mov
line_content
obtained byget_line_content_from_span
inkclvm/parser/src/session/mod.rs
into thenote
field ofMessage
struct.4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
I haven't handled the failing tests yet.
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links: