@@ -10,13 +10,10 @@ module Development.IDE.Plugin.CodeAction
10
10
(
11
11
-- * For haskell-language-server
12
12
codeAction
13
- , codeLens
14
13
, rulePackageExports
15
- , commandHandler
16
14
17
15
-- * For testing
18
16
, blockCommandId
19
- , typeSignatureCommandId
20
17
, matchRegExMultipleImports
21
18
) where
22
19
@@ -28,21 +25,19 @@ import Development.IDE.Core.Service
28
25
import Development.IDE.Core.Shake
29
26
import Development.IDE.GHC.Error
30
27
import Development.IDE.GHC.ExactPrint
31
- import Development.IDE.LSP.Server
32
28
import Development.IDE.Plugin.CodeAction.ExactPrint
33
29
import Development.IDE.Plugin.CodeAction.PositionIndexed
34
30
import Development.IDE.Plugin.CodeAction.RuleTypes
35
31
import Development.IDE.Plugin.CodeAction.Rules
32
+ import Development.IDE.Plugin.TypeLenses (suggestSignature )
36
33
import Development.IDE.Types.Exports
37
34
import Development.IDE.Types.Location
38
35
import Development.IDE.Types.Options
39
36
import qualified Data.HashMap.Strict as Map
40
37
import qualified Language.Haskell.LSP.Core as LSP
41
38
import Language.Haskell.LSP.VFS
42
- import Language.Haskell.LSP.Messages
43
39
import Language.Haskell.LSP.Types
44
40
import qualified Data.Rope.UTF16 as Rope
45
- import Data.Aeson.Types (toJSON , fromJSON , Value (.. ), Result (.. ))
46
41
import Data.Char
47
42
import Data.Maybe
48
43
import Data.List.Extra
@@ -58,17 +53,13 @@ import Control.Applicative ((<|>))
58
53
import Safe (atMay )
59
54
import Bag (isEmptyBag )
60
55
import qualified Data.HashSet as Set
61
- import Control.Concurrent.Extra (threadDelay , readVar )
56
+ import Control.Concurrent.Extra (readVar )
62
57
import Development.IDE.GHC.Util (printRdrName )
63
58
import Ide.PluginUtils (subRange )
64
59
65
60
-- | a command that blocks forever. Used for testing
66
61
blockCommandId :: T. Text
67
62
blockCommandId = " ghcide.command.block"
68
-
69
- typeSignatureCommandId :: T. Text
70
- typeSignatureCommandId = " typesignature.add"
71
-
72
63
-- | Generate code actions.
73
64
codeAction
74
65
:: LSP. LspFuncs c
@@ -117,52 +108,6 @@ mkCA :: T.Text -> [Diagnostic] -> WorkspaceEdit -> CAResult
117
108
mkCA title diags edit =
118
109
CACodeAction $ CodeAction title (Just CodeActionQuickFix ) (Just $ List diags) (Just edit) Nothing
119
110
120
- -- | Generate code lenses.
121
- codeLens
122
- :: LSP. LspFuncs c
123
- -> IdeState
124
- -> CodeLensParams
125
- -> IO (Either ResponseError (List CodeLens ))
126
- codeLens _lsp ideState CodeLensParams {_textDocument= TextDocumentIdentifier uri} = do
127
- let commandId = " typesignature.add"
128
- fmap (Right . List ) $ case uriToFilePath' uri of
129
- Just (toNormalizedFilePath' -> filePath) -> do
130
- _ <- runAction " codeLens" ideState (use TypeCheck filePath)
131
- diag <- getDiagnostics ideState
132
- hDiag <- getHiddenDiagnostics ideState
133
- pure
134
- [ CodeLens _range (Just (Command title commandId (Just $ List [toJSON edit]))) Nothing
135
- | (dFile, _, dDiag@ Diagnostic {_range= _range}) <- diag ++ hDiag
136
- , dFile == filePath
137
- , (title, tedit) <- suggestSignature False dDiag
138
- , let edit = WorkspaceEdit (Just $ Map. singleton uri $ List tedit) Nothing
139
- ]
140
- Nothing -> pure []
141
-
142
- -- | Execute the "typesignature.add" command.
143
- commandHandler
144
- :: LSP. LspFuncs c
145
- -> IdeState
146
- -> ExecuteCommandParams
147
- -> IO (Either ResponseError Value , Maybe (ServerMethod , ApplyWorkspaceEditParams ))
148
- commandHandler lsp _ideState ExecuteCommandParams {.. }
149
- -- _command is prefixed with a process ID, because certain clients
150
- -- have a global command registry, and all commands must be
151
- -- unique. And there can be more than one ghcide instance running
152
- -- at a time against the same client.
153
- | T. isSuffixOf blockCommandId _command
154
- = do
155
- LSP. sendFunc lsp $ NotCustomServer $
156
- NotificationMessage " 2.0" (CustomServerMethod " ghcide/blocking/command" ) Null
157
- threadDelay maxBound
158
- return (Right Null , Nothing )
159
- | T. isSuffixOf typeSignatureCommandId _command
160
- , Just (List [edit]) <- _arguments
161
- , Success wedit <- fromJSON edit
162
- = return (Right Null , Just (WorkspaceApplyEdit , ApplyWorkspaceEditParams wedit))
163
- | otherwise
164
- = return (Right Null , Nothing )
165
-
166
111
suggestExactAction ::
167
112
ExportsMap ->
168
113
DynFlags ->
@@ -772,31 +717,6 @@ suggestFixConstructorImport _ Diagnostic{_range=_range,..}
772
717
= let fixedImport = typ <> " (" <> constructor <> " )"
773
718
in [(" Fix import of " <> fixedImport, [TextEdit _range fixedImport])]
774
719
| otherwise = []
775
-
776
- suggestSignature :: Bool -> Diagnostic -> [(T. Text , [TextEdit ])]
777
- suggestSignature isQuickFix Diagnostic {_range= _range@ Range {.. },.. }
778
- | _message =~
779
- (" (Top-level binding|Polymorphic local binding|Pattern synonym) with no type signature" :: T. Text ) = let
780
- signature = removeInitialForAll
781
- $ T. takeWhile (\ x -> x/= ' *' && x/= ' •' )
782
- $ T. strip $ unifySpaces $ last $ T. splitOn " type signature: " $ filterNewlines _message
783
- startOfLine = Position (_line _start) startCharacter
784
- beforeLine = Range startOfLine startOfLine
785
- title = if isQuickFix then " add signature: " <> signature else signature
786
- action = TextEdit beforeLine $ signature <> " \n " <> T. replicate startCharacter " "
787
- in [(title, [action])]
788
- where removeInitialForAll :: T. Text -> T. Text
789
- removeInitialForAll (T. breakOnEnd " :: " -> (nm, ty))
790
- | " forall" `T.isPrefixOf` ty = nm <> T. drop 2 (snd (T. breakOn " ." ty))
791
- | otherwise = nm <> ty
792
- startCharacter
793
- | " Polymorphic local binding" `T.isPrefixOf` _message
794
- = _character _start
795
- | otherwise
796
- = 0
797
-
798
- suggestSignature _ _ = []
799
-
800
720
-- | Suggests a constraint for a declaration for which a constraint is missing.
801
721
suggestConstraint :: DynFlags -> ParsedSource -> Diagnostic -> [(T. Text , Rewrite )]
802
722
suggestConstraint df parsedModule diag@ Diagnostic {.. }
@@ -1190,10 +1110,6 @@ matchRegex :: T.Text -> T.Text -> Maybe [T.Text]
1190
1110
matchRegex message regex = case message =~~ regex of
1191
1111
Just (_ :: T. Text , _ :: T. Text , _ :: T. Text , bindings ) -> Just bindings
1192
1112
Nothing -> Nothing
1193
-
1194
- filterNewlines :: T. Text -> T. Text
1195
- filterNewlines = T. concat . T. lines
1196
-
1197
1113
unifySpaces :: T. Text -> T. Text
1198
1114
unifySpaces = T. unwords . T. words
1199
1115
0 commit comments