-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Changes from all commits
16d6ea6
84f576f
01874ec
86d34f0
c8c3f64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,6 @@ import Development.IDE.Core.Shake (getDiagnost | |
import qualified Refact.Apply as Refact | ||
|
||
#ifdef HLINT_ON_GHC_LIB | ||
import Data.List (nub) | ||
import Development.IDE.GHC.Compat (BufSpan, | ||
DynFlags, | ||
WarningFlag (Opt_WarnUnrecognisedPragmas), | ||
|
@@ -284,16 +283,26 @@ 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 | ||
-- Gets extensions from ModSummary dynflags for the file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Argh, there's a somewhat important typo. It's supposed to be, "this is used when HLINT_ON_GHC_LIB is defined" instead of "is not". Gonna add it to the |
||
-- Previously this would concatenate extensions from both hlint's parsedFlags | ||
-- and the ModSummary dynflags. However using the parsedFlags extensions | ||
-- can sometimes interfere with the hlint parsing of the file. | ||
-- See https://github.com/haskell/haskell-language-server/issues/1279 | ||
-- | ||
-- Note: this is used when HLINT_ON_GHC_LIB is not defined. We seem to need | ||
-- these extensions to construct dynflags to parse the file again. Therefore | ||
-- using hlint default extensions doesn't seem to be a problem when | ||
-- HLINT_ON_GHC_LIB is not defined because we don't parse the file again. | ||
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 = hscExts' | ||
return hlintExts | ||
where getFlags :: Action DynFlags | ||
getFlags = do | ||
|
@@ -538,8 +547,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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should maybe be in a "known limitations" section on the features page too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll add that.