@@ -36,9 +36,8 @@ import Development.IDE.GHC.Compat (ContextInfo (Use),
36
36
ImpDeclSpec (ImpDeclSpec , is_as , is_dloc , is_qual ),
37
37
ImportSpec (ImpSpec ),
38
38
LImportDecl , ModuleName ,
39
- Name , NameEnv , OccName ,
40
- ParsedModule , RefMap , Span ,
41
- SrcSpan ,
39
+ Name , NameEnv , ParsedModule ,
40
+ RefMap , Span , SrcSpan ,
42
41
TcGblEnv (tcg_rdr_env ),
43
42
emptyUFM , globalRdrEnvElts ,
44
43
gre_imp , gre_name , locA ,
@@ -111,7 +110,7 @@ data ImportedBy = ImportedBy {
111
110
}
112
111
113
112
isRangeWithinImportedBy :: Range -> ImportedBy -> Bool
114
- isRangeWithinImportedBy range ( ImportedBy _ srcSpan) = fromMaybe False $ spanContainsRange srcSpan range
113
+ isRangeWithinImportedBy range ImportedBy {importedBySrcSpan} = fromMaybe False $ spanContainsRange importedBySrcSpan range
115
114
116
115
globalRdrEnvToNameToImportedByMap :: GlobalRdrEnv -> NameEnv [ImportedBy ]
117
116
globalRdrEnvToNameToImportedByMap =
@@ -168,9 +167,6 @@ refMapToUsedIdentifiers = DList.toList . Map.foldlWithKey' folder DList.empty
168
167
, Use `elem` identInfo = Just $ UsedIdentifier name identifierSpan
169
168
| otherwise = Nothing
170
169
171
- occNameToText :: OccName -> Text
172
- occNameToText = Text. pack . occNameString
173
-
174
170
updateColOffset :: Int -> Int -> Int -> Int
175
171
updateColOffset row lineOffset colOffset
176
172
| row == lineOffset = colOffset
@@ -182,13 +178,13 @@ usedIdentifiersToTextEdits range nameToImportedByMap sourceText usedIdentifiers
182
178
State. evalState (makeStateComputation sortedUsedIdentifiers) (Text. lines sourceText, 0 , 0 )
183
179
where
184
180
folder :: [TextEdit ] -> UsedIdentifier -> State ([Text ], Int , Int ) [TextEdit ]
185
- folder prevTextEdits ( UsedIdentifier identifierName identifierSpan)
186
- | Just importedBys <- lookupNameEnv nameToImportedByMap identifierName
187
- , Just ( ImportedBy alias _) <- find (isRangeWithinImportedBy range) importedBys
188
- , let IdentifierSpan row startCol endCol = identifierSpan
189
- , let identifierRange = identifierSpanToRange identifierSpan
190
- , let aliasText = Text. pack $ moduleNameString alias
191
- , let identifierText = Text. pack $ occNameString $ nameOccName identifierName
181
+ folder prevTextEdits UsedIdentifier {usedIdentifierName, usedIdentifierSpan}
182
+ | Just importedBys <- lookupNameEnv nameToImportedByMap usedIdentifierName
183
+ , Just ImportedBy {importedByAlias} <- find (isRangeWithinImportedBy range) importedBys
184
+ , let IdentifierSpan row startCol _ = usedIdentifierSpan
185
+ , let identifierRange = identifierSpanToRange usedIdentifierSpan
186
+ , let aliasText = Text. pack $ moduleNameString importedByAlias
187
+ , let identifierText = Text. pack $ occNameString $ nameOccName usedIdentifierName
192
188
, let qualifiedIdentifierText = aliasText <> " ." <> identifierText = do
193
189
(sourceTextLines, lineOffset, updateColOffset row lineOffset -> colOffset) <- State. get
194
190
let lines = List. drop (row - lineOffset) sourceTextLines
@@ -219,7 +215,7 @@ usedIdentifiersToTextEdits range nameToImportedByMap sourceText usedIdentifiers
219
215
-- 3. For each used name in refMap check whether the name comes from an import
220
216
-- at the origin of the code action.
221
217
codeActionProvider :: PluginMethodHandler IdeState Method_TextDocumentCodeAction
222
- codeActionProvider ideState pluginId (CodeActionParams _ _ documentId range context ) = do
218
+ codeActionProvider ideState _pluginId (CodeActionParams _ _ documentId range _ ) = do
223
219
normalizedFilePath <- getNormalizedFilePathE (documentId ^. L. uri)
224
220
TcModuleResult { tmrParsed, tmrTypechecked } <- runActionE " QualifyImportedNames.TypeCheck" ideState $ useE TypeCheck normalizedFilePath
225
221
if isJust (findLImportDeclAt range tmrParsed)
0 commit comments