Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Tag unused warning as such #815

Merged
merged 6 commits into from
Sep 24, 2020
Merged

Conversation

serras
Copy link
Contributor

@serras serras commented Sep 16, 2020

This patch uses the new "unnecessary" or "deprecated" tags for diagnostics to show unused variables/functions/... dimmed in the editor, as discussed in https://github.com/haskell/ghcide/issues/165#issuecomment-692532054

@serras
Copy link
Contributor Author

serras commented Sep 16, 2020

Mandatory screenshot (notice the grey color)

Captura de pantalla 2020-09-16 a las 20 45 06

@ndmitchell
Copy link
Collaborator

Awesome! One question - I usually don't turn off unused variables, just unused top-level bindings. It would be great to still get the grey color. Could we always turn these warnings on, but suppress them from making it to the diagnostics if we turned them on rather than the user?

@serras
Copy link
Contributor Author

serras commented Sep 17, 2020

That sounds like a good idea, it shouldn't be more difficult than the unDefer bussiness in the same file.

@serras
Copy link
Contributor Author

serras commented Sep 18, 2020

It took a bit more than expected, mostly because some tests broke because of that. In fact, locally all the benchmarks fail for me, but I haven't been able to fix them.

Copy link
Collaborator

@ndmitchell ndmitchell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome!

| not (wopt warning originalFlags)
= if warning `elem` unnecessaryDeprecationWarningFlags
then (Reason warning, (nfp, sh, fd{_severity = Just DsInfo}))
else (Reason warning, (nfp, HideDiag, fd))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume HideDiag means they don't appear at all? Could you just look at _tags ahd only Hide the ones with no tags? (I've no idea here, somewhat guessing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good idea: make those with tags "less important" but not hide them.

Implemented in the latest commit.

, Opt_WarnWarningsDeprecations
]

tagDiag :: (WarnReason, FileDiagnostic) -> (WarnReason, FileDiagnostic)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get a comment on what this does and why? (From the code, its clear, but nice to be able to eyeball it without reading the code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment to the file:

-- | Add a unnecessary/deprecated tag to the required diagnostics.

= expectDiagnostics_ . map (\(fp, dd) -> (fp, map (\(ds, c, t) -> (ds, c, t, Nothing)) dd))

expectDiagnostics_ :: [(FilePath, [(DiagnosticSeverity, Cursor, T.Text, Maybe DiagnosticTag)])] -> Session ()
expectDiagnostics_ expected = do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ususally foo_ would be the version of foo that does slightly less than foo, e.g. doesn't return some info. Could we call expectDiagnostics_ something like expectedDiagnosticsTags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it to expectDiagnosticsWithTags.

test/exe/Main.hs Outdated
@@ -3065,6 +3083,8 @@ ifaceErrorTest = testCase "iface-error-test-1" $ withoutStackEnv $ runWithExtraF
-- - P is being typechecked with the last successful artifacts for A.
expectDiagnostics [("P.hs", [(DsWarning,(4,0), "Top-level binding")])
,("P.hs", [(DsWarning,(6,0), "Top-level binding")])
,("P.hs", [(DsInfo,(4,0), "Defined but not used")])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The really important thing is that these diagnostics have the right tag associated with them. While they don't all need to be expectDiagnostics_ (or whatever it ends up being called), a few more being that with the tag assertion would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I've extended the checks in the latest commit.

@ndmitchell
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ndmitchell
Copy link
Collaborator

I see some test failure:

FAIL (0.59s)
      test/src/Development/IDE/Test.hs:77:
      Got unexpected diagnostics for Uri {getUri = "file:///tmp/extra-dir-28584335661024/ModuleA.hs"} got List [Diagnostic {_range = Range {_start = Position {_line = 1, _character = 0}, _end = Position {_line = 1, _character = 29}}, _severity = Just DsInfo, _code = Nothing, _source = Just "typecheck", _message = "The import of \8216ModuleB\8217 is redundant\n  except perhaps to import instances from \8216ModuleB\8217\nTo import instances alone, use: import ModuleB()", _tags = Just (List [DtUnnecessary]), _relatedInformation = Nothing}]

I did have to fix a merge conflict to get it going again. So certainly possible that's my fault.

@serras
Copy link
Contributor Author

serras commented Sep 24, 2020

I see some test failure:

FAIL (0.59s)
      test/src/Development/IDE/Test.hs:77:
      Got unexpected diagnostics for Uri {getUri = "file:///tmp/extra-dir-28584335661024/ModuleA.hs"} got List [Diagnostic {_range = Range {_start = Position {_line = 1, _character = 0}, _end = Position {_line = 1, _character = 29}}, _severity = Just DsInfo, _code = Nothing, _source = Just "typecheck", _message = "The import of \8216ModuleB\8217 is redundant\n  except perhaps to import instances from \8216ModuleB\8217\nTo import instances alone, use: import ModuleB()", _tags = Just (List [DtUnnecessary]), _relatedInformation = Nothing}]

I did have to fix a merge conflict to get it going again. So certainly possible that's my fault.

I've spent some time and fixed the test. Hopefully everything should be green in some minutes.

@ndmitchell ndmitchell merged commit d64397b into haskell:master Sep 24, 2020
@ndmitchell
Copy link
Collaborator

Awesome work - this is a great feature. Thanks for all your hard to work to write it and adjust so much of the test suite.

pepeiborra pushed a commit to pepeiborra/ghcide that referenced this pull request Oct 5, 2020
* Tag unused warning as such

* Fix compilation for 8.4

* Always enable warning for unneeded elements + fix tests for them

* Apply suggestions by @ndmitchell

* Fix a diagnostics test after merge

Co-authored-by: Neil Mitchell <[email protected]>
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Tag unused warning as such

* Fix compilation for 8.4

* Always enable warning for unneeded elements + fix tests for them

* Apply suggestions by @ndmitchell

* Fix a diagnostics test after merge

Co-authored-by: Neil Mitchell <[email protected]>
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Tag unused warning as such

* Fix compilation for 8.4

* Always enable warning for unneeded elements + fix tests for them

* Apply suggestions by @ndmitchell

* Fix a diagnostics test after merge

Co-authored-by: Neil Mitchell <[email protected]>
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Tag unused warning as such

* Fix compilation for 8.4

* Always enable warning for unneeded elements + fix tests for them

* Apply suggestions by @ndmitchell

* Fix a diagnostics test after merge

Co-authored-by: Neil Mitchell <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants