Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [2.0.15] - 2022-03-21

Integration:

- Improved project generation performance.
- Added support for keeping file/folder structure when working with external packages.
- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor.
  • Loading branch information
Unity Technologies committed Mar 21, 2022
1 parent fa2de33 commit b132c03
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 48 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Code Editor Package for Visual Studio

## [2.0.15] - 2022-03-21

Integration:

- Improved project generation performance.
- Added support for keeping file/folder structure when working with external packages.
- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor.



## [2.0.14] - 2022-01-14

Integration:
Expand Down
Binary file modified Editor/COMIntegration/Release/COMIntegration.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Editor/FileUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static string NormalizePathSeparators(this string path)
return path.Replace(string.Concat(WinSeparator, WinSeparator), WinSeparator.ToString());
}

public static string NormalizeWindowsToUnix(string path)
public static string NormalizeWindowsToUnix(this string path)
{
if (string.IsNullOrEmpty(path))
return path;
Expand Down
Binary file not shown.
74 changes: 52 additions & 22 deletions Editor/ProjectGeneration/ProjectGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public class ProjectGeneration : IGenerator

static readonly string[] k_ReimportSyncExtensions = { ".dll", ".asmdef" };

string[] m_ProjectSupportedExtensions = Array.Empty<string>();
string[] m_BuiltinSupportedExtensions = Array.Empty<string>();
HashSet<string> m_ProjectSupportedExtensions = new HashSet<string>();
HashSet<string> m_BuiltinSupportedExtensions = new HashSet<string>();

readonly string m_ProjectName;
readonly IAssemblyNameProvider m_AssemblyNameProvider;
Expand Down Expand Up @@ -217,8 +217,8 @@ public bool HasSolutionBeenGenerated()

private void SetupProjectSupportedExtensions()
{
m_ProjectSupportedExtensions = m_AssemblyNameProvider.ProjectSupportedExtensions;
m_BuiltinSupportedExtensions = EditorSettings.projectGenerationBuiltinExtensions;
m_ProjectSupportedExtensions = new HashSet<string>(m_AssemblyNameProvider.ProjectSupportedExtensions);
m_BuiltinSupportedExtensions = new HashSet<string>(EditorSettings.projectGenerationBuiltinExtensions);
}

private bool ShouldFileBePartOfSolution(string file)
Expand Down Expand Up @@ -246,37 +246,48 @@ private static string GetExtensionWithoutDot(string path)

public bool IsSupportedFile(string path)
{
var extension = GetExtensionWithoutDot(path);
return IsSupportedFile(path, out _);
}

private bool IsSupportedFile(string path, out string extensionWithoutDot)
{
extensionWithoutDot = GetExtensionWithoutDot(path);

// Dll's are not scripts but still need to be included
if (extension == "dll")
if (extensionWithoutDot == "dll")
return true;

if (extension == "asmdef")
if (extensionWithoutDot == "asmdef")
return true;

if (m_BuiltinSupportedExtensions.Contains(extension))
if (m_BuiltinSupportedExtensions.Contains(extensionWithoutDot))
return true;

if (m_ProjectSupportedExtensions.Contains(extension))
if (m_ProjectSupportedExtensions.Contains(extensionWithoutDot))
return true;

return false;
}


private static ScriptingLanguage ScriptingLanguageFor(Assembly assembly)
{
var files = assembly.sourceFiles;

if (files.Length == 0)
return ScriptingLanguage.None;

return ScriptingLanguageFor(files[0]);
return ScriptingLanguageForFile(files[0]);
}

internal static ScriptingLanguage ScriptingLanguageFor(string path)
internal static ScriptingLanguage ScriptingLanguageForExtension(string extensionWithoutDot)
{
return GetExtensionWithoutDot(path) == "cs" ? ScriptingLanguage.CSharp : ScriptingLanguage.None;
return extensionWithoutDot == "cs" ? ScriptingLanguage.CSharp : ScriptingLanguage.None;
}

internal static ScriptingLanguage ScriptingLanguageForFile(string path)
{
return ScriptingLanguageForExtension(GetExtensionWithoutDot(path));
}

public void GenerateAndWriteSolutionAndProjects()
Expand Down Expand Up @@ -336,7 +347,7 @@ private Dictionary<string, string> GenerateAllAssetProjectParts()
continue;
}

