forked from haskell/haskell-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggestions for missing imports from local modules (haskell/ghcide#739)
* Suggestions for missing imports from local modules * Avoid unnecessary work on InitialLoad when checkProject is off
- Loading branch information
1 parent
39ce701
commit a00cc4b
Showing
10 changed files
with
116 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Development.IDE.Types.Exports | ||
( | ||
IdentInfo(..), | ||
ExportsMap, | ||
createExportsMap, | ||
) where | ||
|
||
import Avail (AvailInfo(..)) | ||
import Control.DeepSeq (NFData) | ||
import Data.Text (pack, Text) | ||
import Development.IDE.GHC.Compat | ||
import Development.IDE.GHC.Util | ||
import Data.HashMap.Strict (HashMap) | ||
import GHC.Generics (Generic) | ||
import Name | ||
import FieldLabel (flSelector) | ||
import qualified Data.HashMap.Strict as Map | ||
import GhcPlugins (IfaceExport) | ||
|
||
type ExportsMap = HashMap IdentifierText [(IdentInfo,ModuleNameText)] | ||
|
||
type IdentifierText = Text | ||
type ModuleNameText = Text | ||
|
||
data IdentInfo = IdentInfo | ||
{ name :: !Text | ||
, rendered :: Text | ||
, parent :: !(Maybe Text) | ||
, isDatacon :: !Bool | ||
} | ||
deriving (Eq, Generic, Show) | ||
|
||
instance NFData IdentInfo | ||
|
||
mkIdentInfos :: AvailInfo -> [IdentInfo] | ||
mkIdentInfos (Avail n) = | ||
[IdentInfo (pack (prettyPrint n)) (pack (printName n)) Nothing (isDataConName n)] | ||
mkIdentInfos (AvailTC parent (n:nn) flds) | ||
-- Following the GHC convention that parent == n if parent is exported | ||
| n == parent | ||
= [ IdentInfo (pack (prettyPrint n)) (pack (printName n)) (Just $! parentP) True | ||
| n <- nn ++ map flSelector flds | ||
] ++ | ||
[ IdentInfo (pack (prettyPrint n)) (pack (printName n)) Nothing False] | ||
where | ||
parentP = pack $ prettyPrint parent | ||
|
||
mkIdentInfos (AvailTC _ nn flds) | ||
= [ IdentInfo (pack (prettyPrint n)) (pack (printName n)) Nothing True | ||
| n <- nn ++ map flSelector flds | ||
] | ||
|
||
createExportsMap :: [ModIface] -> ExportsMap | ||
createExportsMap = Map.fromListWith (++) . concatMap doOne | ||
where | ||
doOne mi = concatMap (unpackAvail mn) (mi_exports mi) | ||
where | ||
mn = moduleName $ mi_module mi | ||
|
||
unpackAvail :: ModuleName -> IfaceExport -> [(Text, [(IdentInfo, Text)])] | ||
unpackAvail mod = | ||
map (\id@IdentInfo {..} -> (name, [(id, pack $ moduleNameString mod)])) | ||
. mkIdentInfos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters