Skip to content
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

Fix hlint parsing file with disabled extension #2671

Merged
merged 5 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,16 @@ getIdeas nfp = do
Just <$> liftIO (parseModuleEx flags' fp contents')

setExtensions flags = do
hlintExts <- getExtensions flags nfp
hlintExts <- getExtensions nfp
debugm $ "hlint:getIdeas:setExtensions:" ++ show hlintExts
return $ flags { enabledExtensions = hlintExts }

getExtensions :: ParseFlags -> NormalizedFilePath -> Action [Extension]
getExtensions pflags nfp = do
getExtensions :: NormalizedFilePath -> Action [Extension]
getExtensions nfp = do
dflags <- getFlags
let hscExts = EnumSet.toList (extensionFlags dflags)
let hscExts' = mapMaybe (GhclibParserEx.readExtension . show) hscExts
let hlintExts = nub $ enabledExtensions pflags ++ hscExts'
let hlintExts = nub hscExts'
eddiemundo marked this conversation as resolved.
Show resolved Hide resolved
return hlintExts
where getFlags :: Action DynFlags
getFlags = do
Expand Down Expand Up @@ -538,8 +538,7 @@ applyHint ide nfp mhint =
liftIO $ withSystemTempFile (takeFileName fp) $ \temp h -> do
hClose h
writeFileUTF8NoNewLineTranslation temp oldContent
(pflags, _, _) <- runAction' $ useNoFile_ GetHlintSettings
eddiemundo marked this conversation as resolved.
Show resolved Hide resolved
exts <- runAction' $ getExtensions pflags nfp
exts <- runAction' $ getExtensions nfp
-- We have to reparse extensions to remove the invalid ones
let (enabled, disabled, _invalid) = Refact.parseExtensions $ map show exts
let refactExts = map show $ enabled ++ disabled
Expand Down
6 changes: 2 additions & 4 deletions plugins/hls-hlint-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ suggestionsTests =
changeDoc doc [change']
testHlintDiagnostics doc

, knownBrokenForHlintOnGhcLib "hlint doesn't take in account cpp flag as ghc -D argument" $
testCase "[#554] hlint diagnostics works with CPP via ghc -XCPP argument" $ runHlintSession "cpp" $ do
, testCase "[#554] hlint diagnostics works with CPP via ghc -XCPP argument" $ runHlintSession "cpp" $ do
doc <- openDoc "CppCond.hs" "haskell"
testHlintDiagnostics doc

Expand Down Expand Up @@ -212,8 +211,7 @@ suggestionsTests =
length diags @?= 1
unusedExt ^. L.code @?= Just (InR "refact:Unused LANGUAGE pragma")

, knownBrokenForHlintOnGhcLib "[#1279] hlint uses a fixed set of extensions" $
testCase "hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do
, testCase "[#1279] hlint should not activate extensions like PatternSynonyms" $ runHlintSession "" $ do
doc <- openDoc "PatternKeyword.hs" "haskell"

waitForAllProgressDone
Expand Down