if (IsSupportedFile(asset) && ScriptingLanguage.None == ScriptingLanguageFor(asset))
if (IsSupportedFile(asset, out var extensionWithoutDot) && ScriptingLanguage.None == ScriptingLanguageForExtension(extensionWithoutDot))
{
// Find assembly the asset belongs to by adding script extension and using compilation pipeline.
var assemblyName = m_AssemblyNameProvider.GetAssemblyNameFromScriptPath(asset);
Expand All @@ -354,7 +365,7 @@ private Dictionary<string, string> GenerateAllAssetProjectParts()
stringBuilders[assemblyName] = projectBuilder;
}

projectBuilder.Append(" <None Include=\"").Append(EscapedRelativePathFor(asset)).Append("\" />").Append(k_WindowsNewline);
IncludeAsset(projectBuilder, "None", asset);
}
}

Expand All @@ -366,6 +377,26 @@ private Dictionary<string, string> GenerateAllAssetProjectParts()
return result;
}

private void IncludeAsset(StringBuilder builder, string tag, string asset)
{
var filename = EscapedRelativePathFor(asset, out var packageInfo);

builder.Append($" <{tag} Include=\"").Append(filename);
if (Path.IsPathRooted(filename) && packageInfo != null)
{
// We are outside the Unity project and using a package context
var linkPath = SkipPathPrefix(asset.NormalizePathSeparators(), packageInfo.assetPath.NormalizePathSeparators());

builder.Append("\">").Append(k_WindowsNewline);
builder.Append(" <Link>").Append(linkPath).Append("</Link>").Append(k_WindowsNewline);
builder.Append($" </{tag}>").Append(k_WindowsNewline);
}
else
{
builder.Append("\" />").Append(k_WindowsNewline);
}
}

