-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ra_syntax: reshape SyntaxError for the sake of removing redundancy #3026
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
Conversation
| ) -> Vec<SyntaxError> { | ||
| let mut res = Vec::new(); | ||
| for e in old_errors { | ||
| if e.offset() <= old_range.start() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AHTUNG! I suppose in this if statement we had a mistake, we need to check that e.range().end() <= old_range.start() and I corrected it in this PR (tests pass anyway...)
| res.extend(new_errors.into_iter().map(|new_err| { | ||
| // fighting borrow checker with a variable ;) | ||
| let offseted_range = *new_err.range() + range_before_reparse.start(); | ||
| new_err.with_range(offseted_range) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised how this reports a move after borrow error
new_err.with_range(*new_err.range() + range_before_reparse.start())
// where
fn with_range(mut self, range: TextRange) -> Self;
fn range(&self) -> &TextRange;| pub struct SyntaxError(String, TextRange); | ||
|
|
||
| // FIXME: there was an unused SyntaxErrorKind previously (before this enum was removed) | ||
| // It was introduced in this PR: https://github.com/rust-analyzer/rust-analyzer/pull/846/files#diff-827da9b03b8f9faa1bade5cdd44d5dafR95 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: there was an enum variant of SyntaxError that was not used anywhere, it was introduced in this PR, but then match arms attributes validation logic was removed without this variant being deleted...
076d830 to
34158f1
Compare
|
|
||
| for old_err in old_errors { | ||
| let old_err_range = *old_err.range(); | ||
| // FIXME: make sure that .start() was here previously by a mistake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixme will be removed before merging this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be TODO then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I just temporarily marked it FIXME to let it pass no todo tests for a while.
A nice trick here to commit code changes and test data changes in sepparate commits, so that the diff is easier to review. |
|
|
||
| for old_err in old_errors { | ||
| let old_err_range = *old_err.range(); | ||
| // FIXME: make sure that .start() was here previously by a mistake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be TODO then
crates/ra_syntax/src/syntax_error.rs
Outdated
| @@ -1,209 +1,47 @@ | |||
| //! FIXME: write short doc here | |||
| //! Module that defines `SyntaxError`. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to explain why, rather than what:
This module defines SyntaxError, the type we use to represent errors from
- tokenization
- parsing
- tree validation
The errors are unstructured: just a message and a location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this description to doc comment on top of SyntaxError itself, otherwise it would be repetition
crates/ra_syntax/src/syntax_error.rs
Outdated
|
|
||
| pub fn location(&self) -> Location { | ||
| self.location.clone() | ||
| pub fn message(&self) -> &str { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove this function and just impl fmt::Display
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yes, seems reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect an fmt::Display impl to give both the error message and location, while this method only gives the message, not the location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You never see error location displayed as a hint on top of error squiggles, but you do want to see the text range if you print it to stdout. In case of std::fmt::Display this is for the first case, whilst std::fmt::Debug is for the second case. But anyway, I think this is not transparent, should we remove impl Display at all here then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did remove message() function, though this is a bit controversial, but I'd like to trust matklad here. Maybe I am wrong saying not transparent in my previous comment right here...
crates/ra_syntax/src/syntax_error.rs
Outdated
| Location::Offset(offset) => offset, | ||
| Location::Range(range) => range.start(), | ||
| } | ||
| pub fn range(&self) -> &TextRange { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to return a reference, TextRange is small and Copy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I am just used to getters returning by reference, wanted to hear your thoughts.
| Parse, SmolStr, SyntaxKind, TextUnit, | ||
| }; | ||
|
|
||
| pub(crate) use rowan::{GreenNode, GreenToken}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "re-export" was intentionally after "imports", but I dont' have strong feelings about htis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, if I am not mistaken (need to recheck), this is what rustfmt suggested me to do and I couldn't resist
|
No strong opinion here, but I prefer to document modules, rather than
structs, because they are more useful for high-level picture.
…On Thu, 6 Feb 2020 at 12:01, Veetaha ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In crates/ra_syntax/src/syntax_error.rs
<#3026 (comment)>
:
> @@ -1,209 +1,47 @@
-//! FIXME: write short doc here
+//! Module that defines `SyntaxError`.
I moved this description to doc comment on top of SynraxError itself,
otherwise it would be repetition
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#3026>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M5RXDLNDUEYVN7ZGE3RBPU2FANCNFSM4KQUPYHQ>
.
|
But I see here you decided to document a struct instead of a module ... |
|
I cannot be right because of that specific reason: my point was rather that
we should now allow UI concerns (how exactly is the red squiggle shown)
bleed into domain model. If we want to customize the squiggle, the place to
do that is conv.rs all the way up in ra+lsp-server. But yeah, it is
convenient that vscode just does the right thing out of the box here,
…On Friday, 7 February 2020, Veetaha ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In crates/ra_syntax/src/syntax_error.rs
<#3026 (comment)>
:
> }
-
- pub fn kind(&self) -> SyntaxErrorKind {
- self.kind.clone()
+ pub fn new_at_offset(message: impl Into<String>, offset: TextUnit) -> Self {
+ Self(message.into(), TextRange::offset_len(offset, 1.into()))
Apparently you are right, this is what I found in vscode docs
<https://code.visualstudio.com/api/language-extensions/language-server-extension-guide#diagnostics-tips-and-tricks>
If the start and end positions are the same, VS Code will underline with a
squiggle the word at that position.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3026>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3MZSK72ISQXLC445AFDRBUPUJANCNFSM4KQUPYHQ>
.
|
|
@matklad, I know this is not the most important thing, but might I ask you, please to elaborate on this comment? |
|
Still no strong opinion, though I find there's a meaningful difference between "See X" (which is a redirect) and "This module defines X" (which reads like a placeholder comment) :) |
|
But I do have a strong opinion. When you use the struct itself, you get documentation popups with more detailed docs, but you don't get them when you trigger autocompletion for the module itself (mentioning that you often just |
|
See X sounds better, you are right! |
|
Yeah, convinced, you are right! We should move all single-struct modules to |
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
… X" as per matklad
43df237 to
e05eb63
Compare
…axError as per matklad
…en constructed from TextUnit
|
@matklad, in response to your comment here about the bug I supposedly found. I did check that there was a bug in Also, note that, though unintended to be in this PR, but I was forced to amend As a side note, we have a bit of code duplication in |
|
Also, @matklad, please note on an [UPD] I wrote in PR description, I hope it makes sense. I'd like to experiment with moving tree validation errors to I hope it makes sense! |
|
|
bors r+ |
3026: ra_syntax: reshape SyntaxError for the sake of removing redundancy r=matklad a=Veetaha Followup of #2911, also puts some crosses to the todo list of #223. **AHTUNG!** A big part of the diff of this PR are test data files changes. Simplified `SyntaxError` that was `SyntaxError { kind: { /* big enum */ }, location: Location }` to `SyntaxError(String, TextRange)`. I am not sure whether the tuple struct here is best fit, I am inclined to add names to the fields, because I already provide getters `SyntaxError::message()`, `SyntaxError::range()`. I also removed `Location` altogether ... This is currently WIP, because the following is not done: - [ ] ~~Add tests to `test_data` dir for unescape errors *// I don't know where to put these errors in particular, because they are out of the scope of the lexer and parser. However, I have an idea in mind that we move all validators we have right now to parsing stage, but this is up to discussion...*~~ **[UPD]** I came to a conclusion that tree validation logic, which unescape errors are a part of, should be rethought of, we currently have no tests and no place to put tests for tree validations. So I'd like to extract potential redesign (maybe move of tree validation to ra_parser) and adding tests for this into a separate task. Co-authored-by: Veetaha <gerzoh1@gmail.com> Co-authored-by: Veetaha <veetaha2@gmail.com>
|
I would not be 100% sure that we can't go without typed |
Build succeeded
|
|
Oh, I just noticed I forgot to remove one FIXME comment... |
|
And that's why one should use TODO for comments that *should* be removed
before merging :D
…On Tue, 18 Feb 2020 at 14:03, Veetaha ***@***.***> wrote:
Oh, I just noticed I forgot to remove one FIXME comment...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3026>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANB3M77IGYZZSSTM24LYCDRDPMCVANCNFSM4KQUPYHQ>
.
|
Followup of #2911, also puts some crosses to the todo list of #223.
AHTUNG! A big part of the diff of this PR are test data files changes.
Simplified
SyntaxErrorthat wasSyntaxError { kind: { /* big enum */ }, location: Location }toSyntaxError(String, TextRange). I am not sure whether the tuple struct here is best fit, I am inclined to add names to the fields, because I already provide gettersSyntaxError::message(),SyntaxError::range().I also removed
Locationaltogether ...This is currently WIP, because the following is not done:
Add tests to[UPD] I came to a conclusion that tree validation logic, which unescape errors are a part of, should be rethought of, we currently have no tests and no place to put tests for tree validations. So I'd like to extract potential redesign (maybe move of tree validation to ra_parser) and adding tests for this into a separate task.test_datadir for unescape errors // I don't know where to put these errors in particular, because they are out of the scope of the lexer and parser. However, I have an idea in mind that we move all validators we have right now to parsing stage, but this is up to discussion...