Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellisense not working for F# type provider

I've created a simple type provider that I want to expose some pre-generated types in an assembly, as follows:

[<TypeProvider>]
type TestProvider() as this =
    inherit TypeProviderForNamespaces()
    let providedType = ProvidedTypeDefinition(Assembly.GetExecutingAssembly(), "Test", "TypeLib", None)
    do let assembly = Assembly.LoadFrom @"C:\Some\Long\Path\TestTypes.dll"
       // Get same problem with providedType.AddAssemblyTypesAsNestedTypesDelayed(),
       // which is what I really want to use
       providedType.AddMember(assembly.GetType("TestTypes.Circle"))
       this.AddNamespace("Test", [providedType])

I consume this provider from another project as follows:

// Circle member not showing up under TypeLib
type Circle = Test.TypeLib.Circle

let c = Circle()
c.Radius <- 4.
printfn "%f" c.Radius
System.Console.ReadKey() |> ignore

It compiles, runs, and works as expected, but for some reason the Circle doesn't show up in the Intellisense list for Test.TypeLib. Also when I hover over Circle it says A reference to type 'TestType.Circle' in assembly 'TestTypes' was found, but the type could not be found in that assembly.

What am I doing wrong?

UPDATE: As suggested by a Dmitry, I viewed the related question and downloaded the associated type provider that is trying to do something similar to what mine is doing. Unfortunately, on my machine that provider behaves the same as mine, i.e. it provides Intellisense for namespaces but not types. So I don't know if it could be something specific to my configuration or what.

like image 852
luksan Avatar asked Nov 10 '22 13:11

luksan


1 Answers

Well, it wasn't my code. It turns out that when I use the exact ProvidedTypes-head.fs contained in the linked example, then everything works like it should. However, when I use a different version, like the ProvidedTypes.fs from FSharp.Data, then it has the incorrect behavior. I'm not sure what the difference is between them that is causing the issue. I'm also not sure where to find the "official" version of the the file, if one indeed exists.

UPDATE: Looks like the official version is here.

like image 130
luksan Avatar answered Dec 20 '22 04:12

luksan