Skip to content

Commit 9509b27

Browse files
committed
Use relative file paths for HIE files and Stan's config maps
Stan expects relative paths. Without this change, file names won't map correctly to their associated language extension data, which means no enabled extensions will be detected. This causes annoying false positives with, e.g., the `StrictData` extension. (See issue #3174.)
1 parent 4788bfc commit 9509b27

File tree

1 file changed

+11
-10
lines changed
  • plugins/hls-stan-plugin/src/Ide/Plugin

1 file changed

+11
-10
lines changed

plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,25 @@ rules recorder plId = do
164164
logWith recorder Debug (LogDebugStanEnvVars env)
165165
seTomlFiles <- liftIO $ usedTomlFiles useDefConfig (stanArgsConfigFile stanArgs)
166166

167+
-- Note that Stan works in terms of relative paths, but the HIE come in as absolute. Without
168+
-- making its path relative, the file name(s) won't line up with the associated Map keys.
169+
relativeHsFilePath <- liftIO $ makeRelativeToCurrentDirectory $ fromNormalizedFilePath file
170+
let hieRelative = hie{hie_hs_file=relativeHsFilePath}
171+
167172
(cabalExtensionsMap, checksMap, confIgnored) <- case configTrial of
168173
FiascoL es -> do
169174
logWith recorder Development.IDE.Warning (LogWarnConf es)
170175
pure (Map.empty,
171176
HM.fromList [(LSP.fromNormalizedFilePath file, inspectionsIds)],
172177
[])
173178
ResultL warnings stanConfig -> do
174-
let currentHSAbs = fromNormalizedFilePath file -- hie_hs_file hie
175-
currentHSRel <- liftIO $ makeRelativeToCurrentDirectory currentHSAbs
176-
cabalExtensionsMap <- liftIO $ createCabalExtensionsMap isLoud (stanArgsCabalFilePath stanArgs) [hie]
177-
178-
-- Files (keys) in checksMap need to have an absolute path for the analysis, but applyConfig needs to receive relative
179-
-- filepaths to apply the config, because the toml config has relative paths. Stan itself seems to work only in terms of relative paths.
180-
let checksMap = HM.mapKeys (const currentHSAbs) $ applyConfig [currentHSRel] stanConfig
181-
182-
let analysis = runAnalysis cabalExtensionsMap checksMap (configIgnored stanConfig) [hie]
179+
-- A Map from *relative* file paths (just one, in this case) to language extension info.
180+
cabalExtensionsMap <- liftIO $ createCabalExtensionsMap isLoud (stanArgsCabalFilePath stanArgs) [hieRelative]
181+
-- HashMap of *relative* file paths to info about enabled checks for those file paths.
182+
let checksMap = applyConfig [relativeHsFilePath] stanConfig
183183
pure (cabalExtensionsMap, checksMap, configIgnored stanConfig)
184-
let analysis = runAnalysis cabalExtensionsMap checksMap confIgnored [hie]
184+
185+
let analysis = runAnalysis cabalExtensionsMap checksMap confIgnored [hieRelative]
185186
return (analysisToDiagnostics file analysis, Just ())
186187
else return ([], Nothing)
187188

0 commit comments

Comments
 (0)