Problems with the VS SDK

It looks this will not be as easy as I expected to use F# for the Visual Studio plugin (based on IronStudio). It is not just terribly slow, but it looks like the template for creating VS studio language integration is using some parts with dependent types. Yes, I know it might be only my limitations not seeing an obvious solution to this, but it looks like the project classes the ToolsPackage class and the SolutionAdviser classes are too interdependent... I have to think how should I solve this problem.


Not so nice features of F#

Negative Numbers

Given the following code it does not compile:
> let func = fun ()-> 3;;

val func : unit -> int
> func() -1;;

func() -1;;

stdin(5,1): error FS0003: This value is not a function and cannot be applied

Pretty annoying error message, as the problem is with the -1 part, not the func(). (You have to put a space between - and 1.)

I was not able to specify mutually dependent types with attributes on the second class.


New Eureqa client

Today, I have created a new Eureqa client, this time a .NET. Hopefully it is not full with bugs.
It is a pity that there are no documentation comments in the Eureqa API. I guess it is harder for the API users to find out what are the possible options.



Today I have finished the port of the sample Ook language extension from C# to F#. It was interesting, as I was learning both the Visual Studio extension mechanisms, and also F#. The only problem remaining, that the Visual Studio crashes when I try to edit (add a module to the vsixmanifest file) with the VSIX editor.

It was not too easy task, some of the problems:
  • Implementing an interface with events:

    let tagsChangedHandlers = new ResizeArray<EventHandler<SnapshotSpanEventArgs>>()
    interface ITagger<ooktokentag> with
    member this.add_TagsChanged v = tagsChangedHandlers.Add v |> ignore
    member this.remove_TagsChanged v = tagsChangedHandlers.Remove v |> ignore

  • Properly setting up the project file was not so easy either (at least I now know what are the ProjectTypeGuids for C#, F# and the VS SDK)
  • I had to move the TemplateQuickInfoControllerProvider and TemplateQuickInfoController classes to the same file (I am not sure how to do this if both classes have attributes)
  • There are no implicit conversions
  • One of the most annoying thing was when there was an error in my F# code and when I tried to correct it and saved the file the Visual Studio just crashed
  • You have to use refs instead of mutable variables if you would like to get the result from a method (not so surprising, maybe I should read fully the Expert F# 2.0 before further coding)
  • I have not found a simple way to emulate early return from methods
  • It was pretty annoying to find that the unbox gives an int by default, which is not so much fun if you want a uint16, this solved the problem:

    member private this.GetTypeChar(pvaIn : IntPtr) : char =
    let x : uint16 = unbox(Marshal.GetObjectForNativeVariant(pvaIn))

In general it was not so bad. I really liked the way it pushed me to make things more independent and be aware of the dependencies. I think because of the legacy API it is not a perfect fit for F# (and to be honest I have not transformed to a really functional solution), but everything can be worked around.

Although the F# Visual Studio plugin is terribly slow... I was typing and typing when finally I got back the cursor and the code completion and other things. I hope this was just because of an extension for Visual Studio, although except the F# refactor those useful, so those will stay.