hls-change-type-signature-plugin 1.0.1.0 → 1.0.1.1
raw patch · 13 files changed
+118/−19 lines, 13 filesdep ~ghcidedep ~hls-plugin-apidep ~hls-test-utilsPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ghcide, hls-plugin-api, hls-test-utils
API changes (from Hackage documentation)
- Ide.Plugin.ChangeTypeSignature: descriptor :: PluginId -> PluginDescriptor IdeState
+ Ide.Plugin.ChangeTypeSignature: descriptor :: PluginDescriptor IdeState
Files
- hls-change-type-signature-plugin.cabal +9/−6
- src/Ide/Plugin/ChangeTypeSignature.hs +12/−8
- test/Main.hs +6/−5
- test/testdata/TRigidType2.expected.hs +4/−0
- test/testdata/TRigidType2.hs +4/−0
- test/testdata/error1.txt +6/−0
- test/testdata/error2.txt +6/−0
- test/testdata/error3.txt +10/−0
- test/testdata/error4.txt +19/−0
- test/testdata/error5.txt +15/−0
- test/testdata/ghc921-error1.txt +9/−0
- test/testdata/ghc921-error2.txt +9/−0
- test/testdata/ghc921-error3.txt +9/−0
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.0+version: 1.0.1.1 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>@@ -15,16 +15,18 @@ LICENSE README.md test/testdata/*.hs+ test/testdata/*.txt test/testdata/*.yaml library+ buildable: True exposed-modules: Ide.Plugin.ChangeTypeSignature hs-source-dirs: src build-depends:- , base >=4.12 && < 5- , ghcide ^>=1.6 || ^>=1.7- , hls-plugin-api ^>=1.3 || ^>=1.4- , lsp-types + , base >=4.12 && < 5+ , ghcide ^>=1.8+ , hls-plugin-api ^>=1.5+ , lsp-types , regex-tdfa , syb , text@@ -45,6 +47,7 @@ test-suite tests+ buildable: True type: exitcode-stdio-1.0 default-language: Haskell2010 hs-source-dirs: test@@ -54,7 +57,7 @@ , base >=4.12 && < 5 , filepath , hls-change-type-signature-plugin- , hls-test-utils ^>=1.3+ , hls-test-utils ^>=1.4 , lsp , QuickCheck , regex-tdfa
src/Ide/Plugin/ChangeTypeSignature.hs view
@@ -12,6 +12,7 @@ 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)@@ -22,20 +23,23 @@ import Development.IDE.GHC.Util (printOutputable) import Generics.SYB (extQ, something) import Ide.PluginUtils (getNormalizedFilePath,- handleMaybeM, response)+ handleMaybeM, pluginResponse) import Ide.Types (PluginDescriptor (..),- PluginId, PluginMethodHandler,+ PluginMethodHandler, defaultPluginDescriptor, mkPluginHandler) import Language.LSP.Types import Text.Regex.TDFA ((=~)) -descriptor :: PluginId -> PluginDescriptor IdeState-descriptor plId = (defaultPluginDescriptor plId) { pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionHandler }+changeTypeSignatureId :: IsString a => a+changeTypeSignatureId = "changeTypeSignature" +descriptor :: PluginDescriptor IdeState+descriptor = (defaultPluginDescriptor changeTypeSignatureId) { pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionHandler }+ codeActionHandler :: PluginMethodHandler IdeState 'TextDocumentCodeAction-codeActionHandler ideState plId CodeActionParams {_textDocument = TextDocumentIdentifier uri, _context = CodeActionContext (List diags) _} = response $ do- nfp <- getNormalizedFilePath plId (TextDocumentIdentifier uri)+codeActionHandler 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 pure $ List actions@@ -44,7 +48,7 @@ getDecls state = handleMaybeM "Error: Could not get Parsed Module" . liftIO . fmap (fmap (hsmodDecls . unLoc . pm_parsed_source))- . runAction "changeSignature.GetParsedModule" state+ . runAction (changeTypeSignatureId <> ".GetParsedModule") state . use GetParsedModule -- | Text representing a Declaration's Name@@ -146,7 +150,7 @@ changeSigToCodeAction :: Uri -> ChangeSignature -> Command |? CodeAction changeSigToCodeAction uri ChangeSignature{..} = InR CodeAction { _title = mkChangeSigTitle declName actualType- , _kind = Just (CodeActionUnknown "quickfix.changeSignature")+ , _kind = Just (CodeActionUnknown ("quickfix." <> changeTypeSignatureId)) , _diagnostics = Just $ List [diagnostic] , _isPreferred = Nothing , _disabled = Nothing
test/Main.hs view
@@ -9,7 +9,7 @@ import qualified Ide.Plugin.ChangeTypeSignature as ChangeTypeSignature import System.FilePath ((<.>), (</>)) import Test.Hls (CodeAction (..), Command,- GhcVersion (GHC92), IdeState,+ GhcVersion (..), IdeState, PluginDescriptor, Position (Position), Range (Range), Session,@@ -32,13 +32,14 @@ main = defaultTestRunner test changeTypeSignaturePlugin :: PluginDescriptor IdeState-changeTypeSignaturePlugin = ChangeTypeSignature.descriptor "changeTypeSignature"+changeTypeSignaturePlugin = ChangeTypeSignature.descriptor test :: TestTree test = testGroup "changeTypeSignature" [ testRegexes , codeActionTest "TExpectedActual" 4 11- , knownBrokenForGhcVersions [GHC92] "Error Message in 9.2 does not provide enough info" $ codeActionTest "TRigidType" 4 14+ , knownBrokenForGhcVersions [GHC92, GHC94] "Error Message in 9.2/9.4 does not provide enough info" $ codeActionTest "TRigidType" 4 14+ , codeActionTest "TRigidType2" 4 6 , codeActionTest "TLocalBinding" 7 22 , codeActionTest "TLocalBindingShadow1" 11 8 , codeActionTest "TLocalBindingShadow2" 7 22@@ -112,8 +113,8 @@ isChangeTypeAction CodeAction{_kind} = case _kind of Nothing -> False Just kind -> case kind of- "quickfix.changeSignature" -> True- _ -> False+ "quickfix.changeTypeSignature" -> True+ _ -> False regexTest :: FilePath -> Text -> Bool -> TestTree
+ test/testdata/TRigidType2.expected.hs view
@@ -0,0 +1,4 @@+module TRigidType2 where++test :: [Int] -> Int+test = head
+ test/testdata/TRigidType2.hs view
@@ -0,0 +1,4 @@+module TRigidType2 where++test :: a -> Int+test = head
+ test/testdata/error1.txt view
@@ -0,0 +1,6 @@+ • Couldn't match type ‘Int’+ with ‘Data.HashSet.Internal.HashSet Int’+ Expected type: Int -> Int+ Actual type: Data.HashSet.Internal.HashSet Int -> Int+ • In the expression: head . toList+ In an equation for ‘test’: test = head . toList
+ test/testdata/error2.txt view
@@ -0,0 +1,6 @@+ • Couldn't match type ‘b0 -> t0 a0 -> b0’ with ‘Int’+ Expected type: Int -> Int+ Actual type: (b0 -> a0 -> b0) -> b0 -> t0 a0 -> b0+ • Probable cause: ‘foldl’ is applied to too few arguments+ In the expression: foldl+ In an equation for ‘test’: test = foldl
+ test/testdata/error3.txt view
@@ -0,0 +1,10 @@+ • Couldn't match expected type ‘Int’ with actual type ‘[Int]’+ • In the expression: map (+ x) [1, 2, 3]+ In an equation for ‘test’:+ test x+ = map (+ x) [1, 2, 3]+ where+ go = head . reverse+ |+152 | test x = map (+ x) [1,2,3]+ | ^^^^^^^^^^^^^^^^^
+ test/testdata/error4.txt view
@@ -0,0 +1,19 @@+ • Couldn't match type ‘a’ with ‘[[Int]]’+ ‘a’ is a rigid type variable bound by+ the type signature for:+ test :: forall a. Ord a => a -> Int+ at src/Ide/Plugin/ChangeTypeSignature.hs:154:1-25+ Expected type: a -> Int+ Actual type: [[Int]] -> Int+ • In the expression: go . head . reverse+ In an equation for ‘test’:+ test+ = go . head . reverse+ where+ go = head . reverse+ • Relevant bindings include+ test :: a -> Int+ (bound at src/Ide/Plugin/ChangeTypeSignature.hs:155:1)+ |+155 | test = go . head . reverse+ | ^^^^^^^^^^^^^^^^^^^
+ test/testdata/error5.txt view
@@ -0,0 +1,15 @@+ • Couldn't match type ‘(a0 -> m0 b0) -> m0 (t0 b0)’ with ‘Int’+ Expected type: Int -> Int+ Actual type: t0 a0 -> (a0 -> m0 b0) -> m0 (t0 b0)+ • Probable cause: ‘forM’ is applied to too few arguments+ In the expression: forM+ In an equation for ‘test’: test = forM+ In an equation for ‘implicit’:+ implicit+ = return OpTEmpty+ where+ test :: Int -> Int+ test = forM+ |+82 | test = forM+ | ^^^^
+ test/testdata/ghc921-error1.txt view
@@ -0,0 +1,9 @@+ • Couldn't match type ‘Data.Set.Internal.Set Int’ with ‘Int’+ Expected: Int -> [Int]+ Actual: Data.Set.Internal.Set Int -> [Int]+ • In the second argument of ‘(.)’, namely ‘toList’+ In the expression: head . toList+ In an equation for ‘test’: test = head . toList+ |+83 | test = head . toList+ | ^^^^^^
+ test/testdata/ghc921-error2.txt view
@@ -0,0 +1,9 @@+ • Couldn't match type ‘b0 -> a0 -> b0’ with ‘Int’+ Expected: Int -> Int+ Actual: (b0 -> a0 -> b0) -> b0 -> t0 a0 -> b0+ • Probable cause: ‘foldl’ is applied to too few arguments+ In the expression: foldl+ In an equation for ‘test’: test = foldl+ |+83 | test = foldl+ |
+ test/testdata/ghc921-error3.txt view
@@ -0,0 +1,9 @@+ • Couldn't match type ‘[Int]’ with ‘Int’+ Expected: Int -> [Int]+ Actual: [Int] -> [Int]+ • In the second argument of ‘(.)’, namely ‘reverse’+ In the expression: head . reverse+ In an equation for ‘test’: test = head . reverse+ |+84 | test = head . reverse+ |