haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Fix for multiple build targets at cabal-add

Open VenInf opened this issue 1 year ago • 1 comments

Fix for multiple build targets at cabal-add

In my current merged solution, cabal-add CodeAction is provided only for the main target. This was only a temporary solution due to limitations of the getBuildTargets function. For more information, consult this thread.

Now it was fixed, and you can choose to what target add the dependency. Video with an example:

https://github.com/user-attachments/assets/b75587df-e277-48de-8c3c-3fb705b64f32

Also, I changed the title for the CodeAction, to a hopefully better one.

Implementation details

I changed the functions getBuildTargets and buildTargetComponentName to
the getBuildTargetComponentNames that handles GenericPackageDescription and gives ComponentNames of all targets.

What isn't implemented

  • [x] Previous tests were built assuming that there is need to wait only for one CodeAction. Now this leads to a race condition.

VenInf avatar Aug 30 '24 00:08 VenInf

So, do I understand this correctly, we offer to add the dependency to some dependency, even though we should be able to statically tell to which component the filepath belongs to?

Yes, this implementation offers to chose, to what target add the dependency. I think that I can narrow down the list of potential targets using the information from the filepath, but it will take some time to implement. I don't know if it's possible to completely resolve to what target the dependency is related to. Right now, in current merged solution, there are no resolvers at all.

VenInf avatar Sep 22 '24 16:09 VenInf

After a better look at the current implementation, it turned out that target selection was better than expected. Unfortunately, the mechanism isn't properly documented and tested, and I will solve it in a separate PR.

VenInf avatar Nov 22 '24 13:11 VenInf