F# IntelliSense Improvements in Visual Studio 11 Beta

F# IntelliSense Improvements in Visual Studio 11 Beta

  • Comments 3

IntelliSense is the identifier auto-completion facility in Visual Studio.  As a developer, IntelliSense is critical to my productivity, as it allows me to easily work with thousands of functions from different namespaces and classes without having to constantly leave the editor to consult API documentation.  In this blog post, I’ll show how the improvements to F# IntelliSense in Visual Studio 11 Beta will make day-to-day programming with F# easier and more enjoyable, and how F# IntelliSense, coupled with the new language feature of Type Providers, shapes the future of the experience developers have with all the world’s data.

 

Improving Day-to-Day IntelliSense

When you think of IntelliSense, you may just think of an example like:

image

 

 

You can bring up a completion list explicitly by pressing the keyboard shortcut Ctrl-Space, or a completion list will appear automatically just by “dotting into” an object.  The list of members appears, and the highlighted member shows more detail about that member.  If you’re a developer, that is all familiar.

 

Smart Filtering

We’ve made a number of refinements to the F# IntelliSense experience in Visual Studio 11 that will really impact your productivity.  First, the completion list now does “smart” choosing and filtering when you type a mixed-case partial identifier.  For example, if I want “Console.WriteLine,” rather than arrow down through all the completions on “Console”:

image

 

 

or type a fully unique prefix like “Console.WriteL”:

image

 

 

I can now type “Console.WL”:

image

 

 

and quickly select WriteLine from the filtered list that contains only those identifiers with a capital “W” and a capital “L.”

This “smart filtering” feature can have a huge impact when working with certain APIs.  What was that Form color change event I wanted again?

image

 

 

There are about 300 entries in that completion list; good luck scrolling through all those to find what you want.  But if I know it was some kind of “changed” event, then I can type two more characters “Ch”:

image

 

…and now  the filtering shows only methods with “Ch” in them, which is mostly the “XXXChanged” events.

 

And if instead I type “CoCh”:

image

 

Oh, right, it was “ForeColorChanged” I was looking for.  “Smart-filtering” the completion list makes it dramatically easier to find the API you’re looking for.

 

Parameter Help

F# now supports parameter help while you type.  You can explicitly bring it up by pressing Ctrl-Shift-Space.  For example, if I don’t recall what one particular exotic overload of String.Compare does, I can bring up the parameter help:

image

 

 

to learn about all the parameters for that overload.  Note that my cursor was before the “1," the fourth parameter, and so the 4th parameter is bolded in the list.  Parameter help automatically pops up when you type the open parenthesis:

image

 

 

and tracks parameters and selects overloads as you type more parameters:

image

 

 

In F# you can even use Ctrl-Shift-Space to get parameter help for one-argument functions that have no parentheses:

image

 

 

Parameter help makes it easy to select the right overload API and understand arguments without breaking the flow of typing code in the editor.

 

Contextual Filtering

F# IntelliSense now has some contextual filtering based on the language construct you are using.  For example, there are tons of completions under “System”:

image

 

 

but if I am opening a namespace in an “open” declaration:

image

 

 

F# will automatically filter the list down to just the namespaces and modules, since those are the only things that make sense in this context.  Or if I’m updating a record, and bring up identifier completion suggestions with Ctrl-Space:

image

 

 

the list only contains the record field names that are valid at that location.  There is still much more that can be done here, but F# continues to improve its ability to automatically filter completion lists based on context.

 

IntelliSense with Type Providers and Queries

Though the aforementioned improvements to F# IntelliSense impact nearly every line of code you write, perhaps the most compelling thing is how IntelliSense interacts with the new F# language feature of Type Providers. Type Providers are assemblies you can reference that read an external schematized data source (like a database or web service) and surface it as though it were normal types in your F# program.

 

Good “Tomato” Movies?

 

When I browse into a data context with F# type providers, I see a few directions I can head:

image

 

 

“People” and “Genres” also seem like they may be interesting to explore at some point, but for the moment, I’m interested in their “Titles” catalog, which has info about lots of movies.  There is a lot of information available for each movie title:

image

 

 

Looking down this list, it seems that these two are the ones I need:

image

image

 

 

 

I note that “AverageRating” is a Nullable<float>, which my intuition makes sense of—they probably don’t have rating information for every title in their catalog, so some are null.  I’m not sure how to sort a nullable key, but once again IntelliSense comes to the rescue when I typed “sor” and pressed Ctrl-Space:

image

 

 

Yes, “sortByNullableDescending” is clearly what I need here to get the results in descending order by the “AverageRating” field.  So I craft the query that filters just the titles I am interested in, in sorted order, and print out the results.

This is tremendously easy for me; the only part I needed to do outside the Visual Studio editor was the original Bing search to find the URI of a data source that had the information I needed.  From there, I’m just typing code in the Visual Studio editor, using IntelliSense to steer me through all the new-to-me APIs.  I did not have to search the web for detailed API information to find out how to use their web service, how to craft requests or parse responses.  I did not have to use some kind of UI “wizard” interface to connect to the data source.  I did not have to explicitly invoke a code generation tool to generate .NET object model classes and add that code to my project.  I just pressed “dot”—and immediately I was able to explore the APIs to find the code I need to solve my problem.

I like to think that Type Providers turn IntelliSense into “Intelli-Dollars.” While there are perhaps a thousand classes in the .NET Framework, there are hundreds of thousands of schematized data types available for consumption in our information-rich world, available as web services, OData and RSS feeds, databases inside enterprises, in the Azure DataMarket, on your Sharepoint sites—the list goes on and on.  Type providers create a simple bridge to make all these information sources immediately available programmatically within your statically-typed F# programming environment, browseable via IntelliSense.  A world of data is at your fingertips with F#—grab Visual Studio 11 and glimpse the future of the developer experience in an information-rich world.

Summary

We’ve made a number of improvements to F# IntelliSense in Visual Studio 11.  Smart-filtering, parameter help, and contextual-filtering make everyday coding simpler and more productive.  Type Providers extend this rich IDE experience to the reach of all the data available around us.

 

Brian McNamara
Visual Studio F# Developer

 

Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post
  • Hi, great, congratulation to improvements!

    And what about other features, which we know from C# like find all references or highlighting all occurrences of identifier when staying with cursor on it, or regions ? What are plans? I am not much humble now, I know. ;-)

    Thanks

  • Please, no regions!

    I prefer not to sweep code under the carpet.

  • Just FYI for others that might end up trying out this code, Netflix killed their OData service (as I just found out when Intellisense said the type provider got a 404 error).

    error FS3033: The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: Error reading schema. The remote server returned an error: (404) Not Found.

    http://odata.netflix.com/

    ********

    Consistent with other changes Netflix is making to its Public API program, as of April 8th, 2013, this service is no longer available.

    ********

Page 1 of 1 (3 items)