Skip to content

Commit

Permalink
resolve merging issues
Browse files Browse the repository at this point in the history
  • Loading branch information
VenInf committed Aug 18, 2024
1 parent ae6a060 commit 385d83b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 30 deletions.
15 changes: 7 additions & 8 deletions plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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
Expand All @@ -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


-- ----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-cabal-plugin/test/CabalAdd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions plugins/hls-cabal-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
-- ----------------------------------------------------------------------------
Expand Down

0 comments on commit 385d83b

Please sign in to comment.