-
-
Notifications
You must be signed in to change notification settings - Fork 391
Auto complete definitions within imports #2152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
47fd19d
34e3e7a
31471c7
8b9310e
dcfdbfc
863a483
9306c91
21af666
2111b5e
f899d00
987119b
b3a0ad7
b54678d
7a73509
10919e0
2c519c4
387e5d0
feaa4e9
5bfff3d
8a167a0
4f85abc
daf1915
1c1012d
80820bb
b79af6b
7454e6c
f0e25c3
fa7763e
1077480
88f2c56
110ce17
63fb733
6df51ae
440fb82
689b1b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import Data.Aeson | |
import qualified Data.HashMap.Strict as Map | ||
import qualified Data.HashSet as Set | ||
import Data.List (find) | ||
import qualified Data.Map as DM (Map, fromListWith, empty) | ||
import Data.Maybe | ||
import qualified Data.Text as T | ||
import Development.IDE.Core.PositionMapping | ||
|
@@ -131,35 +132,49 @@ getCompletionsLSP ide plId | |
fmap Right $ case (contents, uriToFilePath' uri) of | ||
(Just cnts, Just path) -> do | ||
let npath = toNormalizedFilePath' path | ||
(ideOpts, compls) <- liftIO $ runIdeAction "Completion" (shakeExtras ide) $ do | ||
(ideOpts, compls, moduleExports) <- liftIO $ runIdeAction "Completion" (shakeExtras ide) $ do | ||
opts <- liftIO $ getIdeOptionsIO $ shakeExtras ide | ||
localCompls <- useWithStaleFast LocalCompletions npath | ||
nonLocalCompls <- useWithStaleFast NonLocalCompletions npath | ||
pm <- useWithStaleFast GetParsedModule npath | ||
binds <- fromMaybe (mempty, zeroMapping) <$> useWithStaleFast GetBindings npath | ||
exportsMapIO <- fmap(envPackageExports . fst) <$> useWithStaleFast GhcSession npath | ||
exportsMap <- mapM liftIO exportsMapIO | ||
let moduleExports = buildModouleExportMap exportsMap | ||
let exportsCompItems = foldMap (map (fromIdentInfo uri) . Set.toList) . Map.elems . getExportsMap <$> exportsMap | ||
exportsCompls = mempty{anyQualCompls = fromMaybe [] exportsCompItems} | ||
let compls = (fst <$> localCompls) <> (fst <$> nonLocalCompls) <> Just exportsCompls | ||
pure (opts, fmap (,pm,binds) compls) | ||
case compls of | ||
Just (cci', parsedMod, bindMap) -> do | ||
pure (opts, fmap (,pm,binds) compls, moduleExports) | ||
case (compls, moduleExports) of | ||
(Just (cci', parsedMod, bindMap), mExports) -> do | ||
alexnaspo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pfix <- VFS.getCompletionPrefix position cnts | ||
case (pfix, completionContext) of | ||
(Just (VFS.PosPrefixInfo _ "" _ _), Just CompletionContext { _triggerCharacter = Just "."}) | ||
-> return (InL $ List []) | ||
(Just pfix', _) -> do | ||
let clientCaps = clientCapabilities $ shakeExtras ide | ||
config <- getCompletionsConfig plId | ||
allCompletions <- liftIO $ getCompletions plId ideOpts cci' parsedMod bindMap pfix' clientCaps config | ||
allCompletions <- liftIO $ getCompletions plId ideOpts cci' parsedMod bindMap pfix' clientCaps config mExports | ||
pure $ InL (List allCompletions) | ||
_ -> return (InL $ List []) | ||
_ -> return (InL $ List []) | ||
_ -> return (InL $ List []) | ||
|
||
---------------------------------------------------------------------------------------------------- | ||
|
||
identInfoToKeyVal :: IdentInfo -> (T.Text, T.Text) | ||
identInfoToKeyVal IdentInfo {rendered, moduleNameText} = | ||
(moduleNameText, rendered) | ||
|
||
buildModouleExportMap:: Maybe (ExportsMap) -> DM.Map T.Text [T.Text] | ||
buildModouleExportMap (Just exportsMap) = do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this function do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a typo in the name, however, it builds a map of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And why is it needed? Can't you use the ExportsMap as it is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe I need it because I have to group on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, you are right. But why build a map to do only one lookup and then throw it away?
Neither is good enough, you want O(logN). How? Probably by changing the representation of the exports map to add a second index, the module name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think the first suggestion would be a good first pass? With potential follow up commits to pull out a plugin? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ExportsMap only indexes package modules. You will need to fetch the ModIface for local modules. So both changes are needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took a first pass at this. There is still more work to do. As of this comment, I am just generating the map based on the already existing map. I also see that this does not work for local modules, as you suggested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second pass - I generate the map from the modIface rather than the existing map.. This still does not account for local modules There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I now generate the map for local modules as well. I will take a look at your other comments. |
||
sortAndGroup $ map identInfoToKeyVal $ | ||
concatMap (Set.toList . snd) $ toList $ getExportsMap exportsMap | ||
buildModouleExportMap (Nothing) = DM.empty | ||
|
||
sortAndGroup :: [(T.Text, T.Text)] -> DM.Map T.Text [T.Text] | ||
sortAndGroup assocs = DM.fromListWith (++) [(k, [v]) | (k, v) <- assocs] | ||
|
||
extendImportCommand :: PluginCommand IdeState | ||
extendImportCommand = | ||
PluginCommand (CommandId extendImportCommandId) "additional edits for a completion" extendImportHandler | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Control.Applicative (Alternative) | ||
import qualified Data.List | ||
|
||
main :: IO () | ||
main = putStrLn "hello" | ||
|
||
foo :: Either a b -> Either a b | ||
foo = id |
Uh oh!
There was an error while loading. Please reload this page.