fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Why types generated for Intellisense are not the same as types generated during compilation? #221

Closed object closed 6 years ago

object commented 6 years ago

This is more of a question rather than issue report, and if you scroll down this thread (https://github.com/fsprojects/SQLProvider/issues/178) you should get the idea about why this question arose. I will summarize it in short here:

  1. We are trying to add offline support to SQLProvider, so developers can cache a database schema, store it in a file and be able to compile the project even when the database is not available.

  2. We have a branch with experimental version (https://github.com/object/SQLProvider/tree/schema_cache) that mostly works. However, we try not to cache the schema for the whole database that may be rather big but only save definitions referenced in the scope of the current project/solution. So everytime a query references some database objects, we expand schema cache with them. Here's where things don't work as we hoped.

  3. If I save the schema cache using new design-time method SaveContextSchema, then the schema is saved only for the scope of the current file. If a solution has other files with queries that reference different database owners/schemas, they are not saved. So if I bring the database offline and try to compile the solution using saved schema cache, compiler will complain about database objects referenced in other files. If I list all queries used in a solution in a single file, then everything is fine.

  4. What is strange however is that even when compilation fails, Intellisense still works for queries that reference objects that don't satisfy the compiler, i.e. if I hover a cursor over a query (that causes compiler error), VS Intellisense shows me correct object definition and type. So I don't see any highlighted errors in the code editor like there are no errors. But I see them in the Output windows.

So I wonder what's the difference in generated types resolution between VS Intellisense and the F# compiler. And how to make generated types to cover the scope of the whole solution.

gibranrosa commented 6 years ago

Hi @object ! Only to make more clear for people outside the SQLProvider group, where you say "generated types", actually is "provided types", since the types are erased after compilation.

object commented 6 years ago

Yes, thank you for the correction. It's provided types indeed.

object commented 6 years ago

Installed latest VS update and can no longer reproduce the issue, so I am closing it.