@@ -35,7 +35,6 @@ import Data.Typeable
35
35
import Development.IDE
36
36
import Development.IDE.Core.Rules (defineNoFile )
37
37
import Development.IDE.Core.Shake (getDiagnostics )
38
- import Development.Shake
39
38
40
39
#ifdef GHC_LIB
41
40
import Development.IDE.Core.RuleTypes (GhcSession (.. ))
@@ -113,9 +112,8 @@ rules = do
113
112
diagnostics :: NormalizedFilePath -> Either ParseError [Idea ] -> [FileDiagnostic ]
114
113
diagnostics file (Right ideas) =
115
114
[(file, ShowDiag , ideaToDiagnostic i) | i <- ideas, ideaSeverity i /= Ignore ]
116
- -- We don't return parse errors as diagnostics cause they match the emitted ones
117
- -- by ghc and they would be duplicated
118
- diagnostics file (Left parseErr) = []
115
+ diagnostics file (Left parseErr) =
116
+ [(file, ShowDiag , parseErrorToDiagnostic parseErr)]
119
117
120
118
ideaToDiagnostic :: Idea -> Diagnostic
121
119
ideaToDiagnostic idea =
@@ -130,6 +128,18 @@ rules = do
130
128
}
131
129
where codePre = if null $ ideaRefactoring idea then " " else " refact:"
132
130
131
+ parseErrorToDiagnostic :: ParseError -> Diagnostic
132
+ parseErrorToDiagnostic (Hlint. ParseError l msg contents) =
133
+ LSP. Diagnostic {
134
+ _range = srcSpanToRange l
135
+ , _severity = Just LSP. DsInfo
136
+ , _code = Just (LSP. StringValue " parser" )
137
+ , _source = Just " hlint"
138
+ , _message = T. unlines [T. pack msg,T. pack contents]
139
+ , _relatedInformation = Nothing
140
+ , _tags = Nothing
141
+ }
142
+
133
143
-- This one is defined in Development.IDE.GHC.Error but here
134
144
-- the types could come from ghc-lib or ghc
135
145
srcSpanToRange :: SrcSpan -> LSP. Range
@@ -157,11 +167,16 @@ getIdeas nfp = do
157
167
where moduleEx :: ParseFlags -> Action (Maybe (Either ParseError ModuleEx ))
158
168
#ifdef GHC_LIB
159
169
moduleEx flags = do
160
- flags' <- setExtensions flags
161
- (_, contents) <- getFileContents nfp
162
- let fp = fromNormalizedFilePath nfp
163
- let contents' = T. unpack <$> contents
164
- Just <$> (liftIO $ parseModuleEx flags' fp contents')
170
+ mbpm <- getParsedModule nfp
171
+ -- If ghc was not able to parse the module, we disable hlint diagnostics
172
+ if isNothing mbpm
173
+ then return Nothing
174
+ else do
175
+ flags' <- setExtensions flags
176
+ (_, contents) <- getFileContents nfp
177
+ let fp = fromNormalizedFilePath nfp
178
+ let contents' = T. unpack <$> contents
179
+ Just <$> (liftIO $ parseModuleEx flags' fp contents')
165
180
166
181
setExtensions flags = do
167
182
hsc <- hscEnv <$> use_ GhcSession nfp
0 commit comments