Skip to content

Unused/inactive highlighting when file is not linked #17397

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

Closed
cynecx opened this issue Jun 12, 2024 · 23 comments
Closed

Unused/inactive highlighting when file is not linked #17397

cynecx opened this issue Jun 12, 2024 · 23 comments
Labels
A-diagnostics diagnostics / error reporting Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug

Comments

@cynecx
Copy link
Contributor

cynecx commented Jun 12, 2024

rust-analyzer version: 4af21ff

Before an unlinked file (or a #[cfg(FALSE)] module) just had a small diagnostic for the first line. Now the whole file gets the visually marked as "unused", which was implemented here: #17350.

The PR mentions:

Whilst this is marginally more prominent, it's less invasive than a pop-up, and users do want to know why they're getting no rust-analyzer support in certain files.

I agree it is less "invasive" compared to pop-up but now it's also more visually distracting (or for me straight up annoying). My workflow quite often consists of workflows where I've got unlinked files in the work-tree and having the whole file "grayed out" it not great visually speaking.

There must be a better to do this. It might be interesting to see what RustRover is doing here. But for now I've reverted this change locally, so it's not bugging me anymore.

@cynecx cynecx added the C-bug Category: bug label Jun 12, 2024
@cynecx cynecx changed the title Annoying unused highlighting when file is not linked Unused/inactive highlighting when file is not linked Jun 12, 2024
@Veykril
Copy link
Member

Veykril commented Jun 12, 2024

RustRover shows a banner-like thing at the top of the file I believe. VSCode doesn't really let us to do that unfortunately.

@davidbarsky @Wilfred I'll put this on your plate to figure out :) I figured people would find this annoying as that was the exact reason why the diagnostic was limited to the first few characters of the file

@Veykril Veykril added the A-diagnostics diagnostics / error reporting label Jun 12, 2024
@RalfJung
Copy link
Member

Yeah this definitely sounds quite annoying, e.g. when working on ui test files in rustc and Miri which are expected to be "unlinked".

@Veykril Veykril added the Broken Window Bugs / technical debt to be addressed immediately label Jun 12, 2024
@Veykril
Copy link
Member

Veykril commented Jun 12, 2024

The only thing i can think of is to turn the status bar item yellow when having an unlinked file open, but people like to completely ignore the status bar so I don't know how useful that would be.

@lnicola
Copy link
Member

lnicola commented Jun 12, 2024

How about a code lens at the top of the file? It might still be too easy to miss though.

@RalfJung
Copy link
Member

RalfJung commented Jun 12, 2024 via email

@cynecx
Copy link
Contributor Author

cynecx commented Jun 12, 2024

I agree with Ralf here. But what can we do in the meantime until this gets figured out? I'd be in favor of reverting that PR or at the very least put it behind a ff/config.

@lnicola
Copy link
Member

lnicola commented Jun 12, 2024

Disabling the diagnostic (rust-analyzer.diagnostics.disabled) probably works.

@cynecx
Copy link
Contributor Author

cynecx commented Jun 12, 2024

Oh… I didn't know that setting existed 😅 Thanks!

@davidbarsky
Copy link
Contributor

davidbarsky commented Jun 12, 2024

Yeah, I think it's reasonable that some people are annoyed by this, which is why I think should be controlled at the language/build system level, not the IDE level1. However, that discussion isn't immediately relevant to this issue.

Short-term, I think that @lnicola's solution will work. Medium-term, what do y'all think of this: change this diagnostic to a notification and add a configuration option that allows users to clearlist certain files paths, such as those corresponding to rustc/miri's UI tests. With the newly-landed rust-analyzer.toml functionality, it'd be possible to enable this setting for all people using rust-analyzer in rustc/rust-analyzer.

Footnotes

  1. We did see that new Rust users benefitted tremendously from this diagnostic, so I'm personally inclined to keep this around in some form.

@Veykril
Copy link
Member

Veykril commented Jun 12, 2024

No, this is not going to be a notification. I cannot think of something even more annoying than that. We had people screaming at us for ages because of us showing a notification when the server panicked, this would get us immense backlash if we were to do that.

@davidbarsky
Copy link
Contributor

How would you feel about having this being a diagnostic by default, and behind a off-by-default setting, the ability to upgrade it to a notification? For the users Wilfred and I are responsible for, we'll make it a notification, but most rust-analyzer users won't see, let alone complain about it.

@Wilfred
Copy link
Contributor

Wilfred commented Jun 12, 2024

For what it's worth, #[cfg(FALSE)] hasn't changed, it has always shown inactive highlighting across the whole scope.

As @davidbarsky mentioned, this was a huge win when we measured it for our users. Rust newcomers would find that go-to-def didn't work for some files, and not realise that they needed to e.g. add mod new_file; to lib.rs.

I totally get that it's awkward when you have a deliberately untracked file, and hurts power users / exotic setups more.

The obvious options I see are:

  • Adding a setting to opt-in to the old behaviour, perhaps for both untracked files and inactive cfgs.
  • Adding the ability to mark a file as intentionally untracked to rust-analyzer, say a custom comment syntax. It's already possible to do cfg(rust_analyzer) I think.
  • Mention the rust-analyzer.diagnostics.disabled setting in the hover text for inactive and unused files.

@davidbarsky
Copy link
Contributor

RustRover shows a banner-like thing at the top of the file I believe. VSCode doesn't really let us to do that unfortunately.

To add to this, the reason I brought up the notification approach—despite users in the past being very reasonably annoyed by it!—is that the UI guidelines for VS Code suggest using a notification for this sort of thing. I would love to have a banner like RustRover does or maybe even have a modal creating a new file, but I don't know if that's a good idea, let alone possible in VS Code.

@cynecx
Copy link
Contributor Author

cynecx commented Jun 12, 2024

Isn't it possible to color code lenses? (With decorations?) I remember seeing some extensions doing that. Even without color I'd think that this is "visible" enough (compared to the previous "short-span" behavior). But idk...

EDIT: A code lense might be somewhat convenient here because it can provide an action to add the file automatically to the parent module... 🙃

@Wilfred
Copy link
Contributor

Wilfred commented Jun 13, 2024

#17411 improves the hover information: it's using full sentences, and it suggests the diagnostic setting for power users.

@RalfJung
Copy link
Member

I'm now also getting this for files that are in the module hierarchy, but RA is still loading:

image

That's just a plain false positive, IMO.

@Veykril
Copy link
Member

Veykril commented Jun 13, 2024

No, this is not going to be a notification. I cannot think of something even more annoying than that. We had people screaming at us for ages because of us showing a notification when the server panicked, this would get us immense backlash if we were to do that.

I remembered earlier that we actually used to have a notification (we still have a config that toggles it), but that is nowadays disabled fully in code as it is buggy and more importantly annoying even with the setting. (buggy in part because r-a will flag any file on startup)

@Veykril
Copy link
Member

Veykril commented Jun 13, 2024

Isn't it possible to color code lenses? (With decorations?) I remember seeing some extensions doing that. Even without color I'd think that this is "visible" enough (compared to the previous "short-span" behavior). But idk...

EDIT: A code lense might be somewhat convenient here because it can provide an action to add the file automatically to the parent module... 🙃

I don't think so? We could decorate the first line in a file and color that at best

@Veykril
Copy link
Member

Veykril commented Jun 13, 2024

I'm now also getting this for files that are in the module hierarchy, but RA is still loading:

image

That's just a plain false positive, IMO.

That didn't really change either by that PR, when r-a starts up it has no crate-graph yet so it lints all files. Its just more noticable now (flagging files at start up is something we ought to not do generally).

@RalfJung
Copy link
Member

I remembered earlier that we actually used to have a notification (we still have a config that toggles it), but that is nowadays disabled fully in code as it is buggy and more importantly annoying even with the setting. (buggy in part because r-a will flag any file on startup)

If it wasn't buggy, maybe it wouldn't be so annoying?

Wilfred added a commit to Wilfred/rust-analyzer that referenced this issue Jun 13, 2024
This partially reverts rust-lang#17350, based on the feedback in rust-lang#17397.

If we don't have an autofix, it's more annoying to highlight the whole line.
This heuristic fixes the diagnostic overwhelming the user during startup.
@Wilfred
Copy link
Contributor

Wilfred commented Jun 13, 2024

@RalfJung agreed on the startup case being annoying, #17415 should fix that.

bors added a commit that referenced this issue Jun 19, 2024
fix: Only show unlinked-file diagnostic on first line during startup

This partially reverts #17350, based on the feedback in #17397.

If we don't have an autofix, it's more annoying to highlight the whole file. This autofix heuristic fixes the diagnostic being overwhelming during startup.
@Veykril
Copy link
Member

Veykril commented Jul 7, 2024

Does #17415 resolve this for you now?

@cynecx
Copy link
Contributor Author

cynecx commented Jul 7, 2024

@Veykril I mean it improves things but that diagnostic, in general, is just not compatible with workflows where you have intentionally unlinked files. That's why I am currently just utilizing rust-analyzer.diagnostics.disabled. So I guess this is technically fixed for me, even though I still think the situation isn't perfect. Feel free to to close this issue then, or keep this opened for further issue tracking for anything "unlinked file" related.

EDIT: Actually on second thought, let's just close this one. It's probably best to track further improvements in a new issue tracker or something. Thanks everyone!

@cynecx cynecx closed this as completed Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

6 participants