private void SyncProject(
Assembly assembly,
Dictionary<string, string> allAssetsProjectParts,
Expand Down Expand Up @@ -479,17 +510,16 @@ private string ProjectText(Assembly assembly,
projectBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
foreach (string file in assembly.sourceFiles)
{
if (!IsSupportedFile(file))
if (!IsSupportedFile(file, out var extensionWithoutDot))
continue;

var extension = Path.GetExtension(file).ToLower();
var fullFile = EscapedRelativePathFor(file);
if (".dll" != extension)
if ("dll" != extensionWithoutDot)
{
projectBuilder.Append(" <Compile Include=\"").Append(fullFile).Append("\" />").Append(k_WindowsNewline);
IncludeAsset(projectBuilder, "Compile", file);
}
else
{
var fullFile = EscapedRelativePathFor(file, out _);
references.Add(fullFile);
}
}
Expand Down Expand Up @@ -564,7 +594,7 @@ private static string XmlEscape(string s)

private void AppendReference(string fullReference, StringBuilder projectBuilder)
{
var escapedFullPath = EscapedRelativePathFor(fullReference);
var escapedFullPath = EscapedRelativePathFor(fullReference, out _);
projectBuilder.Append(" <Reference Include=\"").Append(Path.GetFileNameWithoutExtension(escapedFullPath)).Append("\">").Append(k_WindowsNewline);
projectBuilder.Append(" <HintPath>").Append(escapedFullPath).Append("</HintPath>").Append(k_WindowsNewline);
projectBuilder.Append(" </Reference>").Append(k_WindowsNewline);
Expand Down Expand Up @@ -924,13 +954,13 @@ private string GetProjectActiveConfigurations(string projectGuid)
projectGuid);
}

private string EscapedRelativePathFor(string file)
private string EscapedRelativePathFor(string file, out UnityEditor.PackageManager.PackageInfo packageInfo)
{
var projectDir = ProjectDirectory.NormalizePathSeparators();
file = file.NormalizePathSeparators();
var path = SkipPathPrefix(file, projectDir);

var packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.Replace('\\', '/'));
packageInfo = m_AssemblyNameProvider.FindForAssetPath(path.NormalizeWindowsToUnix());
if (packageInfo != null)
{
// We have to normalize the path, because the PackageManagerRemapper assumes
Expand Down
27 changes: 6 additions & 21 deletions Editor/VisualStudioEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ private static IVisualStudioInstallation[] DiscoverInstallations()

internal static bool IsEnabled => CodeEditor.CurrentEditor is VisualStudioEditor && UnityInstallation.IsMainUnityEditorProcess;

// this one seems legacy and not used anymore
// keeping it for now given it is public, so we need a major bump to remove it
public void CreateIfDoesntExist()
{
if (!_generator.HasSolutionBeenGenerated())
Expand Down Expand Up @@ -260,7 +262,7 @@ private bool IsProjectGeneratedFor(string path, out ProjectGenerationFlag missin
return true;

// We only want to check for cs scripts
if (ProjectGeneration.ScriptingLanguageFor(path) != ScriptingLanguage.CSharp)
if (ProjectGeneration.ScriptingLanguageForFile(path) != ScriptingLanguage.CSharp)
return true;

// Even on windows, the package manager requires relative path + unix style separators for queries
Expand Down Expand Up @@ -357,31 +359,14 @@ bool OpenOSXApp(string path, int line, int column)
absolutePath = Path.GetFullPath(path);
}

string solution = GetOrGenerateSolutionFile(path);
var solution = GetOrGenerateSolutionFile(path);
return OpenVisualStudio(CodeEditor.CurrentEditorInstallation, solution, absolutePath, line);
}

private string GetOrGenerateSolutionFile(string path)
{
var solution = GetSolutionFile(path);
if (solution == "")
{
_generator.Sync();
solution = GetSolutionFile(path);
}

return solution;
}

string GetSolutionFile(string path)
{
var solutionFile = _generator.SolutionFile();
if (File.Exists(solutionFile))
{
return solutionFile;
}

return "";
_generator.Sync();
return _generator.SolutionFile();
}
}
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
"name": "com.unity.ide.visualstudio",
"displayName": "Visual Studio Editor",
"description": "Code editor integration for supporting Visual Studio as code editor for unity. Adds support for generating csproj files for intellisense purposes, auto discovery of installations, etc.",
"version": "2.0.14",
"version": "2.0.15",
"unity": "2019.4",
"unityRelease": "25f1",
"dependencies": {
"com.unity.test-framework": "1.1.9"
},
"relatedPackages": {
"com.unity.ide.visualstudio.tests": "2.0.14"
"com.unity.ide.visualstudio.tests": "2.0.15"
},
"upm": {
"changelog": "Integration:\n\n- Improved project generation performance.\n- Added support for keeping file/folder structure when working with external packages.\n- Fixed project generation not being refreshed when selecting Visual Studio as the preferred external editor."
},
"upmCi": {
"footprint": "8aa1049966a0586c636698ec81d764940b1dbe44"
"footprint": "d5d60c3083dbc14a4be33dc1f8c4e7fe147ffb74"
},
"repository": {
"url": "https://github.cds.internal.unity3d.com/unity/com.unity.ide.visualstudio.git",
"type": "git",
"revision": "f1e8af5df9e2507088a8622d173c9a7d5a03a882"
"revision": "ca1ece42f5a2c5484ba15a15bb975ccc1f6a1a3c"
}
}

0 comments on commit b132c03

Please sign in to comment.