-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tuple struct index inference #1117
Conversation
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.
LGTM, I don't know how to handle the error recovery though... I'd suggest adding a parser test for the x.0.
error recovery though, even if we don't handle it very well currently.
Done. It had to be a failure test because the validation logic I added rejects attempts to index tuples with anything other than decimal integers without underscores or suffixes, as per the Rust reference. |
I think we should avoid intorducing a TupleIndex node, I think it won't be generally useful. Instead, I suggest hand-writing an
method manually, which looks for token among We might also add an
and corresponding accessor for convenience. |
Fascinating! So what happens is that, when we insert a fake identifier, we parse I guess an immediate thing we can do is to rewrite the completion test such that there's at least one char after dot, like As for fixing the quirk.... I honestly don't immediately see a clean solution here. We can tweak the lexer to not lex |
@matklad I have incorporated the feedback from your comments -- |
bors r+ |
1117: [WIP] Tuple struct index inference r=matklad a=robojumper The first commit adds a helper struct `ast::FieldKind` to facilitate inference. The second commit adds a slightly modified test from #1109 while mentioning that there is a problem with how we're handling tuple indexing / floats. cc #1109 Co-authored-by: robojumper <[email protected]>
Build succeeded |
Ah, remapping tokens on the parser level won't be trivial because parser intentionally doesn't know about the token's text... |
Hm, couldn't we just handle this during lowering to HIR? I think it should just work if we removed the |
We'll need to tweak both HIR and completion_ctx. SPecifically, this line in context is currently failing: https://github.com/rust-analyzer/rust-analyzer/blob/990e74ba7c77485f914434ac6f09a40d1364634d/crates/ra_ide_api/src/completion/completion_context.rs#L214 Thinking about it more, I don't like the idea of hacking either lexer (b/c that adds context to lexer) or parser (b/c it adds back knowledge about token texts to parser), so I am indeed inclined towards patching this (in a pretty horrible way, by looking at the sibling token of field expressions) when converting to HIR / completing. |
The first commit adds a helper struct
ast::FieldKind
to facilitate inference.The second commit adds a slightly modified test from #1109 while mentioning that there is a problem with how we're handling tuple indexing / floats.
cc #1109