Skip to content

Commit 7440aa3

Browse files
committed
docs, revert changes
1 parent c054121 commit 7440aa3

File tree

1 file changed

+30
-13
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal

1 file changed

+30
-13
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,25 @@ data CabalAddCommandParams =
114114

115115
instance Logger.Pretty CabalAddCommandParams where
116116
pretty CabalAddCommandParams{..} =
117-
"CabalAdd parameters:" <+> vcat
118-
[ "cabal path:" <+> pretty cabalPath
119-
, "target:" <+> pretty buildTarget
120-
, "dependendency:" <+> pretty dependency
121-
, "version:" <+> pretty version
117+
"CabalAdd parameters:" Logger.<+> Logger.vcat
118+
[ "cabal path:" Logger.<+> Logger.pretty cabalPath
119+
, "target:" Logger.<+> Logger.pretty buildTarget
120+
, "dependendency:" Logger.<+> Logger.pretty dependency
121+
, "version:" Logger.<+> Logger.pretty version
122122
]
123123

124-
-- | Gives a code action that calls the command,
125-
-- if a suggestion for a missing dependency is found.
126-
-- Disabled action if no cabal files given.
127-
-- Conducts IO action on a cabal file to find build targets.
124+
-- | Creates a code action that calls the `cabalAddCommand`,
125+
-- using dependency-version suggestion pairs as input.
126+
--
127+
-- Returns disabled action if no cabal files given.
128+
--
129+
-- Takes haskell file and cabal file paths to create a relative path
130+
-- to the haskell file, which is used to get a `BuildTarget`.
131+
-- In current implementation the dependency is being added to the main found
132+
-- build target, but if there will be a way to get all build targets from a file
133+
-- it will be possible to support addition to a build target of choice.
134+
--
135+
-- The cabal file path is also used to make the text `edit` down the line.
128136
addDependencySuggestCodeAction
129137
:: Logger.Recorder (Logger.WithPriority Log)
130138
-> PluginId
@@ -142,8 +150,17 @@ addDependencySuggestCodeAction recorder plId verTxtDocId suggestions haskellFile
142150
targets -> pure $ concat [mkCodeAction cabalFilePath (Just $ buildTargetToStringRepr target) <$>
143151
suggestions | target <- targets]
144152
where
153+
-- | Note the use of `pretty` funciton.
154+
-- It converts the `BuildTarget` to an acceptable string representation.
155+
-- It will be used in as the input for `cabal-add`'s `executeConfig`.
145156
buildTargetToStringRepr target = render $ pretty $ buildTargetComponentName target
146157

158+
-- | Gives the build targets that are used in the `CabalAdd`.
159+
-- Note the unorthodox usage of `readBuildTargets`:
160+
-- If the relative path to the haskell file is provided,
161+
-- the `readBuildTargets` will return a main build target.
162+
-- This behaviour is acceptable for now, but changing to a way of getting
163+
-- all build targets in a file is advised.
147164
getBuildTargets :: GenericPackageDescription -> FilePath -> FilePath -> IO [BuildTarget]
148165
getBuildTargets gpd cabalFilePath haskellFilePath = do
149166
let haskellFileRelativePath = makeRelative (dropFileName cabalFilePath) haskellFilePath
@@ -205,10 +222,10 @@ getDependencyEdit :: MonadIO m => Logger.Recorder (Logger.WithPriority Log) -> (
205222
FilePath -> Maybe String -> NonEmpty String -> ExceptT PluginError m WorkspaceEdit
206223
getDependencyEdit recorder env cabalFilePath buildTarget dependency = do
207224
let (state, caps, verTxtDocId) = env
208-
runActionE "cabal.cabal-add" state $ do
209-
contents <- useWithStaleE GetFileContents $ toNormalizedFilePath cabalFilePath
210-
inFields <- useWithStaleE ParseCabalFields $ toNormalizedFilePath cabalFilePath
211-
inPackDescr <- useWithStaleE ParseCabalFile $ toNormalizedFilePath cabalFilePath
225+
(mbCnfOrigContents, mbFields, mbPackDescr) <- liftIO $ runAction "cabal.cabal-add" state $ do
226+
contents <- Development.IDE.useWithStale GetFileContents $ toNormalizedFilePath cabalFilePath
227+
inFields <- Development.IDE.useWithStale ParseCabalFields $ toNormalizedFilePath cabalFilePath
228+
inPackDescr <- Development.IDE.useWithStale ParseCabalFile $ toNormalizedFilePath cabalFilePath
212229
let mbCnfOrigContents = case snd . fst <$> contents of
213230
Just (Just txt) -> Just $ encodeUtf8 txt
214231
_ -> Nothing

0 commit comments

Comments
 (0)