packages feed

hls-stan-plugin 1.0.0.0 → 1.0.1.0

raw patch · 3 files changed

+40/−36 lines, 3 filesdep +data-defaultdep ~hls-test-utils

Dependencies added: data-default

Dependency ranges changed: hls-test-utils

Files

hls-stan-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name:          hls-stan-plugin-version:       1.0.0.0+version:       1.0.1.0 synopsis:      Stan integration plugin with Haskell Language Server description:   Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -16,14 +16,17 @@   LICENSE   test/testdata/*.hs +source-repository head+    type:     git+    location: https://github.com/haskell/haskell-language-server.git+ flag pedantic   description: Enable -Werror   default:     False   manual:      True - library-  if impl(ghc < 8.8) || impl(ghc >= 9.0)+  if impl(ghc < 8.10) || impl(ghc >= 9.0)     buildable: False   else     buildable: True@@ -32,6 +35,7 @@   build-depends:       base     , containers+    , data-default     , deepseq     , hashable     , hls-plugin-api@@ -54,7 +58,7 @@     OverloadedStrings  test-suite test-  if impl(ghc < 8.8) || impl(ghc >= 9.0)+  if impl(ghc < 8.10) || impl(ghc >= 9.0)     buildable: False   else     buildable: True@@ -70,7 +74,7 @@     , filepath     , hls-stan-plugin     , hls-plugin-api-    , hls-test-utils      ^>=1.3 || ^>= 1.4+    , hls-test-utils      ^>=1.5     , lens     , lsp-types     , text
src/Ide/Plugin/Stan.hs view
@@ -1,29 +1,18 @@-module Ide.Plugin.Stan (descriptor) where+module Ide.Plugin.Stan (descriptor, Log) where  import           Control.DeepSeq                (NFData) import           Control.Monad                  (void) import           Control.Monad.IO.Class         (liftIO) import           Control.Monad.Trans.Class      (lift) 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 qualified Data.Map                       as Map import           Data.Maybe                     (fromJust, mapMaybe) import qualified Data.Text                      as T-import           Development.IDE                (Action, FileDiagnostic,-                                                 GetHieAst (..),-                                                 GetModSummaryWithoutTimestamps (..),-                                                 GhcSession (..), IdeState,-                                                 NormalizedFilePath,-                                                 Pretty (..), Recorder,-                                                 RuleResult, Rules,-                                                 ShowDiagnostic (..),-                                                 TypeCheck (..), WithPriority,-                                                 action, cmapWithPrio, define,-                                                 getFilesOfInterestUntracked,-                                                 hscEnv, msrModSummary,-                                                 tmrTypechecked, use, uses)+import           Development.IDE import           Development.IDE.Core.Rules     (getHieFile,                                                  getSourceFileSource) import           Development.IDE.Core.RuleTypes (HieAstResult (..))@@ -38,9 +27,12 @@ import           Development.IDE.GHC.Error      (realSrcSpanToRange) import           GHC.Generics                   (Generic) import           HieTypes                       (HieASTs, HieFile)+import           Ide.Plugin.Config import           Ide.Types                      (PluginDescriptor (..),-                                                 PluginId,-                                                 defaultPluginDescriptor)+                                                 PluginId, configHasDiagnostics,+                                                 defaultConfigDescriptor,+                                                 defaultPluginDescriptor,+                                                 pluginEnabledConfig) import qualified Language.LSP.Types             as LSP import           Stan.Analysis                  (Analysis (..), runAnalysis) import           Stan.Category                  (Category (..))@@ -50,7 +42,12 @@ import           Stan.Observation               (Observation (..))  descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState-descriptor recorder plId = (defaultPluginDescriptor plId) {pluginRules = rules recorder}+descriptor recorder plId = (defaultPluginDescriptor plId)+  { pluginRules = rules recorder plId+  , pluginConfigDescriptor = defaultConfigDescriptor+      { configHasDiagnostics = True+      }+    }  newtype Log = LogShake Shake.Log deriving (Show) @@ -67,18 +64,21 @@  type instance RuleResult GetStanDiagnostics = () -rules :: Recorder (WithPriority Log) -> Rules ()-rules recorder = do+rules :: Recorder (WithPriority Log) -> PluginId -> Rules ()+rules recorder plId = do   define (cmapWithPrio LogShake recorder) $     \GetStanDiagnostics file -> do-      maybeHie <- getHieFile file-      case maybeHie of-        Nothing -> return ([], Nothing)-        Just hie -> do-          let enabledInspections = HM.fromList [(LSP.fromNormalizedFilePath file, inspectionsIds)]-          -- This should use Cabal config for extensions and Stan config for inspection preferences is the future-          let analysis = runAnalysis Map.empty enabledInspections [] [hie]-          return (analysisToDiagnostics file analysis, Just ())+      config <- getPluginConfigAction plId+      if pluginEnabledConfig plcDiagnosticsOn config then do+          maybeHie <- getHieFile file+          case maybeHie of+            Nothing -> return ([], Nothing)+            Just hie -> do+              let enabledInspections = HM.fromList [(LSP.fromNormalizedFilePath file, inspectionsIds)]+              -- This should use Cabal config for extensions and Stan config for inspection preferences is the future+              let analysis = runAnalysis Map.empty enabledInspections [] [hie]+              return (analysisToDiagnostics file analysis, Just ())+      else return ([], Nothing)    action $ do     files <- getFilesOfInterestUntracked@@ -87,7 +87,7 @@     analysisToDiagnostics :: NormalizedFilePath -> Analysis -> [FileDiagnostic]     analysisToDiagnostics file = mapMaybe (observationToDianostic file) . toList . analysisObservations     observationToDianostic :: NormalizedFilePath -> Observation -> Maybe FileDiagnostic-    observationToDianostic file (Observation {observationSrcSpan, observationInspectionId}) =+    observationToDianostic file Observation {observationSrcSpan, observationInspectionId} =       do         inspection <- HM.lookup observationInspectionId inspectionsMap         let@@ -109,7 +109,7 @@         return ( file,           ShowDiag,           LSP.Diagnostic-            { _range = realSrcSpanToRange $ observationSrcSpan,+            { _range = realSrcSpanToRange observationSrcSpan,               _severity = Just LSP.DsHint,               _code = Just (LSP.InR $ unId (inspectionId inspection)),               _source = Just "stan",
test/Main.hs view
@@ -38,8 +38,8 @@ testDir :: FilePath testDir = "test/testdata" -stanPlugin :: PluginDescriptor IdeState-stanPlugin = Stan.descriptor mempty "stan"+stanPlugin :: PluginTestDescriptor Stan.Log+stanPlugin = mkPluginTestDescriptor Stan.descriptor "stan"  runStanSession :: FilePath -> Session a -> IO a runStanSession subdir =