-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use MSBuild globs to determine which file changes are relevant #75139
Conversation
dd6d49c
to
0ea7f75
Compare
0ea7f75
to
3cc1b19
Compare
new(projectDirectory, ".cs"), | ||
new(projectDirectory, ".cshtml"), | ||
new(projectDirectory, ".razor") | ||
new(_projectDirectory, ".cs"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we not watching for changes in non-Razor additional files, which might affect other source generators? How about resx files, etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are watching for changes for files we already know about in the solution elsewhere. This is attempting to look for added/removed files that we don't know about that we might need to reload the project for.
Yes - this file watcher has problems. Additions of files outside the project cone are not watched. Additions of other kinds of files are also not watched. However that is pre-existing and not directly the problem I'm trying to solve at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note - this code only applies to C# standalone (without Dev Kit).
@@ -57,7 +66,34 @@ public LoadedProject(ProjectSystemProject projectSystemProject, SolutionServices | |||
|
|||
private void FileChangedContext_FileChanged(object? sender, string filePath) | |||
{ | |||
NeedsReload?.Invoke(this, EventArgs.Empty); | |||
// If the project file itself changed, we almost certainly need to reload the project. | |||
if (string.Equals(filePath, _projectFilePath, StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we gonna get .csproj file change events if we didn't include .csproj in CreateContext?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we explicitly watch it here - https://github.com/dotnet/roslyn/pull/75139/files#diff-a22b4449b374ba36a2fddc35ae1e95fad8405e435bcdbd22ef1613f284d4c14cL55 (I should update that line to use the new var)
Resolves dotnet/vscode-csharp#6985
The approach I took was to serialize glob information over to the host process, and use MS.Extensions.FileGlobbing to match files against the globs.
Unfortunately it is quite difficult to get full fidelity matching - ideally we would be able to call
IsMatch
on aCompositeGlob
built from all the project globs - however we do not want to load MSBuild in the host process.Instead, we serialize the set of
Includes
,Excludes
, andRemoves
from the evaluatedGlobResult
. This roughly should be the correct set of globs and matches how CPS recreates globs, see https://devdiv.visualstudio.com/DevDiv/_git/CPS?path=/src/Microsoft.VisualStudio.ProjectSystem/Build/MsBuildGlobFactory.cs&version=GBmain&line=34&lineEnd=35&lineStartColumn=1&lineEndColumn=1&lineStyle=plain&_a=contentsWe then match using the project directory as the relative directory (also matches CPS). However our matching is a bit simpler as we don't currently even get file watcher notifications for anything outside the project cone.