-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After using #r on a non-existent .dll, creating that .dll requires document change to update diagnostics #1808
Comments
Here are some notes about the old implementation that has been lost
These fixes are also crucial for correctly updating intellisense information in response to changes in dependent files. Separately
|
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. |
Agreed. |
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 |
Prior to this, we never update the compiler options stored for scripts. This means that as you add #r or #load the compilation options aren't updated. This PR updates the options in the semantic analysis phase. We can't update them on every request for options because it is too expensive. This fixes some aspects of #1808 but the underlying problem of not reacting to file update events in dependencies is not fixed.
you can request projects or documents to be re-checked by importing IDiagnosticsAnalyzerService and calling |
@vladima Thanks!! |
@vladima @OmarTawfik @brettfo In the old F# Language Service code (actually FSharp.LanguageService.Base, in C#) we implemented our own
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 We don't explicitly implement thanks |
I guess something like this might work (browser compiled solution, might contain open System.ComponentModel.Composition
open Microsoft.VisualStudio.Editor
open Microsoft.VisualStudio.Utilities
open Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
open Microsoft.CodeAnalysis.Diagnostics
[<ContentType(FSharpCommonConstants.FSharpContentTypeName)>]
[<Export(typeof<IVsTextViewCreationListener>)>]
type FSharpTextViewCreationListener
[<ImportingConstructor>]
(
textViewAdapter: IVsEditorAdaptersFactoryService,
workspace: VisualStudioWorkspaceImpl,
analyzerService: IDiagnosticAnalyzerService
) =
interface IVsTextViewCreationListener with
member this.VsTextViewCreated(textView) =
let wpfTextView = textViewAdapter.GetWpfTextView(textView)
match wpfTextView.TextBuffer.Properties.TryGetProperty<ITextDocument>(typeof<ITextDocument>) with
| true, textDocument ->
let filePath = textDocument.FilePath
let onGotFocus = new EventHandler(fun _ _ ->
analyzerService.Reanalyze(workspace, projectIds = null, documentIds = workspace.CurrentSolution.GetDocumentIdsWithFilePath(filePath))
)
let rec onViewClosed = new EventHandler(fun _ _ ->
wpfTextView.GotAggregateFocus.RemoveHandler(onGotFocus)
wpfTextView.Closed.RemoveHandler(onViewClosed)
)
wpfTextView.GotAggregateFocus.AddHandler(onGotFocus)
wpfTextView.Closed.AddHandler(onViewClosed)
| _ -> () |
Roslyn already has a service that tracks the active document, and in theory kicks of re-analysis through the Diagnostic analyzer. @heejaechang - can you point us to that code? |
does F# do error reporting based on roslyn diagnostic service, then it does all dependency checking and priority queue on changes and etc. |
these make sure document that has focus get processed first and then opened files and then modified files and etc. http://source.roslyn.io/#Microsoft.CodeAnalysis.Features/SolutionCrawler/WorkCoordinator.HighPriorityProcessor.cs,70 |
it sounds like F# need to abstract this out - http://source.roslyn.io/#Microsoft.CodeAnalysis.Features/SolutionCrawler/WorkCoordinator.SemanticChangeProcessor.cs,32 and make it to enqueue right set of work items to propagate semantic changes for F#. this doesn't do anything for F# I believe because F# doesn't actually use roslyn's semantic model and current implementation only understand how to propagate semantic changes for ones that provide roslyn's semantic model. |
This fixes a large chunk of #1808. I've tested it by hand. The build still doesn't react to files coming/going in DependencyFiles. I'll adjust the description in #1808 to make the cases distinct. Basically F# has an analysis engine which tells the UI when to do "foreground" rechecks of files because the checking state has changed. This reacts to those events. See https://fsharp.github.io/FSharp.Compiler.Service/queue.html for some info. When the UI gets the focus on a document, it should also notify the F# engine to start checking that document * fix tests * Fix bridge between backgronud builders * fix test
@vladima Thanks for your code, it worked well, please see PR |
…t#1906) This fixes a large chunk of dotnet#1808. I've tested it by hand. The build still doesn't react to files coming/going in DependencyFiles. I'll adjust the description in dotnet#1808 to make the cases distinct. Basically F# has an analysis engine which tells the UI when to do "foreground" rechecks of files because the checking state has changed. This reacts to those events. See https://fsharp.github.io/FSharp.Compiler.Service/queue.html for some info. When the UI gets the focus on a document, it should also notify the F# engine to start checking that document * fix tests * Fix bridge between backgronud builders * fix test
@dsyme Is it safe to close this with your PR? |
No, there is a still a case of propagating changes even when there's been no change in focus to "kick things off" , but files have come/gone from disk. Basically I believe the F# IncrementalBuilder will correctly notice all dependent file changes if activated to run. But we are relying on regaining the focus to prompt it to run at all. But this problem is much less severe after the PR |
@heejaechang Yes, but what I'm wondering is whether Roslyn actually includes a file tracker - e.g. does it react to on-disk file change events for referenced DLLs (e.g. not including cross-project references, which let's assume are handled in-memory). I haven't checked the Roslyn source code, it's just a general question In VS2015 the Visual F# Tools used to install Visual Studio file change event listeners as described here : #1808 (comment). Right now in VS2017 |
Yes see |
@Pilchie thanks. A couple of questions
|
It should (eventually) result in a WorkspaceChanged event with a project updated. I'm not sure which Note that C# also has |
Oh, hey, look at dotnet/roslyn#21964. Maybe we don't handle it properly for C# either. |
Prior to this, we never update the compiler options stored for scripts. This means that as you add #r or #load the compilation options aren't updated. This PR updates the options in the semantic analysis phase. We can't update them on every request for options because it is too expensive. This fixes some aspects of dotnet#1808 but the underlying problem of not reacting to file update events in dependencies is not fixed.
…t#1906) This fixes a large chunk of dotnet#1808. I've tested it by hand. The build still doesn't react to files coming/going in DependencyFiles. I'll adjust the description in dotnet#1808 to make the cases distinct. Basically F# has an analysis engine which tells the UI when to do "foreground" rechecks of files because the checking state has changed. This reacts to those events. See https://fsharp.github.io/FSharp.Compiler.Service/queue.html for some info. When the UI gets the focus on a document, it should also notify the F# engine to start checking that document * fix tests * Fix bridge between backgronud builders * fix test
I'm closing this very old issue - @TIHan implemented this correctly AFAIU |
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#load
should disappearAssume 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
script1.fsx
with this content and save it to an empty directory.You will see a red-squiggly on
script2.fsx
Now create an empty
script2.fsx
using VS or any other tool.Expected: the red-squiggly should disappear in
script1.fsx
when you return to that file (without making any edits toscript1.fsx
)Now edit
script2.fsx
using so there is an error in the file. e.g. the contentsSave the file and go back to the
script1.fsx
window.Expected: the red-squiggly should re-appear in
script1.fsx
when you return to that file (without making any edits toscript1.fsx
)Now edit
script2.fsx
to clear the error and save the file. Go back to thescript1.fsx
window.Expected: the red-squiggly should disappear from
script1.fsx
when 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 editscript1.fsx
(which has the effect of forcing a re-check of the file)The text was updated successfully, but these errors were encountered: