Opened 2 years ago

Closed 10 months ago

#5687 closed feature request (fixed)

Friendly Interface for auto-completion of GHCi

Reported by: linsumang Owned by:
Priority: normal Milestone: 7.6.2
Component: GHCi Version: 7.2.1
Keywords: Cc: hvr@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Now the GHCi can do TAB completion when running in term.

But in Emacs/Inf?-Haskell mode, TAB completion doesn't work.
It should be great that if GHCi support the command like "complete" in GDB.

If GHCi supports this, it's easy to implement TAB completion in Emacs/Inf?-Haskell mode.

Attachments (3)

ticket-5687-ghci-complete.diff (2.0 KB) - added by hvr 11 months ago.
First draft for a :complete command
ticket-5687-ghci-complete.v2.diff (3.5 KB) - added by hvr 11 months ago.
2nd draft for :complete command
ticket-5687-ghci-complete-docs.v2.diff (3.8 KB) - added by hvr 10 months ago.
User Guide entry for :complete comment

Download all attachments as: .zip

Change History (13)

comment:1 Changed 2 years ago by igloo

  • Difficulty set to Unknown
  • Milestone set to 7.6.1

comment:2 Changed 20 months ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2

Changed 11 months ago by hvr

First draft for a :complete command

comment:3 Changed 11 months ago by hvr

  • Cc hvr@… added

The attached patch currently exposes the ghciCompleteWord function and uses Read/Show quoted strings for input/output. The first two lines returned are the number of completion candidates and the unused line part (as returned by ghciCompleteWord). The remaining lines are all completions found (up to the given limit).

Here's an example:

Prelude> :complete 
Syntax: :complete repl <max-completions> <quoted-string-to-complete>
Prelude> :complete repl 5 "import For"
21
"import "
"Foreign"
"Foreign.C"
"Foreign.C.Error"
"Foreign.C.String"
"Foreign.C.Types"
Prelude> :complete repl 5 ":"
52
""
":?"
":abandon"
":add"
":back"
":break"
Prelude> :complete repl 5 "map"
3
""
"map"
"mapM"
"mapM_"
Prelude> :complete repl 0 "map"
3
""
Prelude> :complete repl 0 ""
470
""
Prelude> :complete repl -1 "map"
3
""
"map"
"mapM"
"mapM_"

comment:4 Changed 11 months ago by igloo

  • Status changed from new to patch

Changed 11 months ago by hvr

2nd draft for :complete command

comment:5 Changed 11 months ago by hvr

I've attached a patch providing a more refined :complete command:

This one takes an optional range (1-based indexing, syntax [n-][m] where n denotes first index, and m the last index shown), allowing to slice the result list; moreover the first line emitted now contains:

<completions-printed-count> <total-completions-count> <line-prefix>

And here's an example session again:

Prelude> :complete 
Syntax: :complete repl [<range>] <quoted-string-to-complete>
Prelude> :complete repl 5 "import For"
5 21 "import "
"Foreign"
"Foreign.C"
"Foreign.C.Error"
"Foreign.C.String"
"Foreign.C.Types"
Prelude> :complete repl 5-10 "import For"
6 21 "import "
"Foreign.C.Types"
"Foreign.Concurrent"
"Foreign.ForeignPtr"
"Foreign.ForeignPtr.Safe"
"Foreign.ForeignPtr.Unsafe"
"Foreign.Marshal"
Prelude> :complete repl 20- "import For"
2 21 "import "
"Foreign.StablePtr"
"Foreign.Storable"
Prelude> :complete repl "map"
3 3 ""
"map"
"mapM"
"mapM_"

comment:6 Changed 11 months ago by igloo

Is there any sort of standard for what the output should look like?

comment:7 Changed 11 months ago by igloo

  • Status changed from patch to new

hvr says he knows of no standard. He'll add some docs for the user guide, and is also working on an implementation of the emacs side.

hvr: I wonder if it would be better to use your own String-showing function rather than using Show, so as to make it possible to correctly use simpler parsing on the emacs side.

comment:8 Changed 10 months ago by hvr

@igloo:

I've got a nicely working proof of concept implementation for Emacs (see http://youtu.be/06q-sCoqwEY for a short screencast demonstration).

Implementing complete Read/Show? serialization for strings wasn't that hard in Elisp, and the standard case, when no escaping is needed has a cheap code path.

Changed 10 months ago by hvr

User Guide entry for :complete comment

comment:9 Changed 10 months ago by igloo

  • Status changed from new to patch

comment:10 Changed 10 months ago by igloo

  • Resolution set to fixed
  • Status changed from patch to closed

Applied, thanks

Note: See TracTickets for help on using tickets.