-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Add unused variable support #1062
Comments
There are a couple of somewhat orthogonal changes here:
So to summarize, I’m proposing to
|
I was proposing 1 and 3, but not 2. To my mind, the ability to enable additional warnings for the IDE only should be controlled in |
So you aren’t proposing to turn them on by default? As I mentioned, I really want to be able to turn this off and I don’t see how |
I think by default its reasonable to gray out the unused variables. I believe in VS Code you can achieve that by making them very low-level diagnostics, which are so low level they don't get onto the problems page. So if the user hasn't explicitly turned them on, we turn them on and reduce their severity until you are only left with the gray text (which I think everyone should want). |
I still really dislike the idea of turning on warnings by default with no way to disable them. That reminds me of static analysis tools with a ton of false positives that people just stop using at some point because the signal to noise ratio is too low. Given that I actually like this particular warnings, I’m fine with turning them on by default but I want to at least have a CLI flag to disable that which shouldn’t add much complexity in the implementation given that we already need to differentiate between the warning being enabled explicitly in which case we don’t want to demote it to a hint and the warning being part of the defaults. |
You mean you don't want to see the variables in gray? Because that's the only proposed effect I am suggesting from "turning on the warning". Note that in most other IDE's you get the gray by default, and in VS Code, you can set the "unused variable color" for a particular language, and setting it to no effect is equivalent to turning off this warning. |
My issue is with “turning on the warning” not making them gray. I don’t want to see warnings that I don’t care about even if they are only displayed in gray and if I do care about them then I want them to be shown when I run my build tool in a terminal as well. |
I propose that we:
This is how TypeScript and similar work in VS Code. |
We don’t have control over how the client displays hint diagnostics and I don’t want to rely on how VSCode handles this. From the server side all we can do is mark them as hints and add the unnecessary tag. I think we are mostly in agreement here. All I’m saying is that I want to have something like a |
Sure, no objection to that - I would rather the way of emitting unused variables wasn't the same as a diagnostic, or we could have a Fake tag on the diagnostic so all clients knew it wasn't real. |
It isn’t clear to me from the spec that clients are supposed to handle an unknown tag gracefully so I’m a bit hesitant to use a fake tag. I think marking it as a hint should probably give us a reasonably sane behavior in most clients which makes it hard to justify trying to come up with something other than diagnostics which would require custom support for |
Sorry, I meant what we want is some predefined tag like Fake which has a semantic guarantee we are looking for. I wasn't suggesting we invent a new tag - agree that Hint is fine. I wonder if vanilla flag should also disable the deferred type errors treatment too, as that differs from what normal tools give. |
The deferred type errors remap the warning to an error in |
I think that once haskell/ghcide#232 lands, we can reuse the same infrastructure for "unused" warnings. In fact, I volunteer to implement this feature once the other PR is merged. |
Unfortunately, it seems like |
@serras just in case, haskell-lsp-0.22 already exposes the field: http://hackage.haskell.org/package/haskell-lsp-types-0.22.0.0/docs/Language-Haskell-LSP-Types.html#t:Diagnostic 😃 |
@jneira thanks for the pointer! now I have homework for the weekend :) |
I could not wait until the weekend! haskell/ghcide#815 is in |
Closed by haskell/ghcide#815, thanks @serras! |
Using VSCode you can tag a Diagnostic as
DiagnosticTag.Unnecessary
as per https://github.com/Microsoft/vscode/blob/83625fa9cbbdec3eab4a635c62f88aab0929aa80/src/vs/vscode.d.ts#L3945 to have them rendered in a faded out manner. I suggest thatghcide
should always enable the unused import, unused definition and unused variable warnings, and then map them through as Hint diagnostics (which I guess don't show up in the Problems page?) with Unnecessary as their tag (or higher priority if the user had turned them on too). While I'm not a fan of some of these warnings (unused variables mostly), having the distinction visible in the IDE would be very useful as a feedback sign.As a note of caution, this tagging is only available in the next version of the LSP spec, so because of how new it is, will require adding to the underlying LSP libraries too.
The text was updated successfully, but these errors were encountered: