Skip to content
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

Merged
merged 3 commits into from
Sep 25, 2024

Conversation

dibarbet
Copy link
Member

@dibarbet dibarbet commented Sep 16, 2024

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 a CompositeGlob 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, and Removes from the evaluated GlobResult. 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=contents

We 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.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 16, 2024
@dibarbet dibarbet force-pushed the ignore_file_changes branch 3 times, most recently from dd6d49c to 0ea7f75 Compare September 19, 2024 17:45
new(projectDirectory, ".cs"),
new(projectDirectory, ".cshtml"),
new(projectDirectory, ".razor")
new(_projectDirectory, ".cs"),
Copy link
Member

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.?

Copy link
Member Author

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.

Copy link
Member Author

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))
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated code (WPF, *.g.cs files) triggers infinite textDocument/diagnostic loop
4 participants