Skip to content
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

Inferior fsharp tab completion #197

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jdodds
Copy link
Contributor

@jdodds jdodds commented Mar 9, 2019

work being done on #184

We want to be able to use fsi's tab-completion, but we can't if we have
to pass --readline- as it turns off readline support. comint reports itself
as a dumb-terminal by default, which causes fsi to treat it like one. Setting
TERM=emacs (or likely and value that's not 'dumb') appears to let us interact
with fsi in the way we want to.

The previous combination of (process-connection-nil) and setting --readline- was
probably done to get around fsi's behavior when using a pty and TERM=dumb, but Im
not 100% sure of that.

This setup for init-ing the inferior fsharp process might need revisted in the future.
This is a start at implementing tab completion for inferior fsharp buffers
through comint-redirect style process filters. The completion process is as
follows:

When inferior-fsharp-get-completion is triggered, we copy the input at the
inferior fsharp prompt and clear the input. We then set up redirection of the
inferior processes output via comint-redirect-setup, and set up a proess filter
to check the output for our completion. Once we get output that looks like a
completion, we grab it, send (length completion) backspaces to the
inferior process to clear it's input buffer, remove our process filter, undo
our redirection setup, return our completion back to the function that
requested it, and insert it in the inferior fsharp prompt line.

This is pretty awkward feeling due to needing to manage our buffer's prompt and
fsi's input buffer seperately, hopefully that's not entirely unavoidable.

Right now, this lacks a few things needed as a bare minimum to be acceptable,
imo:

+ it currently assumes a completion will always be returned (easy to fix)

+ it needs to call (sleep-for) to ensure our output filters aren't deactivated
  before all the output from fsi has been received

+ it will only ever give the first completion -- the way fsi does it is to
  return subsequent members of completions on subsequent tab presses, we don't
  have a mechanism for handling this yet.

The first point can probably be fixed just by looking for a bell in output or
using a timeout, but the second two will require a more fleshed out solution for
process/buffer communication.

Need to read python-shell-completion-native and probably some other
inferior-repl modes completion implementations for guidance.

We also need to figure out how to write tests for this and write them before
going much further here.
@jdodds jdodds force-pushed the inferior-fsharp-tab-completion branch from 1a8d270 to f589e6c Compare March 9, 2019 06:33
@juergenhoetzel juergenhoetzel marked this pull request as ready for review March 10, 2019 17:43
@juergenhoetzel juergenhoetzel self-requested a review March 10, 2019 17:43
@juergenhoetzel
Copy link
Collaborator

Thanks for working on this 👍

FSI hangs when trying to complete an invalid prefix:

open System.X<TAB>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants