Skip to content

Commit

Permalink
Auto merge of rust-lang#17411 - Wilfred:clearer_unlinked_file, r=Veykril
Browse files Browse the repository at this point in the history
fix: Improve hover text in unlinked file diagnostics

Use full sentences, and mention how to disable the diagnostic if users are intentionally working on unowned files.

![Screenshot 2024-06-12 at 5 55 48 PM](https://github.com/rust-lang/rust-analyzer/assets/70800/c91ee1ed-1c72-495a-9ee3-9e360a5c6977)

(Full disclosure: I've tested a rust-analyzer build in VS Code, but the pop-up logic is currently disabled due to rust-lang#17062, so I haven't tested that.)
  • Loading branch information
bors committed Jun 24, 2024
2 parents a32ce24 + 39179c4 commit f9a337c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ pub(crate) fn unlinked_file(
// FIXME: This is a hack for the vscode extension to notice whether there is an autofix or not before having to resolve diagnostics.
// This is to prevent project linking popups from appearing when there is an autofix. https://github.com/rust-lang/rust-analyzer/issues/14523
let message = if fixes.is_none() {
"file not included in crate hierarchy"
"This file is not included in any crates, so rust-analyzer can't offer IDE services."
} else {
"file not included in module tree"
"This file is not included anywhere in the module tree, so rust-analyzer can't offer IDE services."
};

let message = format!("{message}\n\nIf you're intentionally working on unowned files, you can silence this warning by adding \"unlinked-file\" to rust-analyzer.diagnostics.disabled in your settings.");

let mut range = ctx.sema.db.parse(file_id).syntax_node().text_range();
let mut unused = true;

Expand Down
3 changes: 2 additions & 1 deletion src/tools/rust-analyzer/editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export async function createClient(
// value === "unlinked-file" &&
value === "temporary-disabled" &&
!unlinkedFiles.includes(uri) &&
diag.message !== "file not included in module tree"
(diag.message === "file not included in crate hierarchy" ||
diag.message.startsWith("This file is not included in any crates"))
) {
const config = vscode.workspace.getConfiguration("rust-analyzer");
if (config.get("showUnlinkedFileNotification")) {
Expand Down

0 comments on commit f9a337c

Please sign in to comment.