GithubHelp home page GithubHelp logo

betterfsi's Introduction

BetterFSI

A utility script for improving the F# Interactive experience, specially when working with multi-file scripts. For Visual Studio.

The Concept

Entering code directly in the FSI REPL is not usual practice because it is hard to keep track of what has been sent and in what order. Lack of syntax highliting and intellisense does not help either. Also as the code scrolls up it gets lost and it becomes difficult to fetch and maintain. Only the simplest tasks can be done this way.

It is then a good idea to maintain the code in FSX file(s) and from there send it to the REPL. This involves using CTRL-A a lot to select the whole file and then sending it to the FSI. This is not difficult but as the code grows and is done repeatedly it becomes less comfortable because of all the scrolling back. When several files are involved the task becomes rather cumbersome.

The purpose of this script is to facilitate and automate this task. BetterFSI keeps track of file dependencies and automatically refreshes the code in the REPL as needed.

Separating Code and Invocation

Working with scripts sometimes involves creating actual code and then calling it with specific parameters. As you make changes to the code and send them to the REPL you may not want it to execute all the calls every time because they may be slow, have side effects or there could be many which are innecessary. One way of dealing with this is to select only the part of code that you want to send but this is even harder than selecting all with CTRL-A.

A good idea then is to keep the calls commented out between (* *), that way they can be sent together with the code without actually executing them. Then when they need to be invoked it is easy to send just the ones needed with a couple of keystrokes or mouse clicks.

That is the way BetterFSI is intended to be used.

Usage:

  • Place BetterFSI.fsx among your script files.
  • Add the following comment somewhere in your own script file(s):
(*          
(*keep*)#load "BetterFSI.fsx"  // <<<==== Execute first in F# Interactive
Do __SOURCE_FILE__ __LINE__ //
Do __SOURCE_FILE__ __LINE__ //   sprintf "Hello %s" System.Windows.Forms.SystemInformation.UserName |> BetterFSI.Copy 
Do __SOURCE_FILE__ __LINE__ //   BetterFSI.Paste()
Do __SOURCE_FILE__ __LINE__ //   BetterFSI.Paste().[..6]
Do __SOURCE_FILE__ __LINE__ //   let f = new System.Windows.Forms.Form() ;; f.Text <- BetterFSI.Paste() ;; f.ShowDialog()
Do __SOURCE_FILE__ __LINE__ //
*)
  • Execute the #load line once to activate the script.
  • Put your calls after the Do __SOURCE_FILE__ __LINE__ //
  • Execute one (or several) whole line with Right-Click Execute in Interactive

When any of your files changes, they will be reloaded automaticaly just before executing your command.

Caveats:

  • It uses SendKeys so it is better to use the mouse than the shortcut as they keystrokes sometimes may interfere and produce undesirable results. Surely there must be a better way of implementing this as a VS extension.
  • It works only for Visual Studio

Enjoy!

betterfsi's People

Contributors

amieres avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.