packages feed

hls-change-type-signature-plugin 1.0.1.1 → 1.1.0.0

raw patch · 3 files changed

+31/−28 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

API changes (from Hackage documentation)

- Ide.Plugin.ChangeTypeSignature: descriptor :: PluginDescriptor IdeState
+ Ide.Plugin.ChangeTypeSignature: descriptor :: PluginId -> PluginDescriptor IdeState

Files

hls-change-type-signature-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               hls-change-type-signature-plugin-version:            1.0.1.1+version:            1.1.0.0 synopsis:           Change a declarations type signature with a Code Action description:   Please see the README on GitHub at <https://github.com/haskell/plugins/hls-change-type-signature-plugin/README.md>@@ -18,14 +18,18 @@   test/testdata/*.txt   test/testdata/*.yaml +source-repository head+    type:     git+    location: https://github.com/haskell/haskell-language-server.git+ library   buildable: True   exposed-modules:  Ide.Plugin.ChangeTypeSignature   hs-source-dirs:   src   build-depends:     , base             >=4.12 && < 5-    , ghcide          ^>=1.8-    , hls-plugin-api  ^>=1.5+    , ghcide          ^>=1.9+    , hls-plugin-api  ^>=1.6     , lsp-types     , regex-tdfa     , syb@@ -57,7 +61,7 @@     , base                 >=4.12 && < 5     , filepath     , hls-change-type-signature-plugin-    , hls-test-utils       ^>=1.4+    , hls-test-utils       ^>=1.5     , lsp     , QuickCheck     , regex-tdfa
src/Ide/Plugin/ChangeTypeSignature.hs view
@@ -12,7 +12,6 @@ import           Data.Foldable                  (asum) import qualified Data.HashMap.Strict            as Map import           Data.Maybe                     (mapMaybe)-import           Data.String                    (IsString) import           Data.Text                      (Text) import qualified Data.Text                      as T import           Development.IDE                (realSrcSpanToRange)@@ -25,30 +24,28 @@ import           Ide.PluginUtils                (getNormalizedFilePath,                                                  handleMaybeM, pluginResponse) import           Ide.Types                      (PluginDescriptor (..),+                                                 PluginId (PluginId),                                                  PluginMethodHandler,                                                  defaultPluginDescriptor,                                                  mkPluginHandler) import           Language.LSP.Types import           Text.Regex.TDFA                ((=~)) -changeTypeSignatureId :: IsString a => a-changeTypeSignatureId = "changeTypeSignature"--descriptor :: PluginDescriptor IdeState-descriptor = (defaultPluginDescriptor changeTypeSignatureId) { pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionHandler }+descriptor :: PluginId -> PluginDescriptor IdeState+descriptor plId = (defaultPluginDescriptor plId) { pluginHandlers = mkPluginHandler STextDocumentCodeAction (codeActionHandler plId) } -codeActionHandler :: PluginMethodHandler IdeState 'TextDocumentCodeAction-codeActionHandler ideState _ CodeActionParams {_textDocument = TextDocumentIdentifier uri, _context = CodeActionContext (List diags) _} = pluginResponse $ do+codeActionHandler :: PluginId -> PluginMethodHandler IdeState 'TextDocumentCodeAction+codeActionHandler plId ideState _ CodeActionParams {_textDocument = TextDocumentIdentifier uri, _context = CodeActionContext (List diags) _} = pluginResponse $ do       nfp <- getNormalizedFilePath uri-      decls <- getDecls ideState nfp-      let actions = mapMaybe (generateAction uri decls) diags+      decls <- getDecls plId ideState nfp+      let actions = mapMaybe (generateAction plId uri decls) diags       pure $ List actions -getDecls :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m [LHsDecl GhcPs]-getDecls state = handleMaybeM "Error: Could not get Parsed Module"+getDecls :: MonadIO m => PluginId -> IdeState -> NormalizedFilePath -> ExceptT String m [LHsDecl GhcPs]+getDecls (PluginId changeTypeSignatureId) state = handleMaybeM "Could not get Parsed Module"     . liftIO     . fmap (fmap (hsmodDecls . unLoc . pm_parsed_source))-    . runAction (changeTypeSignatureId <> ".GetParsedModule") state+    . runAction (T.unpack changeTypeSignatureId <> ".GetParsedModule") state     . use GetParsedModule  -- | Text representing a Declaration's Name@@ -76,8 +73,8 @@ type SigName = (HasOccName (IdP GhcPs))  -- | Create a CodeAction from a Diagnostic-generateAction :: SigName => Uri -> [LHsDecl GhcPs] -> Diagnostic -> Maybe (Command |? CodeAction)-generateAction uri decls diag = changeSigToCodeAction uri <$> diagnosticToChangeSig decls diag+generateAction :: SigName => PluginId -> Uri -> [LHsDecl GhcPs] -> Diagnostic -> Maybe (Command |? CodeAction)+generateAction plId uri decls diag = changeSigToCodeAction plId uri <$> diagnosticToChangeSig decls diag  -- | Convert a diagnostic into a ChangeSignature and add the proper SrcSpan diagnosticToChangeSig :: SigName => [LHsDecl GhcPs] -> Diagnostic -> Maybe ChangeSignature@@ -148,8 +145,8 @@                                                 then T.strip $ snd $ T.breakOnEnd " => " sig                                                 else T.strip $ snd $ T.breakOnEnd " :: " sig -changeSigToCodeAction :: Uri -> ChangeSignature -> Command |? CodeAction-changeSigToCodeAction uri ChangeSignature{..} = InR CodeAction { _title       = mkChangeSigTitle declName actualType+changeSigToCodeAction :: PluginId -> Uri -> ChangeSignature -> Command |? CodeAction+changeSigToCodeAction (PluginId changeTypeSignatureId) uri ChangeSignature{..} = InR CodeAction { _title       = mkChangeSigTitle declName actualType                                                                , _kind        = Just (CodeActionUnknown ("quickfix." <> changeTypeSignatureId))                                                                , _diagnostics = Just $ List [diagnostic]                                                                , _isPreferred = Nothing
test/Main.hs view
@@ -9,8 +9,8 @@ import qualified Ide.Plugin.ChangeTypeSignature as ChangeTypeSignature import           System.FilePath                ((<.>), (</>)) import           Test.Hls                       (CodeAction (..), Command,-                                                 GhcVersion (..), IdeState,-                                                 PluginDescriptor,+                                                 GhcVersion (..),+                                                 PluginTestDescriptor,                                                  Position (Position),                                                  Range (Range), Session,                                                  TestName, TestTree,@@ -21,9 +21,11 @@                                                  getCodeActions,                                                  goldenWithHaskellDoc,                                                  knownBrokenForGhcVersions,-                                                 liftIO, openDoc,-                                                 runSessionWithServer, testCase,-                                                 testGroup, toEither, type (|?),+                                                 liftIO,+                                                 mkPluginTestDescriptor',+                                                 openDoc, runSessionWithServer,+                                                 testCase, testGroup, toEither,+                                                 type (|?),                                                  waitForAllProgressDone,                                                  waitForDiagnostics, (@?=)) import           Text.Regex.TDFA                ((=~))@@ -31,8 +33,8 @@ main :: IO () main = defaultTestRunner test -changeTypeSignaturePlugin :: PluginDescriptor IdeState-changeTypeSignaturePlugin = ChangeTypeSignature.descriptor+changeTypeSignaturePlugin :: PluginTestDescriptor ()+changeTypeSignaturePlugin = mkPluginTestDescriptor' ChangeTypeSignature.descriptor "changeTypeSignature"  test :: TestTree test = testGroup "changeTypeSignature" [