diff --git a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs index b668e3eb39..03e8fbfdff 100644 --- a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs +++ b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs @@ -100,7 +100,7 @@ haskellInteractionDescriptor recorder plId = (defaultPluginDescriptor plId "Provides the cabal-add code action in haskell files") { pluginHandlers = mconcat - [ mkPluginHandler LSP.SMethod_TextDocumentCodeAction $ cabalAddCodeAction recorder + [ mkPluginHandler LSP.SMethod_TextDocumentCodeAction cabalAddCodeAction ] , pluginCommands = [PluginCommand CabalAdd.cabalAddCommand "add a dependency to a cabal file" (CabalAdd.command cabalAddRecorder)] , pluginRules = pure () @@ -332,8 +332,8 @@ gotoDefinition ideState _ msgParam = do isSectionArgName name (Syntax.Section _ sectionArgName _) = name == CabalFields.onelineSectionArgs sectionArgName isSectionArgName _ _ = False -cabalAddCodeAction :: Recorder (WithPriority Log) -> PluginMethodHandler IdeState 'LSP.Method_TextDocumentCodeAction -cabalAddCodeAction recorder state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) _ CodeActionContext{_diagnostics=diags}) = do +cabalAddCodeAction :: PluginMethodHandler IdeState 'LSP.Method_TextDocumentCodeAction +cabalAddCodeAction state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) _ CodeActionContext{_diagnostics=diags}) = do maxCompls <- fmap maxCompletions . liftIO $ runAction "cabal.cabal-add" state getClientConfigAction let suggestions = take maxCompls $ concatMap CabalAdd.hiddenPackageSuggestion diags case suggestions of @@ -351,12 +351,11 @@ cabalAddCodeAction recorder state plId (CodeActionParams _ _ (TextDocumentIdenti case mbGPD of Nothing -> pure $ InL [] Just (gpd, _) -> do - actions <- liftIO $ CabalAdd.addDependencySuggestCodeAction cabalAddRecorder plId - verTxtDocId suggestions - haskellFilePath cabalFilePath gpd + actions <- liftIO $ CabalAdd.addDependencySuggestCodeAction plId verTxtDocId + suggestions + haskellFilePath cabalFilePath + gpd pure $ InL $ fmap InR actions - where - cabalAddRecorder = cmapWithPrio LogCabalAdd recorder -- ---------------------------------------------------------------- diff --git a/plugins/hls-cabal-plugin/test/CabalAdd.hs b/plugins/hls-cabal-plugin/test/CabalAdd.hs index 92e732cbf6..f6bc7dbde0 100644 --- a/plugins/hls-cabal-plugin/test/CabalAdd.hs +++ b/plugins/hls-cabal-plugin/test/CabalAdd.hs @@ -124,7 +124,7 @@ cabalAddTests = testHiddenPackageSuggestions :: String -> [T.Text] -> [(T.Text, T.Text)] -> TestTree testHiddenPackageSuggestions testTitle messages suggestions = let diags = map (\msg -> messageToDiagnostic msg ) messages - suggestions' = map (safeHead . hiddenPackageSuggestion 1) diags + suggestions' = map (safeHead . hiddenPackageSuggestion) diags assertions = zipWith (@?=) suggestions' (map Just suggestions) testNames = map (\(f, s) -> "Check if " ++ T.unpack f ++ (if s == "" then "" else "-") ++ T.unpack s ++ " was parsed correctly") suggestions test = testGroup testTitle $ zipWith testCase testNames assertions diff --git a/plugins/hls-cabal-plugin/test/Main.hs b/plugins/hls-cabal-plugin/test/Main.hs index 9e59b89813..00e39583f4 100644 --- a/plugins/hls-cabal-plugin/test/Main.hs +++ b/plugins/hls-cabal-plugin/test/Main.hs @@ -231,27 +231,6 @@ codeActionTests = testGroup "Code Actions" guard (_title == "Replace with " <> license) pure action - - generateHiddenPackageTestSession :: FilePath -> FilePath -> T.Text -> [Int] -> Session () - generateHiddenPackageTestSession cabalFile haskellFile dependency indicesRes = do - hsdoc <- openDoc haskellFile "haskell" - cabDoc <- openDoc cabalFile "cabal" - _ <- waitForDiagnosticsFrom hsdoc - cas <- Maybe.mapMaybe (^? _R) <$> getAllCodeActions hsdoc - let selectedCas = filter (\ca -> "Add dependency" `T.isPrefixOf` (ca ^. L.title)) cas - mapM_ executeCodeAction selectedCas - _ <- skipManyTill anyMessage $ getDocumentEdit cabDoc -- Wait for the changes in cabal file - contents <- documentContents cabDoc - liftIO $ assertEqual (T.unpack dependency <> " isn't found in the cabal file") indicesRes (Text.indices dependency contents) - - testHiddenPackageSuggestions :: String -> [T.Text] -> [(T.Text, T.Text)] -> TestTree - testHiddenPackageSuggestions testTitle messages suggestions = - let suggestions' = map (safeHead . hiddenPackageSuggestion 1) messages - assertions = zipWith (@?=) suggestions' (map Just suggestions) - testNames = map (\(f, s) -> "Check if " ++ T.unpack f ++ "-" ++ T.unpack s ++ " was parsed correctly") suggestions - test = testGroup testTitle $ zipWith testCase testNames assertions - in test - -- ---------------------------------------------------------------------------- -- Goto Definition Tests -- ----------------------------------------------------------------------------