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

Report to the client if the project being loaded is sdk style #2502

Merged
merged 2 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public static void ProjectInformation(this IEventEmitter emitter,
HashedString sdkVersion,
IEnumerable<HashedString> references,
IEnumerable<HashedString> fileExtensions,
IEnumerable<int> fileCounts)
IEnumerable<int> fileCounts,
bool sdkStyleProject)
{
var projectConfiguration = new ProjectConfigurationMessage()
{
Expand All @@ -66,7 +67,8 @@ public static void ProjectInformation(this IEventEmitter emitter,
SessionId = sessionId.Value,
References = references.Select(hashed => hashed.Value),
FileExtensions = fileExtensions.Select(hashed => hashed.Value),
FileCounts = fileCounts
FileCounts = fileCounts,
SdkStyleProject = sdkStyleProject
};

emitter.Emit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public class ProjectConfigurationMessage
public IEnumerable<string> References { get; set; }
public IEnumerable<string> FileExtensions { get; set; }
public IEnumerable<int> FileCounts { get; set; }
public bool SdkStyleProject { get; set; }
}
}
16 changes: 15 additions & 1 deletion src/OmniSharp.MSBuild/ProjectLoadListener.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Build.Execution;
Expand Down Expand Up @@ -51,14 +52,27 @@ public void ProjectLoaded(ProjectLoadedEventArgs args)
var hashedReferences = GetHashedReferences(args);
var (hashedFileExtensions, fileCounts) = GetUniqueHashedFileExtensionsAndCounts(args);

_eventEmitter.ProjectInformation(projectId, sessionId, (int)outputKind, projectCapabilities, targetFrameworks, sdkVersion, hashedReferences, hashedFileExtensions, fileCounts);
var sdkStyleProject = IsSdkStyleProject(args);
_eventEmitter.ProjectInformation(projectId, sessionId, (int)outputKind, projectCapabilities, targetFrameworks, sdkVersion, hashedReferences, hashedFileExtensions, fileCounts, sdkStyleProject);
}
catch (Exception ex)
{
_logger.LogError("Unexpected exception got thrown from project load listener: " + ex);
}
}

private static bool IsSdkStyleProject(ProjectLoadedEventArgs args)
{
// To see if a project is an SDK style project we check for either of two things
// 1. If it has a TargetFramework / TargetFrameworks property. This isn't fully complete
// as this property could come from a different props file
// 2. If it imports an SDK. This can be defined multiple ways in the project file, but
// we can look at the resolved imports after evaluation to see if any are SDK based.
bool hasTargetFrameworkProperty = args.Project.Properties.Any(property => property.Name is "TargetFramework" or "TargetFrameworks");
bool importsSdk = args.Project.Imports.Any(import => import.SdkResult != null);
return hasTargetFrameworkProperty || importsSdk;
}

private static (IEnumerable<HashedString> Extensions, IEnumerable<int> Counts) GetUniqueHashedFileExtensionsAndCounts(ProjectLoadedEventArgs args)
{
var contentFiles = args.ProjectInstance
Expand Down