diff --git a/plugins/hls-stan-plugin/hls-stan-plugin.cabal b/plugins/hls-stan-plugin/hls-stan-plugin.cabal index 748d0a5ba18..bc1e77d8d1e 100644 --- a/plugins/hls-stan-plugin/hls-stan-plugin.cabal +++ b/plugins/hls-stan-plugin/hls-stan-plugin.cabal @@ -25,7 +25,11 @@ flag pedantic default: False manual: True +common warnings + ghc-options: -Wall -Wunused-packages + library + import: warnings if (impl(ghc > 8.8.1) && impl(ghc <= 9.2.3) || impl(ghc >= 9.4.0) && impl(ghc < 9.10.0)) buildable: True else @@ -35,16 +39,13 @@ library build-depends: base , containers - , data-default , deepseq , hashable - , hie-compat , hls-plugin-api , ghc , ghcide , lsp-types , text - , transformers , unordered-containers , stan >= 0.1.2.0 , trial @@ -61,6 +62,7 @@ library OverloadedStrings test-suite test + import: warnings if (impl(ghc > 8.8.1) && impl(ghc <= 9.2.3) || impl(ghc >= 9.4.0) && impl(ghc < 9.10.0)) buildable: True else @@ -71,9 +73,7 @@ test-suite test main-is: Main.hs ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: - aeson , base - , containers , filepath , hls-stan-plugin , hls-plugin-api diff --git a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs index 6389bfb7900..17b5e561d8c 100644 --- a/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs +++ b/plugins/hls-stan-plugin/src/Ide/Plugin/Stan.hs @@ -2,68 +2,46 @@ {-# LANGUAGE PatternSynonyms #-} module Ide.Plugin.Stan (descriptor, Log) where -import Compat.HieTypes (HieASTs, HieFile (..)) -import Control.DeepSeq (NFData) -import Control.Monad (void, when) -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 qualified Data.Text as T +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 qualified Data.Map as Map +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 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 (..), - 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, defaultConfig) -import Stan.Config.Pretty (ConfigAction, configToTriples, - prettyConfigAction, - 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 @@ -101,12 +79,11 @@ stripModifiers = go "" Nothing -> txt Just index -> T.drop (index + 1) txt -renderId :: Id a -> T.Text -renderId (Id t) = "Id = " <> t + instance Pretty Log where pretty = \case - LogShake log -> pretty log + LogShake msg -> pretty msg LogWarnConf errs -> "Fiasco encountered when trying to load stan configuration. Using default inspections:" <> line <> (pretty $ show errs) LogDebugStanConfigResult fps t -> "Config result using: " @@ -162,7 +139,6 @@ rules recorder plId = do -- If envVar is set to 'False', stan will ignore all local and global .stan.toml files logWith recorder Debug (LogDebugStanEnvVars env) - seTomlFiles <- liftIO $ usedTomlFiles useDefConfig (stanArgsConfigFile stanArgs) (cabalExtensionsMap, checksMap, confIgnored) <- case configTrial of FiascoL es -> do @@ -170,7 +146,7 @@ rules recorder plId = do pure (Map.empty, HM.fromList [(LSP.fromNormalizedFilePath file, inspectionsIds)], []) - ResultL warnings stanConfig -> do + ResultL _warnings stanConfig -> do let currentHSAbs = fromNormalizedFilePath file -- hie_hs_file hie currentHSRel <- liftIO $ makeRelativeToCurrentDirectory currentHSAbs cabalExtensionsMap <- liftIO $ createCabalExtensionsMap isLoud (stanArgsCabalFilePath stanArgs) [hie] @@ -178,8 +154,6 @@ rules recorder plId = do -- 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] pure (cabalExtensionsMap, checksMap, configIgnored stanConfig) let analysis = runAnalysis cabalExtensionsMap checksMap confIgnored [hie] return (analysisToDiagnostics file analysis, Just ()) diff --git a/plugins/hls-stan-plugin/test/Main.hs b/plugins/hls-stan-plugin/test/Main.hs index 7b668ea2503..1a0238b020a 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