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

Respect MSBuild globs after initial project load #1841

Merged
merged 17 commits into from
Jul 29, 2020

Conversation

SirIntruder
Copy link
Contributor

Currently, Omnisharp often glitches randomly when new documents are added, or projects get restored (which triggers "FileAdded" events under the hood)

The core issue is that the way MSBuild resolves "which path belongs to which project" can get much more complicated than what omnisharp's crude heuristic can handle. So everything is fine on initial project load, but subsequential changes cause errors.

#1704 lists a lot of connected issues. I've tried to pull this PR and test it, but it turns out:

  • MSBuild globs are very specific and complicated, so strings in "DefaultExcludes" can't be trivially used to check file paths.
  • MSBuild allows for many different ways to modify inclusion rules, besides default excludes

What we really need is to have a way to ask MSBuild "Should this file be in this project?". The closest thing I've found to that is MSBuild's GetAllGlobs() method. So this PR proposes storing a list of MSBuild glob objects directly from MSBuild project, and using them to match new files, instead of using any heuristics.

@leandroslc
Copy link

Great 😄. I didn't know about GetAllGlobs(). It is really a much better solution than mine. In the meantime I was trying to hook an event to trigger a design time build to just update the source files, but I was unsure of how to do it properly.

I tested your solution and it worked fine for me. If this is accepted I can close my PR.

Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

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

Waiting on some comments from some others as well, but I like it!

Only one minor question from me.

@@ -187,6 +192,7 @@ private ProjectData()
AnalyzerConfigFiles = analyzerConfigFiles.EmptyIfDefault();
ReferenceAliases = referenceAliases;
ProjectReferenceAliases = projectReferenceAliases;
FileInclusionGlobs = fileInclusionGlobs;
}

public static ProjectData Create(MSB.Evaluation.Project project)
Copy link
Member

Choose a reason for hiding this comment

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

Would there be any benefit in including the globs as part of the data returned by this method as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late reply! I've investigated a bit, and it seems that this codepath is used when solution contains projects outside the target workspace folder. Since they do get added to the workspace, it's probably worth a fix

@JoeRobich
Copy link
Member

What we really need is to have a way to ask MSBuild "Should this file be in this project?". The closest thing I've found to that is MSBuild's GetAllGlobs() method.

We use GetAllGlobs for this same purpose. =)

Copy link
Member

@filipw filipw left a comment

Choose a reason for hiding this comment

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

thanks a lot, I think this is definitely an improvement for us

@filipw
Copy link
Member

filipw commented Jul 29, 2020

@SirIntruder would you mind resolving conflicts - looks like a merge caused it to no longer build

@david-driscoll
Copy link
Member

I may have broken this one too trying to resolve conflicts. I think I'll pull this down tonight and get it working.

@david-driscoll
Copy link
Member

I've fixed the build error, I'll swing back and check to make sure the build passed later

@david-driscoll david-driscoll merged commit 1d552c5 into OmniSharp:master Jul 29, 2020
@david-driscoll
Copy link
Member

Thanks @SirIntruder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants