Description
F# files are not re-checked when changes happen to dependency files such as #load-ed scripts or referenced DLLs.
This greatly affects the usability of the Visual F# Tools as the user has no idea what state the type checking is in, and has to do artificial edits on their source code to clear errors
This is a regression to functionality that has been working since VS2008
For each F# source file (in or out of a project, whether script or otherwise), the compiler service provides a list of files in the DependencyFiles property. These are DLLs and source files. The IDE should install file watchers for these files, and if a change in a watched file is detected then a re-check of the file should be done, resulting in a refresh of the errors
For example,
-
if an error is corrected in a file referenced by a
#load, and that file is saved to disk, then the red-squiggly on the#loadshould disappear -
Assume one project references another (e.g. fsc references FSharp.Compiler). If the DLLs for the referenced did not exist on disk, then there will be red-squigglies in the project. When the referenced project gets built, DLLs are created by a build. These DLLs will be in the dependency files. When the files appear on disk, a re-check should occur, and the red squigglies should be cleared.
Repro steps
- There are many repros. For example, when scripting, create a
script1.fsxwith this content and save it to an empty directory.
#load "script2.fsx"
System.Console.WriteLine("Hello")
You will see a red-squiggly on script2.fsx
-
Now create an empty
script2.fsxusing VS or any other tool.Expected: the red-squiggly should disappear in
script1.fsxwhen you return to that file (without making any edits toscript1.fsx) -
Now edit
script2.fsxusing so there is an error in the file. e.g. the contentslet fail = 1 + 1.0Save the file and go back to the
script1.fsxwindow.Expected: the red-squiggly should re-appear in
script1.fsxwhen you return to that file (without making any edits toscript1.fsx) -
Now edit
script2.fsxto clear the error and save the file. Go back to thescript1.fsxwindow.Expected: the red-squiggly should disappear from
script1.fsxwhen you return to that file (without making any edits toscript1.fsx)
Similarly for cross-project references to DLLs in project builds
Actual behavior
In all the cases above, the red-squigglies are not cleared in script1.fsx until you actually edit script1.fsx (which has the effect of forcing a re-check of the file)
Activity
cartermp commentedon Nov 22, 2016
Thanks for the detailed bug, @dsyme. @brettfo and @Pilchie, I think this one should be high on our list of bugs to fix right now.
dsyme commentedon Nov 22, 2016
Here are some notes about the old implementation that has been lost
Assume file B has been checked and has DependencyFiles A1 and A2. (Note A1 and A2 might not yet exist)
In the old language service code, the DependencyFiles for B were consumed here after checking
This used the Visual Studio file watching facilities here to install watchers for A1 and A2. (We had to use the VIsual Studio file watching for technical reasons I never understood)
When a file change to A1 or A2 was detected by the VS file watching facilitieswe called NotifyFileTypeCheckStateIsDirty which stored the file away in
dirtyForTypeCheckFilesWhen a file creation to A1 or A2 was detected then we called InvalidateConfiguration to notify the F# compiler service that the whole project should be re-checked. This corresponds to creation of one of the source files of a project, or creation of one of the DLLs in a project.
IIRC we had to be careful not to listen to DLL deletions since that gives the very annoying behaviour of a "clean" build creating lots of red-squiggly errors
OnIdle processing then marked any matching files in the RunningDocumentTable as if they had been edited. THis would have the effect of marking file B as "edited" from the point of view of the language service, and it would be rechecked, and the errors cleared.
These fixes are also crucial for correctly updating intellisense information in response to changes in dependent files.
Separately
NotifyFileTypeCheckStateIsDIrty is also called when a BeforeBackgroundFileCheck event is raised by the background checker This indicates that refreshed background state is available ready to do an updated check of the file. This is crucial to ensure clearing of foreground errors and updates to intellisense information in response to progress in the background build.
It is also worth reviewing whether
CheckProjectInBackgroundis ever being called in the new language service implementation In the old language service, this was be called each time you switched to a file in a project in Visual Studio (or equally to a script). This would have the effect of kicking off the background project build for the project, causingBeforeBackgroundFileCheckevents to be raised file by file as the background build progressed through the files. Without calling CheckProjectInBackground you might not get proper updates in multi-project solutions.dsyme commentedon Nov 22, 2016
Note the model described above is not ideal, especially for multi-project solutions (where you shouldn't have to even have referenced DLLs on-disk to check a project). Further, the implementation shouldn't need to do a "foreground" check to refresh errors - they should be pushed from the background build, which should utilize the active, unsaved content of buffers rather than files on disk. The F# Compiler service has various updates which make it possible to do a better job along these lines.
But in VS2017 RC we have no updates in response to file events at all.... So let's first get back to parity and then progress things.
cartermp commentedon Nov 22, 2016
Agreed.
dsyme commentedon Nov 27, 2016
I'm having a hell of a hard time understanding how to implement this within the Roslyn framework.
One thing we need is the equivalent of this
That is, when Idle we want to run through a set of documents and "act as if the document has changed" for the purposes of Roslyn semantic analysis.
Another thing we need is a place where we can register and store VS file tracking handlers.
I hacked about with this sort of thing:
I'll definitely need help for this
Get correct options for scripts (#1865)
vladima commentedon Nov 29, 2016
you can request projects or documents to be re-checked by importing IDiagnosticsAnalyzerService and calling
Reanalyzedsyme commentedon Nov 29, 2016
@vladima Thanks!!
dsyme commentedon Nov 29, 2016
@vladima @OmarTawfik @brettfo In the old F# Language Service code (actually FSharp.LanguageService.Base, in C#) we implemented our own
ViewFiltertype that includes an implementation ofIVsTextViewEventsincluding an action when the window got the focus:Do you know what the equivalent should be in the Roslynized code?
The context is that we basically want to kick off a call to
checker.CheckProjectInBackground()when a file in a project gets the focus. This will then make sure all errors eventually get updated.We don't explicitly implement
IVsTextViewEventsin the new code.thanks
don
vladima commentedon Nov 30, 2016
I guess something like this might work (browser compiled solution, might contain
peanutserrors)36 remaining items
[-]After using #load on an unresolved .dll, resolving that .dll requires mouseover or document change to update diagnostics[/-][+]After using #r on a non-existent .dll, creating that .dll requires document change to update diagnostics[/+]Get correct options for scripts (dotnet#1865)
Refresh the check of files when notified by F# analysis engine (dotne…
dsyme commentedon Apr 5, 2022
I'm closing this very old issue - @TIHan implemented this correctly AFAIU