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

Handle CSProj files that are not C# projects that #1181

Merged
merged 3 commits into from
May 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/OmniSharp.MSBuild/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public ProjectToUpdate(string filePath, bool allowAutoRestore)
private readonly MetadataFileReferenceCache _metadataFileReferenceCache;
private readonly PackageDependencyChecker _packageDependencyChecker;
private readonly ProjectFileInfoCollection _projectFiles;
private readonly HashSet<string> _failedToLoadProjectFiles;
private readonly ProjectLoader _projectLoader;
private readonly OmniSharpWorkspace _workspace;

Expand All @@ -61,6 +62,7 @@ public ProjectManager(ILoggerFactory loggerFactory, IEventEmitter eventEmitter,
_metadataFileReferenceCache = metadataFileReferenceCache;
_packageDependencyChecker = packageDependencyChecker;
_projectFiles = new ProjectFileInfoCollection();
_failedToLoadProjectFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
_projectLoader = projectLoader;
_workspace = workspace;

Expand Down Expand Up @@ -148,14 +150,25 @@ private void ProcessQueue(CancellationToken cancellationToken)
projectList.Add(currentProject);

// update or add project
_failedToLoadProjectFiles.Remove(currentProject.FilePath);
if (_projectFiles.TryGetValue(currentProject.FilePath, out var projectFileInfo))
{
projectFileInfo = ReloadProject(projectFileInfo);
if (projectFileInfo == null)
{
_failedToLoadProjectFiles.Add(currentProject.FilePath);
continue;
}
_projectFiles[currentProject.FilePath] = projectFileInfo;
}
else
{
projectFileInfo = LoadProject(currentProject.FilePath);
if (projectFileInfo == null)
{
_failedToLoadProjectFiles.Add(currentProject.FilePath);
continue;
}
AddProject(projectFileInfo);
}
}
Expand Down Expand Up @@ -193,16 +206,22 @@ private ProjectFileInfo LoadOrReloadProject(string projectFilePath, Func<(Projec
_logger.LogInformation($"Loading project: {projectFilePath}");

ProjectFileInfo projectFileInfo;
ImmutableArray<MSBuildDiagnostic> diagnostics;

try
{
ImmutableArray<MSBuildDiagnostic> diagnostics;
(projectFileInfo, diagnostics) = loadFunc();

if (projectFileInfo == null)
if (projectFileInfo != null)
{
_logger.LogInformation($"Successfully loaded project file '{projectFilePath}'.");
}
else
{
_logger.LogWarning($"Failed to load project file '{projectFilePath}'.");
}

_eventEmitter.MSBuildProjectDiagnostics(projectFilePath, diagnostics);
}
catch (Exception ex)
{
Expand All @@ -211,13 +230,12 @@ private ProjectFileInfo LoadOrReloadProject(string projectFilePath, Func<(Projec
projectFileInfo = null;
}

_eventEmitter.MSBuildProjectDiagnostics(projectFilePath, diagnostics);

return projectFileInfo;
}

private bool RemoveProject(string projectFilePath)
{
_failedToLoadProjectFiles.Remove(projectFilePath);
if (!_projectFiles.TryGetValue(projectFilePath, out var projectFileInfo))
{
return false;
Expand Down Expand Up @@ -406,6 +424,12 @@ private void UpdateProjectReferences(Project project, ImmutableArray<string> pro

foreach (var projectReferencePath in projectReferencePaths)
{
if (_failedToLoadProjectFiles.Contains(projectReferencePath))
{
_logger.LogWarning($"Ignoring previously failed to load project '{projectReferencePath}' referenced by '{project.Name}'.");
continue;
}

if (!_projectFiles.TryGetValue(projectReferencePath, out var referencedProject))
{
if (File.Exists(projectReferencePath) &&
Expand Down