@@ -88,59 +88,48 @@ codeAction lsp state _ (TextDocumentIdentifier uri) _range CodeActionContext{_di
88
88
df = ms_hspp_opts . pm_mod_summary <$> parsedModule
89
89
actions =
90
90
[ mkCA title [x] edit
91
- | x <- xs, (title, tedit) <- suggestAction exportsMap ideOptions parsedModule text x
91
+ | x <- xs, (title, tedit) <- suggestAction exportsMap ideOptions parsedModule text df annotatedPS x
92
92
, let edit = WorkspaceEdit (Just $ Map. singleton uri $ List tedit) Nothing
93
93
]
94
- actions' =
95
- [mkCA title [x] edit
96
- | x <- xs
97
- , Just ps <- [annotatedPS]
98
- , Just dynflags <- [df]
99
- , (title, graft) <- suggestExactAction exportsMap dynflags ps x
100
- , Right edit <-
101
- [ -- either (Left . traceShow) Right $
102
- rewriteToEdit dynflags uri (annsA ps) graft
103
- ]
104
- ]
105
- actions'' = caRemoveRedundantImports parsedModule text diag xs uri
94
+ actions' = caRemoveRedundantImports parsedModule text diag xs uri
106
95
<> actions
107
- <> actions'
108
96
<> caRemoveInvalidExports parsedModule text diag xs uri
109
- pure $ Right $ List actions''
97
+ pure $ Right $ List actions'
110
98
111
99
mkCA :: T. Text -> [Diagnostic ] -> WorkspaceEdit -> CAResult
112
100
mkCA title diags edit =
113
101
CACodeAction $ CodeAction title (Just CodeActionQuickFix ) (Just $ List diags) (Just edit) Nothing
114
102
115
- suggestExactAction ::
116
- ExportsMap ->
117
- DynFlags ->
118
- Annotated ParsedSource ->
119
- Diagnostic ->
120
- [(T. Text , Rewrite )]
121
- suggestExactAction exportsMap df ps x =
122
- concat
123
- [ suggestConstraint df (astA ps) x
124
- , suggestImplicitParameter (astA ps) x
125
- , suggestExtendImport exportsMap (astA ps) x
126
- ]
103
+ rewrite ::
104
+ Maybe DynFlags ->
105
+ Maybe (Annotated ParsedSource ) ->
106
+ (DynFlags -> ParsedSource -> [(T. Text , Rewrite )]) ->
107
+ [(T. Text , [TextEdit ])]
108
+ rewrite (Just df) (Just ps) f
109
+ | Right edit <- (traverse . traverse ) (rewriteToEdit df (annsA ps)) (f df $ astA ps) = edit
110
+ rewrite _ _ _ = []
127
111
128
112
suggestAction
129
113
:: ExportsMap
130
114
-> IdeOptions
131
115
-> Maybe ParsedModule
132
116
-> Maybe T. Text
117
+ -> Maybe DynFlags
118
+ -> Maybe (Annotated ParsedSource )
133
119
-> Diagnostic
134
120
-> [(T. Text , [TextEdit ])]
135
- suggestAction packageExports ideOptions parsedModule text diag = concat
121
+ suggestAction packageExports ideOptions parsedModule text df annSource diag = concat
136
122
-- Order these suggestions by priority
137
123
[ suggestSignature True diag
124
+ , rewrite df annSource $ \ _ ps -> suggestExtendImport packageExports ps diag
138
125
, suggestFillTypeWildcard diag
139
126
, suggestFixConstructorImport text diag
140
127
, suggestModuleTypo diag
141
128
, suggestReplaceIdentifier text diag
142
129
, removeRedundantConstraints text diag
143
130
, suggestAddTypeAnnotationToSatisfyContraints text diag
131
+ , rewrite df annSource $ \ df ps -> suggestConstraint df ps diag
132
+ , rewrite df annSource $ \ _ ps -> suggestImplicitParameter ps diag
144
133
] ++ concat
145
134
[ suggestNewDefinition ideOptions pm text diag
146
135
++ suggestNewImport packageExports pm diag
0 commit comments