Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack deps update cabal-add dependency #4388

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
4004210
cabal-add code action traces
VenInf Jun 28, 2024
76af0ab
showing specific code action
VenInf Jun 29, 2024
b2e45a0
hidden package progress
VenInf Jul 1, 2024
a940b58
+ hidden-package test case
VenInf Jul 2, 2024
ccbd228
test cases update
VenInf Jul 4, 2024
0266514
embedded cabal-add
VenInf Jul 4, 2024
5cf86c8
cabal-add CodeAction, PATH cabal-add install
VenInf Jul 5, 2024
fc2db8f
+ cabal file path in CodeAction
VenInf Jul 9, 2024
922cfe5
WIP command arguments
VenInf Jul 10, 2024
e20da0d
WIP hardcoded cabal-add
VenInf Jul 10, 2024
a032bc0
+ cabal-add
VenInf Jul 11, 2024
9c64de8
catched parameters in a command
VenInf Jul 11, 2024
f633e70
working prototype
VenInf Jul 12, 2024
fd719e6
adds package's version if detected
VenInf Jul 12, 2024
2087b06
+ docs
VenInf Jul 12, 2024
980e4ed
+ source-repository-package cabal-add
VenInf Jul 15, 2024
01e33c8
parsing comma
VenInf Jul 15, 2024
c8cde85
+ build targets
VenInf Jul 17, 2024
707316b
WIP resolve multiple targets
VenInf Jul 17, 2024
5f1694b
resolve target, no multiple
VenInf Jul 18, 2024
419a48a
rule usage, refactoring
VenInf Jul 18, 2024
3977151
better findResponsibleCabalFile
VenInf Jul 22, 2024
1ad4356
runAction data lookup
VenInf Jul 22, 2024
68b9a64
bugfix
VenInf Jul 27, 2024
f729147
WIP tests
VenInf Jul 29, 2024
d06fa2e
WIP tests, ghcIdePlugin issue(?)
VenInf Jul 30, 2024
fca76cb
WIP: make tests fail for good reason
fendor Jul 31, 2024
260d333
WIP tests, succesfull CodeAction call
VenInf Jul 31, 2024
7258ea0
WIP from writeFile to edit
VenInf Aug 1, 2024
497b1fc
WIP logging prototype
VenInf Aug 3, 2024
cf8d356
Use PluginError instead of error
fendor Aug 4, 2024
45399c6
Wait for TextEdit messages in CabalAdd test
fendor Aug 4, 2024
a1c70db
WIP formatting
VenInf Aug 3, 2024
4abb95e
WIP formatting
VenInf Aug 4, 2024
6924af6
dashed deps test
VenInf Aug 4, 2024
24ac7bb
more tests
VenInf Aug 5, 2024
069e796
renamed tests
VenInf Aug 6, 2024
c05ee6d
formatting and cleanup
VenInf Aug 6, 2024
1959d74
schema update
VenInf Aug 7, 2024
3f5d4f7
test assertion order fix
VenInf Aug 7, 2024
5157063
test dashed change
VenInf Aug 7, 2024
0b335fd
regex tests
VenInf Aug 8, 2024
7704af3
formatting
VenInf Aug 8, 2024
a661b3b
Update plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs
VenInf Aug 14, 2024
11a7496
tests, formatting, other
VenInf Aug 14, 2024
37522fa
formatting
VenInf Aug 14, 2024
1ae3613
descriptor
VenInf Aug 14, 2024
f1ef7c9
Apply suggestions from code review
VenInf Aug 16, 2024
911ccbe
diagnostic optimisation
VenInf Aug 16, 2024
d9bf2b2
Update plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/CabalAdd.hs
VenInf Aug 16, 2024
831b110
Apply suggestions from code review
VenInf Aug 16, 2024
9cb82b8
HlsPlugins rename id
VenInf Aug 16, 2024
7b36ae2
docs, revert changes
VenInf Aug 16, 2024
cca5bfc
logs, docs
VenInf Aug 16, 2024
5fb7943
more docs
VenInf Aug 16, 2024
a3ea3b0
docs
VenInf Aug 16, 2024
78913d3
imports
VenInf Aug 16, 2024
f2129d4
docs
VenInf Aug 16, 2024
0b26f5d
schema
VenInf Aug 16, 2024
e4e363b
Apply suggestions from code review
VenInf Aug 18, 2024
76f064c
- logs and empty suggestion
VenInf Aug 18, 2024
310226f
- empty recorder
VenInf Aug 18, 2024
ae6a060
docs
VenInf Aug 18, 2024
385d83b
resolve merging issues
VenInf Aug 18, 2024
68deb73
Merge branch 'master' into cabal-add-codeaction
fendor Aug 20, 2024
e8c6051
Add cabal-add extra-dep for stack files
fendor Aug 20, 2024
5dad02a
cabal-add release
VenInf Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ packages:
./hls-plugin-api
./hls-test-utils


