fsharp / emacs-fsharp-mode

F# Emacs mode
Apache License 2.0
205 stars 62 forks source link

completion for inferior-fsharp? #184

Open ghost opened 5 years ago

ghost commented 5 years ago

Is it possible to add tab completion for inferior-fsharp, just like inferior-python or utop?

juergenhoetzel commented 5 years ago

Is it possible to add tab completion for inferior-fsharp, just like inferior-python or utop?

Yes, inferior-python rebinds TAB to interact with the inferior process (normally TAB isn't sent to the process. I need to investigate inferior-python internals: Pull requests are always appreciated :smile: .

jdodds commented 5 years ago

Yes, inferior-python rebinds TAB to interact with the inferior process (normally TAB isn't sent to the process. I need to investigate inferior-python internals:

So what they do is use readline.set_completer and comint-redirect-ish functions to grab completions from the inferior process and then show them to the user of the REPL. Comint basically assumes everything is line-based so the best case scenario involves a bit of an awkward dance when you want to communicate with the underlying process without sending newlines.

I've made a little bit of progress on tab completion for inferior-fsharp but it's got a long way to go. I'm not familiar enough with fsharp to see the direct path to instrumenting fsi or it's completion in a similar way to python-mode and am also not familiar enough with comint-derived mode writing and process filters in general 🙃

Are we OK with longer-lived WIP PRs here? I'm happy to to provide a starting point for right now and get some eyes/feedback on things while getting a more complete set of functionality if so.

juergenhoetzel commented 5 years ago

Are we OK with longer-lived WIP PRs here? I'm happy to to provide a starting point for right now and get some eyes/feedback on things while getting a more complete set of functionality if so.

Thanks a lot for for your research: I would love to see a (WIP) PR and help out!

iNecas commented 5 years ago

I was looking a bit into how IFsharp is doing the the autocompletion (https://github.com/fsprojects/IfSharp/blob/74e8ec47f9f3a5a7babb54b463d648e94bdfe813/src/IfSharp.Kernel/Evaluation.fs#L159) and it seems the way to go would be to get an access to Microsoft.FSharp.Compiler.Interactive.Shell.FsiEvaluationSession.

I have not found a way how to do it from inside of fsharpi, so it rather seems we would need to create a wrapper script around the FsiEvaluationSessions, that would expose additional reflection functionality that we could use. Seems like this is the right resource that could help moving this effort forward https://fsharp.github.io/FSharp.Compiler.Service/interactive.html