packages feed

hls-explicit-fixity-plugin 2.0.0.1 → 2.1.0.0

raw patch · 3 files changed

+20/−21 lines, 3 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)

Files

hls-explicit-fixity-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hls-explicit-fixity-plugin-version:            2.0.0.1+version:            2.1.0.0 synopsis:           Show fixity explicitly while hovering description:   Please see the README on GitHub at <https://github.com/haskell/haskell-language-server/tree/master/plugins/hls-explicit-fixity-plugin#readme>@@ -30,10 +30,10 @@     , deepseq     , extra     , ghc-    , ghcide                == 2.0.0.1+    , ghcide                == 2.1.0.0     , hashable-    , hls-plugin-api        == 2.0.0.1-    , lsp                   >=1.2.0.1+    , hls-plugin-api        == 2.1.0.0+    , lsp                   >=2.1.0.0     , text     , transformers @@ -55,5 +55,5 @@     , base     , filepath     , hls-explicit-fixity-plugin-    , hls-test-utils              == 2.0.0.1+    , hls-test-utils              == 2.1.0.0     , text
src/Ide/Plugin/ExplicitFixity.hs view
@@ -11,7 +11,6 @@  import           Control.DeepSeq import           Control.Monad.IO.Class               (MonadIO, liftIO)-import           Control.Monad.Trans.Maybe import           Data.Either.Extra import           Data.Hashable import qualified Data.Map.Strict                      as M@@ -20,6 +19,7 @@ import qualified Data.Text                            as T import           Development.IDE                      hiding (pluginHandlers,                                                        pluginRules)+import           Development.IDE.Core.PluginUtils import           Development.IDE.Core.PositionMapping (idDelta) import           Development.IDE.Core.Shake           (addPersistentRule) import qualified Development.IDE.Core.Shake           as Shake@@ -28,30 +28,29 @@ import           Development.IDE.LSP.Notifications    (ghcideNotificationsPluginPriority) import           Development.IDE.Spans.AtPoint import           GHC.Generics                         (Generic)-import           Ide.PluginUtils                      (getNormalizedFilePath,-                                                       handleMaybeM,-                                                       pluginResponse)+import           Ide.Plugin.Error import           Ide.Types                            hiding (pluginId)-import           Language.LSP.Types+import           Language.LSP.Protocol.Message+import           Language.LSP.Protocol.Types  descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState descriptor recorder pluginId = (defaultPluginDescriptor pluginId)     { pluginRules = fixityRule recorder-    , pluginHandlers = mkPluginHandler STextDocumentHover hover+    , pluginHandlers = mkPluginHandler SMethod_TextDocumentHover hover     -- Make this plugin has a lower priority than ghcide's plugin to ensure     -- type info display first.     , pluginPriority = ghcideNotificationsPluginPriority - 1     } -hover :: PluginMethodHandler IdeState TextDocumentHover-hover state _ (HoverParams (TextDocumentIdentifier uri) pos _) = pluginResponse $ do-    nfp <- getNormalizedFilePath uri-    handleMaybeM "ExplicitFixity: Unable to get fixity" $ liftIO $ runIdeAction "ExplicitFixity" (shakeExtras state) $ runMaybeT $ do-      (FixityMap fixmap, _) <- useE GetFixity nfp-      (HAR{hieAst}, mapping) <- useE GetHieAst nfp+hover :: PluginMethodHandler IdeState Method_TextDocumentHover+hover state _ (HoverParams (TextDocumentIdentifier uri) pos _) = do+    nfp <- getNormalizedFilePathE uri+    runIdeActionE "ExplicitFixity" (shakeExtras state) $ do+      (FixityMap fixmap, _) <-  useWithStaleFastE GetFixity nfp+      (HAR{hieAst}, mapping) <- useWithStaleFastE GetHieAst nfp       let ns = getNamesAtPoint hieAst pos mapping           fs = mapMaybe (\n -> (n,) <$> M.lookup n fixmap) ns-      pure $ toHover $ fs+      pure $ maybeToNull $ toHover fs     where         toHover :: [(Name, Fixity)] -> Maybe Hover         toHover [] = Nothing@@ -60,7 +59,7 @@                 contents = T.intercalate "\n\n" $ fixityText <$> fixities                 -- Append to the previous hover content                 contents' = "\n" <> sectionSeparator <> contents-            in  Just $ Hover (HoverContents $ unmarkedUpContent contents') Nothing+            in  Just $ Hover (InL (mkPlainText contents')) Nothing          fixityText :: (Name, Fixity) -> T.Text         fixityText (name, Fixity _ precedence direction) =
test/Main.hs view
@@ -59,11 +59,11 @@     case h of         Nothing -> liftIO $ assertFailure "No hover"         Just (Hover contents _) -> case contents of-          HoverContentsMS _ -> liftIO $ assertFailure "Unexpected content type"-          HoverContents (MarkupContent mk txt) -> do+          InL (MarkupContent mk txt) -> do               liftIO                 $ assertBool ("Failed to find `" <> T.unpack expected <> "` in hover message: " <> T.unpack txt)                 $ expected `T.isInfixOf` txt+          _ -> liftIO $ assertFailure "Unexpected content type"     closeDoc doc  testDataDir :: FilePath