index-state: 2024-06-29T00:00:00Z

tests: True
Expand Down
9 changes: 9 additions & 0 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ library hls-cabal-plugin
Ide.Plugin.Cabal.Completion.Types
Ide.Plugin.Cabal.FieldSuggest
Ide.Plugin.Cabal.LicenseSuggest
Ide.Plugin.Cabal.CabalAdd
Ide.Plugin.Cabal.Orphans
Ide.Plugin.Cabal.Outline
Ide.Plugin.Cabal.Parse
Expand All @@ -270,6 +271,12 @@ library hls-cabal-plugin
, transformers
, unordered-containers >=0.2.10.0
, containers
, cabal-add
, process
, aeson
, Cabal
, pretty

hs-source-dirs: plugins/hls-cabal-plugin/src

test-suite hls-cabal-plugin-tests
Expand All @@ -284,6 +291,7 @@ test-suite hls-cabal-plugin-tests
Context
Utils
Outline
CabalAdd
build-depends:
, base
, bytestring
Expand All @@ -296,6 +304,7 @@ test-suite hls-cabal-plugin-tests
, lens
, lsp-types
, text
, hls-plugin-api

-----------------------------
-- class plugin
Expand Down
51 changes: 50 additions & 1 deletion plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

module Ide.Plugin.Cabal (descriptor, Log (..)) where
module Ide.Plugin.Cabal (descriptor, haskellInteractionDescriptor, Log (..)) where

import Control.Concurrent.Strict
import Control.DeepSeq
Expand Down Expand Up @@ -53,6 +53,9 @@ import qualified Language.LSP.Protocol.Message as LSP
import Language.LSP.Protocol.Types
import qualified Language.LSP.VFS as VFS

import qualified Data.Text ()
import qualified Ide.Plugin.Cabal.CabalAdd as CabalAdd

data Log
= LogModificationTime NormalizedFilePath FileVersion
| LogShake Shake.Log
Expand All @@ -63,6 +66,7 @@ data Log
| LogFOI (HashMap NormalizedFilePath FileOfInterestStatus)
| LogCompletionContext Types.Context Position
| LogCompletions Types.Log
| LogCabalAdd CabalAdd.Log
deriving (Show)

instance Pretty Log where
Expand All @@ -86,6 +90,25 @@ instance Pretty Log where
<+> "for cursor position:"
<+> pretty position
LogCompletions logs -> pretty logs
LogCabalAdd logs -> pretty logs

-- | Some actions with cabal files originate from haskell files.
-- This descriptor allows to hook into the diagnostics of haskell source files, and
-- allows us to provide code actions and commands that interact with `.cabal` files.
haskellInteractionDescriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
haskellInteractionDescriptor recorder plId =
(defaultPluginDescriptor plId "Provides the cabal-add code action in haskell files")
{ pluginHandlers =
mconcat
[ mkPluginHandler LSP.SMethod_TextDocumentCodeAction cabalAddCodeAction
]
, pluginCommands = [PluginCommand CabalAdd.cabalAddCommand "add a dependency to a cabal file" (CabalAdd.command cabalAddRecorder)]
, pluginRules = pure ()
, pluginNotificationHandlers = mempty
}
where
cabalAddRecorder = cmapWithPrio LogCabalAdd recorder


descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
descriptor recorder plId =
Expand Down Expand Up @@ -309,6 +332,32 @@ gotoDefinition ideState _ msgParam = do
isSectionArgName name (Syntax.Section _ sectionArgName _) = name == CabalFields.onelineSectionArgs sectionArgName
isSectionArgName _ _ = False

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
[] -> pure $ InL []
_ ->
case uriToFilePath uri of
Nothing -> pure $ InL []
Just haskellFilePath -> do
mbCabalFile <- liftIO $ CabalAdd.findResponsibleCabalFile haskellFilePath
case mbCabalFile of
Nothing -> pure $ InL []
Just cabalFilePath -> do
verTxtDocId <- lift $ pluginGetVersionedTextDoc $ TextDocumentIdentifier (filePathToUri cabalFilePath)
mbGPD <- liftIO $ runAction "cabal.cabal-add" state $ useWithStale ParseCabalFile $ toNormalizedFilePath cabalFilePath
case mbGPD of
Nothing -> pure $ InL []
Just (gpd, _) -> do
actions <- liftIO $ CabalAdd.addDependencySuggestCodeAction plId verTxtDocId
suggestions
haskellFilePath cabalFilePath
gpd
pure $ InL $ fmap InR actions


-- ----------------------------------------------------------------
-- Cabal file of Interest rules and global variable
-- ----------------------------------------------------------------
Expand Down
Loading