@@ -36,9 +36,8 @@ import Development.IDE.GHC.Compat (ContextInfo (Use),
3636 ImpDeclSpec (ImpDeclSpec , is_as , is_dloc , is_qual ),
3737 ImportSpec (ImpSpec ),
3838 LImportDecl , ModuleName ,
39- Name , NameEnv , OccName ,
40- ParsedModule , RefMap , Span ,
41- SrcSpan ,
39+ Name , NameEnv , ParsedModule ,
40+ RefMap , Span , SrcSpan ,
4241 TcGblEnv (tcg_rdr_env ),
4342 emptyUFM , globalRdrEnvElts ,
4443 gre_imp , gre_name , locA ,
@@ -111,7 +110,7 @@ data ImportedBy = ImportedBy {
111110}
112111
113112isRangeWithinImportedBy :: Range -> ImportedBy -> Bool
114- isRangeWithinImportedBy range ( ImportedBy _ srcSpan) = fromMaybe False $ spanContainsRange srcSpan range
113+ isRangeWithinImportedBy range ImportedBy {importedBySrcSpan} = fromMaybe False $ spanContainsRange importedBySrcSpan range
115114
116115globalRdrEnvToNameToImportedByMap :: GlobalRdrEnv -> NameEnv [ImportedBy ]
117116globalRdrEnvToNameToImportedByMap =
@@ -168,9 +167,6 @@ refMapToUsedIdentifiers = DList.toList . Map.foldlWithKey' folder DList.empty
168167 , Use `elem` identInfo = Just $ UsedIdentifier name identifierSpan
169168 | otherwise = Nothing
170169
171- occNameToText :: OccName -> Text
172- occNameToText = Text. pack . occNameString
173-
174170updateColOffset :: Int -> Int -> Int -> Int
175171updateColOffset row lineOffset colOffset
176172 | row == lineOffset = colOffset
@@ -182,13 +178,13 @@ usedIdentifiersToTextEdits range nameToImportedByMap sourceText usedIdentifiers
182178 State. evalState (makeStateComputation sortedUsedIdentifiers) (Text. lines sourceText, 0 , 0 )
183179 where
184180 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
192188 , let qualifiedIdentifierText = aliasText <> " ." <> identifierText = do
193189 (sourceTextLines, lineOffset, updateColOffset row lineOffset -> colOffset) <- State. get
194190 let lines = List. drop (row - lineOffset) sourceTextLines
@@ -219,7 +215,7 @@ usedIdentifiersToTextEdits range nameToImportedByMap sourceText usedIdentifiers
219215-- 3. For each used name in refMap check whether the name comes from an import
220216-- at the origin of the code action.
221217codeActionProvider :: PluginMethodHandler IdeState Method_TextDocumentCodeAction
222- codeActionProvider ideState pluginId (CodeActionParams _ _ documentId range context ) = do
218+ codeActionProvider ideState _pluginId (CodeActionParams _ _ documentId range _ ) = do
223219 normalizedFilePath <- getNormalizedFilePathE (documentId ^. L. uri)
224220 TcModuleResult { tmrParsed, tmrTypechecked } <- runActionE " QualifyImportedNames.TypeCheck" ideState $ useE TypeCheck normalizedFilePath
225221 if isJust (findLImportDeclAt range tmrParsed)
0 commit comments