packages feed

hls-alternate-number-format-plugin 1.1.0.0 → 1.2.0.0

raw patch · 4 files changed

+31/−30 lines, 4 filesdep ~ghcidedep ~hls-plugin-apidep ~hls-test-utilsPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: ghcide, hls-plugin-api, hls-test-utils, lsp

API changes (from Hackage documentation)

- Ide.Plugin.AlternateNumberFormat: descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
+ Ide.Plugin.AlternateNumberFormat: descriptor :: Recorder (WithPriority Log) -> PluginDescriptor IdeState

Files

hls-alternate-number-format-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hls-alternate-number-format-plugin-version:            1.1.0.0+version:            1.2.0.0 synopsis:           Provide Alternate Number Formats plugin for Haskell Language Server description:   Please see the README on GitHub at <https://github.com/haskell/haskell-language-server#readme>@@ -18,6 +18,7 @@   test/testdata/*.yaml  library+  buildable: True   exposed-modules:  Ide.Plugin.AlternateNumberFormat, Ide.Plugin.Conversion   other-modules:    Ide.Plugin.Literals   hs-source-dirs:   src@@ -26,13 +27,13 @@       aeson     , base                 >=4.12 && < 5     , containers-    , ghcide               ^>=1.6 || ^>=1.7+    , ghcide               ^>= 1.8     , ghc-boot-th     , hls-graph-    , hls-plugin-api       ^>=1.3 || ^>=1.4+    , hls-plugin-api       ^>= 1.5     , hie-compat     , lens-    , lsp+    , lsp                  ^>=1.6     , mtl     , regex-tdfa     , syb@@ -47,6 +48,7 @@     RecordWildCards  test-suite tests+  buildable: True   type:             exitcode-stdio-1.0   default-language: Haskell2010   hs-source-dirs:   test@@ -57,7 +59,7 @@     , base                 >=4.12 && < 5     , filepath     , hls-alternate-number-format-plugin-    , hls-test-utils       ^>=1.3+    , hls-test-utils       ^>=1.3 || ^>= 1.4     , lsp     , QuickCheck     , regex-tdfa
src/Ide/Plugin/AlternateNumberFormat.hs view
@@ -8,15 +8,15 @@ import           Control.Lens                    ((^.)) import           Control.Monad.Except            (ExceptT, MonadIO, liftIO) import qualified Data.HashMap.Strict             as HashMap+import           Data.String                     (IsString) import           Data.Text                       (Text) import qualified Data.Text                       as T import           Development.IDE                 (GetParsedModule (GetParsedModule),                                                   GhcSession (GhcSession),                                                   IdeState, RuleResult, Rules,                                                   define, getFileContents,-                                                  hscEnv, ideLogger,-                                                  realSrcSpanToRange, runAction,-                                                  use, useWithStale)+                                                  hscEnv, realSrcSpanToRange,+                                                  runAction, use, useWithStale) import qualified Development.IDE.Core.Shake      as Shake import           Development.IDE.GHC.Compat      hiding (getSrcSpan) import           Development.IDE.GHC.Compat.Util (toList)@@ -31,11 +31,11 @@                                                   ExtensionNeeded (NeedsExtension, NoExtension),                                                   alternateFormat) import           Ide.Plugin.Literals-import           Ide.PluginUtils                 (handleMaybe, handleMaybeM,-                                                  response)+import           Ide.PluginUtils                 (getNormalizedFilePath,+                                                  handleMaybeM, pluginResponse) import           Ide.Types import           Language.LSP.Types-import           Language.LSP.Types.Lens         (uri)+import qualified Language.LSP.Types.Lens         as L  newtype Log = LogShake Shake.Log deriving Show @@ -43,8 +43,11 @@   pretty = \case     LogShake log -> pretty log -descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState-descriptor recorder plId = (defaultPluginDescriptor plId)+alternateNumberFormatId :: IsString a => a+alternateNumberFormatId = "alternateNumberFormat"++descriptor :: Recorder (WithPriority Log) -> PluginDescriptor IdeState+descriptor recorder = (defaultPluginDescriptor alternateNumberFormatId)     { pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionHandler     , pluginRules = collectLiteralsRule recorder     }@@ -84,8 +87,8 @@         getExtensions = map GhcExtension . toList . extensionFlags . ms_hspp_opts . pm_mod_summary  codeActionHandler :: PluginMethodHandler IdeState 'TextDocumentCodeAction-codeActionHandler state _ (CodeActionParams _ _ docId currRange _) = response $ do-    nfp <- getNormalizedFilePath docId+codeActionHandler state _ (CodeActionParams _ _ docId currRange _) = pluginResponse $ do+    nfp <- getNormalizedFilePath (docId ^. L.uri)     CLR{..} <- requestLiterals state nfp     pragma <- getFirstPragma state nfp         -- remove any invalid literals (see validTarget comment)@@ -94,7 +97,6 @@         literalPairs = map (\lit -> (lit, alternateFormat lit)) litsInRange         -- make a code action for every literal and its' alternates (then flatten the result)         actions = concatMap (\(lit, alts) -> map (mkCodeAction nfp lit enabledExtensions pragma) alts) literalPairs-     pure $ List actions     where         inCurrentRange :: Literal -> Bool@@ -145,20 +147,14 @@  getFirstPragma :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m NextPragmaInfo getFirstPragma state nfp = handleMaybeM "Error: Could not get NextPragmaInfo" $ do-      ghcSession <- liftIO $ runAction "AlternateNumberFormat.GhcSession" state $ useWithStale GhcSession nfp-      (_, fileContents) <- liftIO $ runAction "AlternateNumberFormat.GetFileContents" state $ getFileContents nfp+      ghcSession <- liftIO $ runAction (alternateNumberFormatId <> ".GhcSession") state $ useWithStale GhcSession nfp+      (_, fileContents) <- liftIO $ runAction (alternateNumberFormatId <> ".GetFileContents") state $ getFileContents nfp       case ghcSession of         Just (hscEnv -> hsc_dflags -> sessionDynFlags, _) -> pure $ Just $ getNextPragmaInfo sessionDynFlags fileContents-        Nothing -> pure Nothing---getNormalizedFilePath :: Monad m => TextDocumentIdentifier -> ExceptT String m NormalizedFilePath-getNormalizedFilePath docId = handleMaybe "Error: converting to NormalizedFilePath"-        $ uriToNormalizedFilePath-        $ toNormalizedUri (docId ^. uri)+        Nothing                                           -> pure Nothing  requestLiterals :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m CollectLiteralsResult requestLiterals state = handleMaybeM "Error: Could not Collect Literals"                 . liftIO-                . runAction "AlternateNumberFormat.CollectLiterals" state+                . runAction (alternateNumberFormatId <> ".CollectLiterals") state                 . use CollectLiterals
src/Ide/Plugin/Literals.hs view
@@ -16,9 +16,9 @@ import qualified Data.Text                     as T import           Development.IDE.GHC.Compat    hiding (getSrcSpan) import           Development.IDE.Graph.Classes (NFData (rnf))-import qualified GHC.Generics                  as GHC import           Generics.SYB                  (Data, Typeable, everything,                                                 extQ)+import qualified GHC.Generics                  as GHC  -- data type to capture what type of literal we are dealing with -- provides location and possibly source text (for OverLits) as well as it's value@@ -78,9 +78,13 @@         HsInt _ val   -> fromIntegralLit patSpan val         HsRat _ val _ -> fromFractionalLit patSpan val         _             -> Nothing-    -- a located HsOverLit is (GenLocated SrcSpan HsOverLit) NOT (GenLocated SrcSpanAnn' a HsOverLit)+#if __GLASGOW_HASKELL__ == 902     NPat _ (L (RealSrcSpan sSpan _) overLit) _ _ -> fromOverLit overLit sSpan     NPlusKPat _ _ (L (RealSrcSpan sSpan _) overLit1) _ _ _ -> fromOverLit overLit1 sSpan+#else+    NPat _ (L (locA -> (RealSrcSpan sSpan _)) overLit) _ _ -> fromOverLit overLit sSpan+    NPlusKPat _ _ (L (locA -> (RealSrcSpan sSpan _)) overLit1) _ _ _ -> fromOverLit overLit1 sSpan+#endif     _ -> Nothing getPattern _ = Nothing 
test/Main.hs view
@@ -7,7 +7,6 @@ import           Data.List                        (find) import           Data.Text                        (Text) import qualified Data.Text                        as T-import           Debug.Trace import qualified Ide.Plugin.AlternateNumberFormat as AlternateNumberFormat import qualified Ide.Plugin.Conversion            as Conversion import           Language.LSP.Types               (toEither)@@ -21,7 +20,7 @@ main = defaultTestRunner test  alternateNumberFormatPlugin :: PluginDescriptor IdeState-alternateNumberFormatPlugin = AlternateNumberFormat.descriptor mempty "alternateNumberFormat"+alternateNumberFormatPlugin = AlternateNumberFormat.descriptor mempty  -- NOTE: For whatever reason, this plugin does not play nice with creating Code Actions on time. -- As a result tests will mostly pass if `import Prelude` is added at the top. We (mostly fendor) surmise this has something