about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide-completion
AgeCommit message (Collapse)AuthorLines
2024-10-21Auto merge of #18337 - dqkqd:issue-18287, r=Veykrilbors-0/+18
fix: private items are shown in completions for modules in fn body Close: #18287
2024-10-21fix: private items are shown in completions for modules in fn bodyKhanh Duong Quoc-0/+18
2024-10-21Update ide testsLukas Wirth-1/+1
2024-10-01Fix: Handle block exprs as modules when finding their parentsShoyu Vanilla-2/+8
2024-09-30Auto merge of #18167 - SomeoneToIgnore:fat-completions, r=Veykrilbors-3/+30
internal: Send less data during `textDocument/completion` if possible Similar to https://github.com/rust-lang/rust-analyzer/pull/15522, stops sending extra data during `textDocument/completion` if that data was set in the client completions resolve capabilities, and sends those only during `completionItem/resolve` requests. Currently, rust-analyzer sends back all fields (including potentially huge docs) for every completion item which might get large. Same as the other one, this PR aims to keep the changes minimal and does not remove extra computations for such fields — instead, it just filters them out before sending to the client. The PR omits primitive, boolean and integer, types such as `deprecated`, `preselect`, `insertTextFormat`, `insertTextMode`, etc. AND `additionalTextEdits` — this one looks very dangerous to compute for each completion item (as the spec says we ought to if there's no corresponding resolve capabilities provided) due to the diff computations and the fact that this code had been in the resolution for some time. It would be good to resolve this lazily too, please let me know if it's ok to do. When tested with Zed which only defines `documentation` and `additionalTextEdits` in its client completion resolve capabilities, rust-analyzer starts to send almost 3 times less characters: Request: ```json {"jsonrpc":"2.0","id":104,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///Users/someonetoignore/work/rust-analyzer/crates/ide/src/inlay_hints.rs"},"position":{"line":90,"character":14},"context":{"triggerKind":1}}} ``` <img width="1338" alt="image" src="https://github.com/user-attachments/assets/104f19b5-7095-4fc1-b008-5d829623b2e2"> Before: 381944 characters [before.json](https://github.com/user-attachments/files/17092385/before.json) After: 140503 characters [after.json](https://github.com/user-attachments/files/17092386/after.json) After Zed's [patch](https://github.com/zed-industries/zed/pull/18212) to enable all resolving possible: 84452 characters [after-after.json](https://github.com/user-attachments/files/17092755/after-after.json)
2024-09-25Merge from rust-lang/rustLaurențiu Nicola-0/+1
2024-09-24Auto merge of #18161 - ChayimFriedman2:postfix-mut, r=Veykrilbors-1/+52
fix: Better support references in consuming postfix completions Fixes #18155.
2024-09-23internal: Make COMPLETION_MARKER more explicitly r-aWilfred Hughes-1/+1
If a user ever sees the completion marker, it's confusing to see text about IntelliJ. Use a string that's more explicitly about completion for rust-analyzer.
2024-09-23Support expect in attribute completion and hoverLaurențiu Nicola-2/+25
2024-09-23Omit completion fields to be resolved laterKirill Bulatov-4/+0
2024-09-23Prepare for omittiong parts of completion data that need to be resolvedKirill Bulatov-3/+34
2024-09-22Include dereferences in consuming postfix completions (e.g. `call`)Chayim Refael Friedman-0/+31
2024-09-22Properly account for mutable references when postfix-completing consuming ↵Chayim Refael Friedman-1/+21
completions (e.g. `call`)
2024-09-21add `C-cmse-nonsecure-entry` ABIFolkert de Vries-0/+1
2024-09-20Auto merge of #18132 - ChayimFriedman2:fix-closure-semi, r=Veykrilbors-32/+100
fix: Don't complete `;` when in closure return expression Completing it will break syntax. Fixes #18130.
2024-09-18Get rid of `$crate` in expansions shown to the userChayim Refael Friedman-10/+22
Be it "Expand Macro Recursively", "Inline macro" or few other things. We replace it with the crate name, as should've always been.
2024-09-18Extract logic to decide how to complete semicolon for unit-returning ↵Chayim Refael Friedman-39/+73
function into `CompletionContext` So that we don't recompute it for every item.
2024-09-18Don't complete `;` when in closure return expressionChayim Refael Friedman-24/+58
Completing it will break syntax.
2024-09-12Auto merge of #18038 - roife:fix-issue-18034, r=Veykrilbors-1/+2
feat: generate names for tuple-struct in add-missing-match-arms fix #18034. This PR includes the following enhancement: - Introduced a `NameGenerator` in `suggest_name`, which implements an automatic renaming algorithm to avoid name conflicts. Here are a few examples: ```rust let mut generator = NameGenerator::new(); assert_eq!(generator.suggest_name("a"), "a"); assert_eq!(generator.suggest_name("a"), "a1"); assert_eq!(generator.suggest_name("a"), "a2"); assert_eq!(generator.suggest_name("b"), "b"); assert_eq!(generator.suggest_name("b"), "b1"); assert_eq!(generator.suggest_name("b2"), "b2"); assert_eq!(generator.suggest_name("b"), "b3"); assert_eq!(generator.suggest_name("b"), "b4"); assert_eq!(generator.suggest_name("b3"), "b5"); ``` - Updated existing testcases in ide-assists for the new `NameGenerator` (only modified generated names). - Generate names for tuple structs instead of using wildcard patterns in `add-missing-match-arms`.
2024-09-10refactor: introduce NameGenerator in suggest_nameroife-1/+2
2024-09-08Automatically add semicolon when completing unit-returning functionsChayim Refael Friedman-40/+192
But provide a config to suppress that. I didn't check whether we are in statement expression position, because this is hard in completion (due to the natural incompleteness of source code when completion is invoked), and anyway using function returning unit as an argument to something seems... dubious.
2024-09-05Add Definition kind for asm register classesLukas Wirth-0/+1
2024-09-03Auto merge of #18031 - roife:suggest-name-in-completion, r=Veykrilbors-0/+110
feat: Suggest name in completion for let_stmt and fn_param fix #17780 1. Refactor: move `ide_assist::utils::suggest_name` to `ide-db::syntax_helpers::suggest_name` for reuse. 2. When completing `IdentPat`, detecte if the current node is a `let_stmt` or `fn_param`, and suggesting a new name based on the context.
2024-09-03tests: suggesting names in completions for let_stmt and fn_paramroife-0/+73
2024-09-03feat: suggest name in let_stmt and fn_paramroife-0/+37
2024-09-02Adjust completions scoringLukas Wirth-50/+46
2024-09-02Simplify CompletionRelevanceLukas Wirth-90/+85
2024-09-01Complete desugared and resugared async fn in trait implsLukas Wirth-55/+248
2024-09-01feat(ide-completion): extra sugar auto-completion `async fn ...` in `impl ↵Yunfei-1/+37
trait` for `async fn in trait` that's defined in desugar form
2024-08-30fix(ide-completion): fix handling of `for` in `impl T for A` in function bodyrami3l-5/+81
2024-08-26Auto merge of #17963 - avrong:avrong/error-lifetimes, r=Veykrilbors-6/+6
Always show error lifetime arguments as `'_` Fixes #17947 Changed error lifetime argument presentation in non-test environment to `'_` and now showing them even if all of args are error lifetimes. This also influenced some of the other tests like `extract_function.rs`, `predicate.rs` and `type_pos.rs`. Not sure whether I need to refrain from adding lifetimes args there. Happy to fix if needed
2024-08-26Show and render error lifetime args as `'_`Aleksei Trifonov-6/+6
2024-08-26Auto merge of #17941 - ChayimFriedman2:pre-closure-to-fn, r=Veykrilbors-2/+4
Preliminary work for #17940 I split the PR as requested, and made small commits.
2024-08-25fix: Fix trait method completions not acknowledging Deref implsLukas Wirth-0/+36
2024-08-24Modify `hacks::parse_expr_from_str()` to take an edition tooChayim Refael Friedman-2/+4
This will be needed as we parse unknown identifiers and want to insert them into source code.
2024-08-16Auto merge of #17905 - ChayimFriedman2:edition-dependent-raw-keyword, r=Veykrilbors-146/+406
fix: Properly account for editions in names This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here). It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now. The rules of thumb are: - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code. - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn). - For debugging tools (helper methods and logs), I used `Edition::LATEST`. Reviewing notes: This is a really big PR but most of it is mechanical translation. I changed `Name` displayers to require an edition, and followed the compiler errors. Most methods just propagate the edition requirement. The interesting cases are mostly in `ide-assists`, as sometimes the correct crate to fetch the edition from requires awareness (there may be two). `ide-completions` and `ide-diagnostics` were solved pretty easily by introducing an edition field to their context. `ide` contains many features, for most of them it was propagated to the top level function and there the edition was fetched based on the file. I also fixed all FIXMEs from #17896. Some required introducing an edition parameter (usually not for many methods after the changes to `Name`), some were changed to a new method `is_any_identifier()` because they really want any possible keyword. Fixes #17895. Fixes #17774.
2024-08-16Properly account for editions in namesChayim Refael Friedman-146/+406
This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here). It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now. The rules of thumb are: - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code. - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn). - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-16Auto merge of #17907 - ChayimFriedman2:no-once_cell, r=Veykrilbors-3/+3
internal: Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/LockChayim Refael Friedman-3/+3
This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-15internal: Properly check the edition for edition dependent syntax kindsLukas Wirth-2/+3
2024-08-10fix: Fix find_path not respecting non-std preference config correctlyLukas Wirth-58/+24
2024-08-06Replace `[package.repository] = "…"` of published crates with ↵Vincent Esche-1/+1
`[package.repository.workspace] = true`
2024-08-06Unify package descriptions by adding references to "rust-analyzer"Vincent Esche-1/+1
With the lack of a README on the individually published library crates and the somewhat cryptic `ra_ap_` prefix it is hard to figure out where those crates belong to, so mentioning "rust-analyzer" feels like auseful hint there.
2024-08-06Add repository URL for published crates' missing `[package.repository]` fieldsVincent Esche-0/+1
2024-08-06Replace `"TBD"` with more helpful desciptions in published crates' ↵Vincent Esche-1/+1
`[package.description]` fields
2024-08-05Simplify FileDelegateLukas Wirth-2/+2
2024-07-29Add test in `ide-completion/src/tests/item_list.rs`Yunfei-1/+3
2024-07-29Cargo fmtYunfei-3/+7
2024-07-29feat(ide-completion): explictly show `async` keyword on `impl trait`Yunfei-2/+4
2024-07-21fix: Allow flyimport to import primitive shadowing modulesLukas Wirth-0/+15