From 9509b277807eb36cebb8db462962349657b354b3 Mon Sep 17 00:00:00 2001 From: ktf Date: Sun, 28 Jan 2024 15:58:50 -0800 Subject: [PATCH 1/9] 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.) --- .../hls-stan-plugin/src/Ide/Plugin/Stan.hs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs index 6389bfb790..9486636357 100644 --- a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs +++ b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs @@ -164,6 +164,11 @@ rules recorder plId = do logWith recorder Debug (LogDebugStanEnvVars env) seTomlFiles <- liftIO $ usedTomlFiles useDefConfig (stanArgsConfigFile stanArgs) + -- Note that Stan works in terms of relative paths, but the HIE come in as absolute. Without + -- making its path relative, the file name(s) won't line up with the associated Map keys. + relativeHsFilePath <- liftIO $ makeRelativeToCurrentDirectory $ fromNormalizedFilePath file + let hieRelative = hie{hie_hs_file=relativeHsFilePath} + (cabalExtensionsMap, checksMap, confIgnored) <- case configTrial of FiascoL es -> do logWith recorder Development.IDE.Warning (LogWarnConf es) @@ -171,17 +176,13 @@ rules recorder plId = do HM.fromList [(LSP.fromNormalizedFilePath file, inspectionsIds)], []) ResultL warnings stanConfig -> do - let currentHSAbs = fromNormalizedFilePath file -- hie_hs_file hie - currentHSRel <- liftIO $ makeRelativeToCurrentDirectory currentHSAbs - cabalExtensionsMap <- liftIO $ createCabalExtensionsMap isLoud (stanArgsCabalFilePath stanArgs) [hie] - - -- Files (keys) in checksMap need to have an absolute path for the analysis, but applyConfig needs to receive relative - -- filepaths to apply the config, because the toml config has relative paths. Stan itself seems to work only in terms of relative paths. - let checksMap = HM.mapKeys (const currentHSAbs) $ applyConfig [currentHSRel] stanConfig - - let analysis = runAnalysis cabalExtensionsMap checksMap (configIgnored stanConfig) [hie] + -- A Map from *relative* file paths (just one, in this case) to language extension info. + cabalExtensionsMap <- liftIO $ createCabalExtensionsMap isLoud (stanArgsCabalFilePath stanArgs) [hieRelative] + -- HashMap of *relative* file paths to info about enabled checks for those file paths. + let checksMap = applyConfig [relativeHsFilePath] stanConfig pure (cabalExtensionsMap, checksMap, configIgnored stanConfig) - let analysis = runAnalysis cabalExtensionsMap checksMap confIgnored [hie] + + let analysis = runAnalysis cabalExtensionsMap checksMap confIgnored [hieRelative] return (analysisToDiagnostics file analysis, Just ()) else return ([], Nothing) From 4e95308b758bd7035cf9db98cf6fa454f91aab45 Mon Sep 17 00:00:00 2001 From: ktf Date: Mon, 29 Jan 2024 22:01:19 -0800 Subject: [PATCH 2/9] Un-exclude Stan diagnostics related to `StrictData` We specifically want to test this diagnostic, so we need it to fire. --- plugins/hls-stan-plugin/test/testdata/.stan.toml | 10 ---------- .../hls-stan-plugin/test/testdata/dir/configTest.hs | 2 -- 2 files changed, 12 deletions(-) diff --git a/plugins/hls-stan-plugin/test/testdata/.stan.toml b/plugins/hls-stan-plugin/test/testdata/.stan.toml index faff35467a..ce73b7f29c 100644 --- a/plugins/hls-stan-plugin/test/testdata/.stan.toml +++ b/plugins/hls-stan-plugin/test/testdata/.stan.toml @@ -1,10 +1,5 @@ # See https://github.com/kowainik/stan/issues/531 # Unix -[[check]] -type = "Exclude" -id = "STAN-0206" -scope = "all" - [[check]] type = "Exclude" id = "STAN-0103" @@ -16,11 +11,6 @@ id = "STAN-0212" directory = "dir/" # Windows -[[check]] -type = "Exclude" -id = "STAN-0206" -scope = "all" - [[check]] type = "Exclude" id = "STAN-0103" diff --git a/plugins/hls-stan-plugin/test/testdata/dir/configTest.hs b/plugins/hls-stan-plugin/test/testdata/dir/configTest.hs index b2ed26a745..add256058b 100644 --- a/plugins/hls-stan-plugin/test/testdata/dir/configTest.hs +++ b/plugins/hls-stan-plugin/test/testdata/dir/configTest.hs @@ -1,5 +1,3 @@ -data A = A Int Int - a = length [1..] b = undefined From 802b46cc8b8ef3578765815d58fb008909c9f2c2 Mon Sep 17 00:00:00 2001 From: ktf Date: Mon, 29 Jan 2024 22:07:54 -0800 Subject: [PATCH 3/9] Add tests to ensure the Stan plugin detects a module's language extensions Includes test cases for both `LANGUAGE` pragmas and extensions enabled in a project's `.cabal` file. --- plugins/hls-stan-plugin/test/Main.hs | 12 ++++++++++++ .../extension-tests/cabal-file/CabalFileTest.hs | 4 ++++ .../extension-tests/cabal-file/cabal-file-test.cabal | 9 +++++++++ .../language-pragma/LanguagePragmaTest.hs | 6 ++++++ .../language-pragma/language-pragma-test.cabal | 11 +++++++++++ 5 files changed, 42 insertions(+) create mode 100644 plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs create mode 100644 plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/cabal-file-test.cabal create mode 100644 plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs create mode 100644 plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/language-pragma-test.cabal diff --git a/plugins/hls-stan-plugin/test/Main.hs b/plugins/hls-stan-plugin/test/Main.hs index 7b668ea250..6f0a41ca9b 100644 --- a/plugins/hls-stan-plugin/test/Main.hs +++ b/plugins/hls-stan-plugin/test/Main.hs @@ -40,6 +40,18 @@ tests = diags <- waitForDiagnosticsFromSource doc "stan" liftIO $ length diags @?= 0 return () + , testCase "respects LANGUAGE pragmas in the source file" $ + runStanSession "" $ do + doc <- openDoc "extension-tests/language-pragma/LanguagePragmaTest.hs" "haskell" + diags <- waitForDiagnosticsFromSource doc "stan" + liftIO $ length diags @?= 0 + return () + , testCase "respects language extensions defined in the .cabal file" $ + runStanSession "" $ do + doc <- openDoc "extension-tests/cabal-file/CabalFileTest.hs" "haskell" + diags <- waitForDiagnosticsFromSource doc "stan" + liftIO $ length diags @?= 0 + return () ] testDir :: FilePath diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs b/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs new file mode 100644 index 0000000000..71b4380104 --- /dev/null +++ b/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs @@ -0,0 +1,4 @@ +module CabalFileTest () where + +-- With `StrictData` enabled in the `.cabal` file, Stan shouldn't complain here: +data A = A Int Int diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/cabal-file-test.cabal b/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/cabal-file-test.cabal new file mode 100644 index 0000000000..aad229c82b --- /dev/null +++ b/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/cabal-file-test.cabal @@ -0,0 +1,9 @@ +cabal-version: 3.0 +name: cabal-file-test +version: 0.0.0.0 + +library + exposed-modules: CabalFileTest + hs-source-dirs: extension-tests/cabal-file + -- Specifically, we're testing that Stan respects the following extension definition: + default-extensions: StrictData diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs b/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs new file mode 100644 index 0000000000..3da9a28254 --- /dev/null +++ b/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs @@ -0,0 +1,6 @@ +{-# LANGUAGE StrictData #-} + +module LanguagePragmaTest () where + +-- With the above `StrictData` language pragma, Stan shouldn't complain here: +data A = A Int Int diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/language-pragma-test.cabal b/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/language-pragma-test.cabal new file mode 100644 index 0000000000..a862644032 --- /dev/null +++ b/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/language-pragma-test.cabal @@ -0,0 +1,11 @@ +cabal-version: 3.0 +name: language-pragma-test +version: 0.0.0.0 + +-- Without at least a minimal valid `.cabal` file, Stan won't bother building its +-- map of language extensions. This means it also won't detect LANGUAGE pragmas +-- without this file. + +library + exposed-modules: LanguagePragmaTest + hs-source-dirs: extension-tests/language-pragma From c0dac2e61c131a8c489c5cf5ee73846ea4658531 Mon Sep 17 00:00:00 2001 From: ktf Date: Tue, 30 Jan 2024 16:27:06 -0800 Subject: [PATCH 4/9] Tighten up Stan plugin language extension test cases These changes ensure that the tests will fail given bad mappings in either the `cabalExtensionsMap` OR the `checksMap`. Either of these could cause bad behavior as seen in issue #3174. --- plugins/hls-stan-plugin/test/Main.hs | 8 ++++++-- .../testdata/extension-tests/cabal-file/CabalFileTest.hs | 3 +++ .../extension-tests/language-pragma/LanguagePragmaTest.hs | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/hls-stan-plugin/test/Main.hs b/plugins/hls-stan-plugin/test/Main.hs index 6f0a41ca9b..32cdd7c41e 100644 --- a/plugins/hls-stan-plugin/test/Main.hs +++ b/plugins/hls-stan-plugin/test/Main.hs @@ -44,13 +44,17 @@ tests = runStanSession "" $ do doc <- openDoc "extension-tests/language-pragma/LanguagePragmaTest.hs" "haskell" diags <- waitForDiagnosticsFromSource doc "stan" - liftIO $ length diags @?= 0 + -- We must include at least one valid diagnostic in our test file to avoid + -- the false-positive case where Stan finds no analyses to perform due to a + -- bad mapping, which would also lead to zero diagnostics being returned. + liftIO $ length diags @?= 1 return () , testCase "respects language extensions defined in the .cabal file" $ runStanSession "" $ do doc <- openDoc "extension-tests/cabal-file/CabalFileTest.hs" "haskell" diags <- waitForDiagnosticsFromSource doc "stan" - liftIO $ length diags @?= 0 + -- We need at least one valid diagnostic here too, for the same reason as above. + liftIO $ length diags @?= 1 return () ] diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs b/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs index 71b4380104..77b6dc3845 100644 --- a/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs +++ b/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs @@ -2,3 +2,6 @@ module CabalFileTest () where -- With `StrictData` enabled in the `.cabal` file, Stan shouldn't complain here: data A = A Int Int + +-- ...but it should still complain here! +kewlFunc = undefined diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs b/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs index 3da9a28254..6f5631ac8c 100644 --- a/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs +++ b/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs @@ -4,3 +4,6 @@ module LanguagePragmaTest () where -- With the above `StrictData` language pragma, Stan shouldn't complain here: data A = A Int Int + +-- ...but it should still complain here! +kewlFunc = undefined From e6a85206dccc08fec9cfe907e308987b52c3b8d5 Mon Sep 17 00:00:00 2001 From: ktf Date: Wed, 31 Jan 2024 14:03:11 -0800 Subject: [PATCH 5/9] Use correct extension/file mappings even in the case of a config fiasco The Stan plugin will still operate as expected even if we can't load a config -- it will simply default to showing all inspections. --- plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs index 9486636357..b97e50f4e1 100644 --- a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs +++ b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs @@ -169,20 +169,20 @@ rules recorder plId = do relativeHsFilePath <- liftIO $ makeRelativeToCurrentDirectory $ fromNormalizedFilePath file let hieRelative = hie{hie_hs_file=relativeHsFilePath} - (cabalExtensionsMap, checksMap, confIgnored) <- case configTrial of + (checksMap, ignoredObservations) <- case configTrial of FiascoL es -> do logWith recorder Development.IDE.Warning (LogWarnConf es) - pure (Map.empty, - HM.fromList [(LSP.fromNormalizedFilePath file, inspectionsIds)], - []) - ResultL warnings stanConfig -> do - -- A Map from *relative* file paths (just one, in this case) to language extension info. - cabalExtensionsMap <- liftIO $ createCabalExtensionsMap isLoud (stanArgsCabalFilePath stanArgs) [hieRelative] + -- If we can't read the config file, default to using all inspections: + let allInspections = HM.fromList [(relativeHsFilePath, inspectionsIds)] + pure (allInspections, []) + ResultL _warnings stanConfig -> do -- HashMap of *relative* file paths to info about enabled checks for those file paths. let checksMap = applyConfig [relativeHsFilePath] stanConfig - pure (cabalExtensionsMap, checksMap, configIgnored stanConfig) + pure (checksMap, configIgnored stanConfig) - let analysis = runAnalysis cabalExtensionsMap checksMap confIgnored [hieRelative] + -- A Map from *relative* file paths (just one, in this case) to language extension info: + cabalExtensionsMap <- liftIO $ createCabalExtensionsMap isLoud (stanArgsCabalFilePath stanArgs) [hieRelative] + let analysis = runAnalysis cabalExtensionsMap checksMap ignoredObservations [hieRelative] return (analysisToDiagnostics file analysis, Just ()) else return ([], Nothing) From 188c7675540508bdb34447b3ddeda317ed65f2a5 Mon Sep 17 00:00:00 2001 From: ktf Date: Thu, 1 Feb 2024 16:03:37 -0800 Subject: [PATCH 6/9] Remove a slew of unused imports --- .../hls-stan-plugin/src/Ide/Plugin/Stan.hs | 33 ++++--------------- plugins/hls-stan-plugin/test/Main.hs | 4 --- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs index b97e50f4e1..3f803bc76b 100644 --- a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs +++ b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs @@ -2,36 +2,18 @@ {-# LANGUAGE PatternSynonyms #-} module Ide.Plugin.Stan (descriptor, Log) where -import Compat.HieTypes (HieASTs, HieFile (..)) +import Compat.HieTypes (HieFile (..)) import Control.DeepSeq (NFData) -import Control.Monad (void, when) +import Control.Monad (void) import Control.Monad.IO.Class (liftIO) -import Control.Monad.Trans.Maybe (MaybeT (MaybeT), runMaybeT) -import Data.Default import Data.Foldable (toList) import Data.Hashable (Hashable) import qualified Data.HashMap.Strict as HM -import Data.HashSet (HashSet) -import qualified Data.HashSet as HS -import qualified Data.Map as Map -import Data.Maybe (fromJust, mapMaybe, - maybeToList) -import Data.String (IsString (fromString)) +import Data.Maybe (mapMaybe) import qualified Data.Text as T import Development.IDE -import Development.IDE.Core.Rules (getHieFile, - getSourceFileSource) -import Development.IDE.Core.RuleTypes (HieAstResult (..)) +import Development.IDE.Core.Rules (getHieFile) import qualified Development.IDE.Core.Shake as Shake -import Development.IDE.GHC.Compat (HieASTs (HieASTs), - HieFile (hie_hs_file), - RealSrcSpan (..), mkHieFile', - mkRealSrcLoc, mkRealSrcSpan, - runHsc, srcSpanEndCol, - srcSpanEndLine, - srcSpanStartCol, - srcSpanStartLine, tcg_exports) -import Development.IDE.GHC.Error (realSrcSpanToRange) import GHC.Generics (Generic) import Ide.Plugin.Config (PluginConfig (..)) import Ide.Types (PluginDescriptor (..), @@ -45,11 +27,8 @@ import Stan (createCabalExtensionsMap, import Stan.Analysis (Analysis (..), runAnalysis) import Stan.Category (Category (..)) import Stan.Cli (StanArgs (..)) -import Stan.Config (Config, ConfigP (..), - applyConfig, defaultConfig) -import Stan.Config.Pretty (ConfigAction, configToTriples, - prettyConfigAction, - prettyConfigCli) +import Stan.Config (Config, ConfigP (..), applyConfig) +import Stan.Config.Pretty (prettyConfigCli) import Stan.Core.Id (Id (..)) import Stan.EnvVars (EnvVars (..), envVarsToText) import Stan.Inspection (Inspection (..)) diff --git a/plugins/hls-stan-plugin/test/Main.hs b/plugins/hls-stan-plugin/test/Main.hs index 4cf6e9c475..e9318043e6 100644 --- a/plugins/hls-stan-plugin/test/Main.hs +++ b/plugins/hls-stan-plugin/test/Main.hs @@ -4,11 +4,7 @@ module Main where import Control.Lens ((^.)) -import Control.Monad (void) -import Data.List (find) -import Data.Text (Text) import qualified Data.Text as T -import qualified Data.Text.IO as T import qualified Ide.Plugin.Stan as Stan import Ide.Types import qualified Language.LSP.Protocol.Lens as L From d028cd6daa5d982a04d825ebb494c16278dd3c09 Mon Sep 17 00:00:00 2001 From: ktf Date: Thu, 1 Feb 2024 16:05:29 -0800 Subject: [PATCH 7/9] Use OS-agnostic path separators in tests --- plugins/hls-stan-plugin/test/Main.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/hls-stan-plugin/test/Main.hs b/plugins/hls-stan-plugin/test/Main.hs index e9318043e6..ebaf51a46b 100644 --- a/plugins/hls-stan-plugin/test/Main.hs +++ b/plugins/hls-stan-plugin/test/Main.hs @@ -32,13 +32,13 @@ tests = return () , testCase "ignores diagnostics from .stan.toml" $ runStanSession "" $ do - doc <- openDoc "dir/configTest.hs" "haskell" + doc <- openDoc ("dir" "configTest.hs") "haskell" diags <- waitForDiagnosticsFromSource doc "stan" liftIO $ length diags @?= 0 return () , testCase "respects LANGUAGE pragmas in the source file" $ runStanSession "" $ do - doc <- openDoc "extension-tests/language-pragma/LanguagePragmaTest.hs" "haskell" + doc <- openDoc ("extension-tests" "language-pragma" "LanguagePragmaTest.hs") "haskell" diags <- waitForDiagnosticsFromSource doc "stan" -- We must include at least one valid diagnostic in our test file to avoid -- the false-positive case where Stan finds no analyses to perform due to a @@ -47,7 +47,7 @@ tests = return () , testCase "respects language extensions defined in the .cabal file" $ runStanSession "" $ do - doc <- openDoc "extension-tests/cabal-file/CabalFileTest.hs" "haskell" + doc <- openDoc ("extension-tests" "cabal-file" "CabalFileTest.hs") "haskell" diags <- waitForDiagnosticsFromSource doc "stan" -- We need at least one valid diagnostic here too, for the same reason as above. liftIO $ length diags @?= 1 @@ -55,7 +55,7 @@ tests = ] testDir :: FilePath -testDir = "plugins/hls-stan-plugin/test/testdata" +testDir = "plugins" "hls-stan-plugin" "test" "testdata" stanPlugin :: PluginTestDescriptor Stan.Log stanPlugin = mkPluginTestDescriptor enabledStanDescriptor "stan" From fc2aff01e1893770ba15f442b60659ad5bbb69b3 Mon Sep 17 00:00:00 2001 From: ktf Date: Thu, 1 Feb 2024 16:21:22 -0800 Subject: [PATCH 8/9] Run `stylish-haskell` --- .../hls-stan-plugin/src/Ide/Plugin/Stan.hs | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs index 3f803bc76b..b902218a38 100644 --- a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs +++ b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs @@ -2,47 +2,47 @@ {-# LANGUAGE PatternSynonyms #-} module Ide.Plugin.Stan (descriptor, Log) where -import Compat.HieTypes (HieFile (..)) -import Control.DeepSeq (NFData) -import Control.Monad (void) -import Control.Monad.IO.Class (liftIO) -import Data.Foldable (toList) -import Data.Hashable (Hashable) -import qualified Data.HashMap.Strict as HM -import Data.Maybe (mapMaybe) -import qualified Data.Text as T +import Compat.HieTypes (HieFile (..)) +import Control.DeepSeq (NFData) +import Control.Monad (void) +import Control.Monad.IO.Class (liftIO) +import Data.Foldable (toList) +import Data.Hashable (Hashable) +import qualified Data.HashMap.Strict as HM +import Data.Maybe (mapMaybe) +import qualified Data.Text as T import Development.IDE -import Development.IDE.Core.Rules (getHieFile) -import qualified Development.IDE.Core.Shake as Shake -import GHC.Generics (Generic) -import Ide.Plugin.Config (PluginConfig (..)) -import Ide.Types (PluginDescriptor (..), - PluginId, configHasDiagnostics, - configInitialGenericConfig, - defaultConfigDescriptor, - defaultPluginDescriptor) -import qualified Language.LSP.Protocol.Types as LSP -import Stan (createCabalExtensionsMap, - getStanConfig) -import Stan.Analysis (Analysis (..), runAnalysis) -import Stan.Category (Category (..)) -import Stan.Cli (StanArgs (..)) -import Stan.Config (Config, ConfigP (..), applyConfig) -import Stan.Config.Pretty (prettyConfigCli) -import Stan.Core.Id (Id (..)) -import Stan.EnvVars (EnvVars (..), envVarsToText) -import Stan.Inspection (Inspection (..)) -import Stan.Inspection.All (inspectionsIds, inspectionsMap) -import Stan.Observation (Observation (..)) -import Stan.Report.Settings (OutputSettings (..), - ToggleSolution (..), - Verbosity (..)) -import Stan.Toml (usedTomlFiles) -import System.Directory (makeRelativeToCurrentDirectory) -import Trial (Fatality, Trial (..), fiasco, - pattern FiascoL, - pattern ResultL, prettyTrial, - prettyTrialWith) +import Development.IDE.Core.Rules (getHieFile) +import qualified Development.IDE.Core.Shake as Shake +import GHC.Generics (Generic) +import Ide.Plugin.Config (PluginConfig (..)) +import Ide.Types (PluginDescriptor (..), PluginId, + configHasDiagnostics, + configInitialGenericConfig, + defaultConfigDescriptor, + defaultPluginDescriptor) +import qualified Language.LSP.Protocol.Types as LSP +import Stan (createCabalExtensionsMap, + getStanConfig) +import Stan.Analysis (Analysis (..), runAnalysis) +import Stan.Category (Category (..)) +import Stan.Cli (StanArgs (..)) +import Stan.Config (Config, ConfigP (..), applyConfig) +import Stan.Config.Pretty (prettyConfigCli) +import Stan.Core.Id (Id (..)) +import Stan.EnvVars (EnvVars (..), envVarsToText) +import Stan.Inspection (Inspection (..)) +import Stan.Inspection.All (inspectionsIds, inspectionsMap) +import Stan.Observation (Observation (..)) +import Stan.Report.Settings (OutputSettings (..), + ToggleSolution (..), + Verbosity (..)) +import Stan.Toml (usedTomlFiles) +import System.Directory (makeRelativeToCurrentDirectory) +import Trial (Fatality, Trial (..), fiasco, + pattern FiascoL, pattern ResultL, + prettyTrial, prettyTrialWith) + descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState descriptor recorder plId = (defaultPluginDescriptor plId desc) { pluginRules = rules recorder plId From c24f564cd8bb78be7e492a68885be1a3f3bcaae8 Mon Sep 17 00:00:00 2001 From: ktf Date: Thu, 1 Feb 2024 20:36:29 -0800 Subject: [PATCH 9/9] Ensure `hs-source-dirs` in test cabal files don't contain path separators Related to (what I assume is) a bug in Stan, or its `extensions` library. Regardless of OS, the `hs-source-dirs` field is prepended as-is to the module name to create the file paths used in the cabal extensions map. This means the maps won't work in Windows if your cabal file contains `/` path separators. Working around the limitation here to ensure tests work on all platforms. --- plugins/hls-stan-plugin/test/Main.hs | 4 ++-- .../cabal-file => extensions-cabal-file}/CabalFileTest.hs | 0 .../cabal-file-test.cabal | 2 +- .../LanguagePragmaTest.hs | 0 .../language-pragma-test.cabal | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename plugins/hls-stan-plugin/test/testdata/{extension-tests/cabal-file => extensions-cabal-file}/CabalFileTest.hs (100%) rename plugins/hls-stan-plugin/test/testdata/{extension-tests/cabal-file => extensions-cabal-file}/cabal-file-test.cabal (83%) rename plugins/hls-stan-plugin/test/testdata/{extension-tests/language-pragma => extensions-language-pragma}/LanguagePragmaTest.hs (100%) rename plugins/hls-stan-plugin/test/testdata/{extension-tests/language-pragma => extensions-language-pragma}/language-pragma-test.cabal (85%) diff --git a/plugins/hls-stan-plugin/test/Main.hs b/plugins/hls-stan-plugin/test/Main.hs index ebaf51a46b..650760c9dc 100644 --- a/plugins/hls-stan-plugin/test/Main.hs +++ b/plugins/hls-stan-plugin/test/Main.hs @@ -38,7 +38,7 @@ tests = return () , testCase "respects LANGUAGE pragmas in the source file" $ runStanSession "" $ do - doc <- openDoc ("extension-tests" "language-pragma" "LanguagePragmaTest.hs") "haskell" + doc <- openDoc ("extensions-language-pragma" "LanguagePragmaTest.hs") "haskell" diags <- waitForDiagnosticsFromSource doc "stan" -- We must include at least one valid diagnostic in our test file to avoid -- the false-positive case where Stan finds no analyses to perform due to a @@ -47,7 +47,7 @@ tests = return () , testCase "respects language extensions defined in the .cabal file" $ runStanSession "" $ do - doc <- openDoc ("extension-tests" "cabal-file" "CabalFileTest.hs") "haskell" + doc <- openDoc ("extensions-cabal-file" "CabalFileTest.hs") "haskell" diags <- waitForDiagnosticsFromSource doc "stan" -- We need at least one valid diagnostic here too, for the same reason as above. liftIO $ length diags @?= 1 diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs b/plugins/hls-stan-plugin/test/testdata/extensions-cabal-file/CabalFileTest.hs similarity index 100% rename from plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/CabalFileTest.hs rename to plugins/hls-stan-plugin/test/testdata/extensions-cabal-file/CabalFileTest.hs diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/cabal-file-test.cabal b/plugins/hls-stan-plugin/test/testdata/extensions-cabal-file/cabal-file-test.cabal similarity index 83% rename from plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/cabal-file-test.cabal rename to plugins/hls-stan-plugin/test/testdata/extensions-cabal-file/cabal-file-test.cabal index aad229c82b..094f06d1dd 100644 --- a/plugins/hls-stan-plugin/test/testdata/extension-tests/cabal-file/cabal-file-test.cabal +++ b/plugins/hls-stan-plugin/test/testdata/extensions-cabal-file/cabal-file-test.cabal @@ -4,6 +4,6 @@ version: 0.0.0.0 library exposed-modules: CabalFileTest - hs-source-dirs: extension-tests/cabal-file + hs-source-dirs: extensions-cabal-file -- Specifically, we're testing that Stan respects the following extension definition: default-extensions: StrictData diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs b/plugins/hls-stan-plugin/test/testdata/extensions-language-pragma/LanguagePragmaTest.hs similarity index 100% rename from plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/LanguagePragmaTest.hs rename to plugins/hls-stan-plugin/test/testdata/extensions-language-pragma/LanguagePragmaTest.hs diff --git a/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/language-pragma-test.cabal b/plugins/hls-stan-plugin/test/testdata/extensions-language-pragma/language-pragma-test.cabal similarity index 85% rename from plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/language-pragma-test.cabal rename to plugins/hls-stan-plugin/test/testdata/extensions-language-pragma/language-pragma-test.cabal index a862644032..336388d4fa 100644 --- a/plugins/hls-stan-plugin/test/testdata/extension-tests/language-pragma/language-pragma-test.cabal +++ b/plugins/hls-stan-plugin/test/testdata/extensions-language-pragma/language-pragma-test.cabal @@ -8,4 +8,4 @@ version: 0.0.0.0 library exposed-modules: LanguagePragmaTest - hs-source-dirs: extension-tests/language-pragma + hs-source-dirs: extensions-language-pragma