-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Introduce "introduce match" #531
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
// FIXME: Set cursor at beginning of first match arm. | ||
// The following doesn't work because of re-indentation: | ||
// | ||
// edit.set_cursor(expr.range().start() + TextUnit::of_str(&first_part)); |
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 think replace_and_indent could return an offset of the start of the substituted node?
I added the expression filter, but immediately noticed another edge case: Triggering it like |
Yeah, although Another drawback is that this (just as introduce variable) will basically be always available. Perhaps we need to activate it only if the rage of expresison exactly matches selection? That is, one would use extend selection to select expression, and then introduce variable/match? |
Hmm, only enabling this when there is a valid selection doesn't feel very convenient to me; in the best case it's one more shortcut to press (and know to press). How likely are we able to make a good guess at what the user meant? E.g., checking the node we are at and deciding that if it's a function call to always match on the full call seems like a good idea to me. |
How about using the whole expression statement / last expression of the block if nothing is selected? |
SGTM! |
Could work! I'll try to find some time tomorrow to change the code. |
Note that I've had to rewrite the history recently, so expect storms while rebasing: #566 (comment) Sorry about that: it's definitively my mistake 🙁 |
Similar to "Introduce variable". This creates a match for the expression under the cursor. This is the simples possible implementation for now, with two FIXMEs and a lot of ideas that are just waiting to be implemented. cf. rust-lang#528
e53aeff
to
015346c
Compare
No worries, just rebased this real quick. |
@@ -397,7 +397,7 @@ impl Analysis { | |||
self.with_db(|db| db.find_all_refs(position)) | |||
} | |||
|
|||
/// Returns a short text descrbing element at position. |
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 is a bit off-topic, but perhaps it helps anyone reading this
I too sometimes struggle with grammar :) A small tip from one non-native English speaker who likes to be correct to any other: there's two plugins that I use to help me avoid spelling issues in my code:
- https://github.com/bartosz-antosik/vscode-spellright
- https://github.com/Jason-Rev/vscode-spell-checker
They complement each other, as one is used in "textual" contexts, such as README's, or code comments, while the other is used to avoid common spelling mistakes in my actual Rust code, and works with CamelCase situations.
Here's my config for both of them, in case it helps anyone:
{
"spellright.language": ["en-GB"],
"spellright.groupDictionaries": false,
"spellright.documentTypes": [
"markdown",
"plaintext",
"rust",
],
"spellright.parserByClass": {
"rust": {
"parser": "code"
}
},
"spellright.notificationClass": "information",
"spellright.configurationScope": "user",
"spellright.statusBarIndicator": false,
"cSpell.checkLimit": 2048,
"cSpell.language": "en-GB",
"cSpell.showStatus": false,
"cSpell.enabledLanguageIds": [
"markdown",
"plaintext",
"rust"
],
"cSpell.userWords": [
"Deserialize",
"Tuple",
"alloc",
"clippy",
"rustc",
"rustfmt",
"struct",
],
"cSpell.languageSettings": [
{
"languageId": "rust",
"ignoreRegExpList": [
"/\/\/\/? .*/"
]
}
]
}
It's easy to add words to the cSpell.userWords
array as you work, using the contextual popup in the editor. I trimmed the list down to a few useful ones for Rust development. The same goes for the spellright spelling updates, but those are stored in $VSCODE/User/spellright.dict
:
clippy
fmt
impl
iter
mut
println
rustc
rustfmt
usize
utf8
vec
cc @matklad
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 do have a spelling problem in any language :-)
I've tried using a cspell check extension, but unfortunately it gives a fair amount of false positives, and in general is pretty distractive: F8
brings you not to the next compiler error, but to the one of the dozen spelling mistakes.
I'd love to have a spellchecker which only checks comments and have close to zeto false positiv rate, but I haven't invstigated this yet.
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 could start by using spellright, and configure it to only show you spelling mistakes in your code comments.
I agree that it's annoying that cspell gives plenty of false positives, but when I'm working in a project, I fairly quickly add all of the project-specific variable names to the list of ignored spellings, after which things quiet down.
Anyway, I agree, it's not perfect, but it helped me, and is "good enough" for now (especially if you skip cspell and only focus on comments/documentation in Rust).
note that we now have a postfix We need to make sure that the two impls share the code :) |
Closing because I won't have time to work on this right now. Will make a new PR later hopefully |
Similar to "Introduce variable". This creates a match for the expression
under the cursor.
This is the simplest possible implementation for now, with two FIXMEs and
a lot of ideas that are just waiting to be implemented.
cf. #528