diff options
author | Adam Gundry <adam@well-typed.com> | 2016-02-01 16:41:03 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-02-01 22:12:52 +0100 |
commit | dd0b7c78f64f2498594d3ef89d3bf884402f14d9 (patch) | |
tree | 792e32b256531c2593e37de30a80f43692e2ded0 | |
parent | 73293109645efe42bf3fdf3335f4ab7cef39001b (diff) | |
download | haskell-dd0b7c78f64f2498594d3ef89d3bf884402f14d9.tar.gz |
Avoid mangled/derived names in GHCi autocomplete (fixes #11328)
This changes `getRdrNamesInScope` to use field labels rather than
selector names for fields from modules with `DuplicateRecordFields`
enabled. Moreover, it filters out derived names (e.g. type
representation bindings) that shouldn't show up in autocomplete.
Test Plan: New test ghci/should_run/T11328
Reviewers: kolmodin, austin, bgamari, simonpj
Reviewed By: bgamari, simonpj
Subscribers: simonpj, thomie
Differential Revision: https://phabricator.haskell.org/D1870
GHC Trac Issues: #11328
-rw-r--r-- | compiler/basicTypes/RdrName.hs | 4 | ||||
-rw-r--r-- | compiler/main/InteractiveEval.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T11328.script | 4 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T11328.stdout | 5 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/all.T | 1 |
5 files changed, 16 insertions, 3 deletions
diff --git a/compiler/basicTypes/RdrName.hs b/compiler/basicTypes/RdrName.hs index 6e0350da74..62771e924b 100644 --- a/compiler/basicTypes/RdrName.hs +++ b/compiler/basicTypes/RdrName.hs @@ -629,10 +629,10 @@ greUsedRdrName gre@GRE{ gre_name = name, gre_lcl = lcl, gre_imp = iss } occ = greOccName gre greRdrNames :: GlobalRdrElt -> [RdrName] -greRdrNames GRE{ gre_name = name, gre_lcl = lcl, gre_imp = iss } +greRdrNames gre@GRE{ gre_lcl = lcl, gre_imp = iss } = (if lcl then [unqual] else []) ++ concatMap do_spec (map is_decl iss) where - occ = nameOccName name + occ = greOccName gre unqual = Unqual occ do_spec decl_spec | is_qual decl_spec = [qual] diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs index b66a4f8c82..ac4c60e735 100644 --- a/compiler/main/InteractiveEval.hs +++ b/compiler/main/InteractiveEval.hs @@ -800,13 +800,16 @@ getNamesInScope :: GhcMonad m => m [Name] getNamesInScope = withSession $ \hsc_env -> do return (map gre_name (globalRdrEnvElts (ic_rn_gbl_env (hsc_IC hsc_env)))) +-- | Returns all 'RdrName's in scope in the current interactive +-- context, excluding any that are internally-generated. getRdrNamesInScope :: GhcMonad m => m [RdrName] getRdrNamesInScope = withSession $ \hsc_env -> do let ic = hsc_IC hsc_env gbl_rdrenv = ic_rn_gbl_env ic gbl_names = concatMap greRdrNames $ globalRdrEnvElts gbl_rdrenv - return gbl_names + -- Exclude internally generated names; see e.g. Trac #11328 + return (filter (not . isDerivedOccName . rdrNameOcc) gbl_names) -- | Parses a string as an identifier, and returns the list of 'Name's that diff --git a/testsuite/tests/ghci/should_run/T11328.script b/testsuite/tests/ghci/should_run/T11328.script new file mode 100644 index 0000000000..410e4b7f47 --- /dev/null +++ b/testsuite/tests/ghci/should_run/T11328.script @@ -0,0 +1,4 @@ +:seti -XDuplicateRecordFields +data T = MkT { foo :: Int } +:complete repl "foo" +:complete repl "$" diff --git a/testsuite/tests/ghci/should_run/T11328.stdout b/testsuite/tests/ghci/should_run/T11328.stdout new file mode 100644 index 0000000000..272da7975c --- /dev/null +++ b/testsuite/tests/ghci/should_run/T11328.stdout @@ -0,0 +1,5 @@ +1 1 "" +"foo" +2 2 "" +"$" +"$!" diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T index 68c74072f6..930f14b7a1 100644 --- a/testsuite/tests/ghci/should_run/all.T +++ b/testsuite/tests/ghci/should_run/all.T @@ -22,3 +22,4 @@ test('T9914', just_ghci, ghci_script, ['T9914.script']) test('T9915', just_ghci, ghci_script, ['T9915.script']) test('T10145', just_ghci, ghci_script, ['T10145.script']) test('T7253', just_ghci, ghci_script, ['T7253.script']) +test('T11328', just_ghci, ghci_script, ['T11328.script']) |