Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [2.0.9] - 2021-05-04

Project generation:

Added support for CLI.

Integration:

Improved performance when discovering Visual Studio installations.
Warn when legacy assemblies are present in the project.
Warn when the package version is not up-to-date.
  • Loading branch information
Unity Technologies committed May 4, 2021
1 parent 06b02ac commit b0f2251
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 53 deletions.
31 changes: 21 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
# Code Editor Package for Visual Studio

## [2.0.8] - 2021-04-09
## [2.0.9] - 2021-05-04

Project generation:

Improved generation performance (especially with DOTS enabled projects).
Improved stability.
Updated Analyzers lookup strategy.
Fixed .vsconfig file not generated when using "regenerate all".
Added support for CLI.

Integration:

Integration
Improved performance when discovering Visual Studio installations.
Warn when legacy assemblies are present in the project.
Warn when the package version is not up-to-date.

Improved automation plugins.

Documentation
## [2.0.8] - 2021-04-09

Open sourced automation plugins.
Project generation:

- Improved generation performance (especially with DOTS enabled projects).
- Improved stability.
- Updated Analyzers lookup strategy.
- Fixed .vsconfig file not generated when using "regenerate all".

Integration:

- Improved automation plugins.

Documentation:

- Open sourced automation plugins.

## [2.0.7] - 2021-02-02

Integration:

- Remove com.unity.nuget.newtonsoft-json dependency in favor of the built-in JsonUtility for the VS Test Runner.


## [2.0.6] - 2021-01-20

Project generation:
Expand Down
76 changes: 76 additions & 0 deletions Editor/AsyncOperation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Unity Technologies.
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.Threading;

namespace Microsoft.Unity.VisualStudio.Editor
{
internal class AsyncOperation<T>
{
private readonly Func<T> _producer;
private readonly ManualResetEventSlim _resetEvent;

private T _result;
private Exception _exception;

private AsyncOperation(Func<T> producer)
{
_producer = producer;
_resetEvent = new ManualResetEventSlim(initialState: false);
}

public static AsyncOperation<T> Run(Func<T> producer)
{
var task = new AsyncOperation<T>(producer);
task.Run();
return task;
}

private void Run()
{
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
_result = _producer();
}
catch (Exception e)
{
_exception = e;
}
finally
{
_resetEvent.Set();
}
});
}

private void CheckCompletion()
{
if (!_resetEvent.IsSet)
_resetEvent.Wait();
}


public T Result
{
get
{
CheckCompletion();
return _result;
}
}

public Exception Exception
{
get
{
CheckCompletion();
return _exception;
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/AsyncOperation.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions Editor/Cli.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.Linq;
using Unity.CodeEditor;

namespace Microsoft.Unity.VisualStudio.Editor
{
internal static class Cli
{
internal static void Log(string message)
{
// Use writeline here, instead of UnityEngine.Debug.Log to not include the stacktrace in the editor.log
Console.WriteLine($"[VisualStudio.Editor.{nameof(Cli)}] {message}");
}

internal static string GetInstallationDetails(IVisualStudioInstallation installation)
{
return $"{installation.ToCodeEditorInstallation().Name} Path:{installation.Path}, LanguageVersionSupport:{installation.LatestLanguageVersionSupported} AnalyzersSupport:{installation.SupportsAnalyzers}";
}

internal static void GenerateSolutionWith(VisualStudioEditor vse, string installationPath)
{
if (vse != null && vse.TryGetVisualStudioInstallationForPath(installationPath, searchInstallations: true, out var vsi))
{
Log($"Using {GetInstallationDetails(vsi)}");
vse.SyncAll();
}
else
{
Log($"No Visual Studio installation found in ${installationPath}!");
}
}

internal static void GenerateSolution()
{
if (CodeEditor.CurrentEditor is VisualStudioEditor vse)
{
Log($"Using default editor settings for Visual Studio installation");
GenerateSolutionWith(vse, CodeEditor.CurrentEditorInstallation);
}
else
{
Log($"Visual Studio is not set as your default editor, looking for installations");
try
{
var installations = Discovery
.GetVisualStudioInstallations()
.Cast<VisualStudioInstallation>()
.OrderByDescending(vsi => !vsi.IsPrerelease)
.ThenBy(vsi => vsi.Version)
.ToArray();

foreach(var vsi in installations)
{
Log($"Detected {GetInstallationDetails(vsi)}");
}

var installation = installations
.FirstOrDefault();

if (installation != null)
{
var current = CodeEditor.CurrentEditorInstallation;
try
{
CodeEditor.SetExternalScriptEditor(installation.Path);
GenerateSolutionWith(CodeEditor.CurrentEditor as VisualStudioEditor, installation.Path);
}
finally
{
CodeEditor.SetExternalScriptEditor(current);
}
} else
{
Log($"No Visual Studio installation found!");
}
}
catch (Exception ex)
{
Log($"Error detecting Visual Studio installations: {ex}");
}
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/Cli.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions Editor/Discovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
using System;
using System.IO;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Linq;
using UnityEngine;

namespace Microsoft.Unity.VisualStudio.Editor
{
internal static class Discovery
{
internal const string ManagedWorkload = "Microsoft.VisualStudio.Workload.ManagedGame";

internal static string _vsWherePath;

public static void FindVSWhere()
{
_vsWherePath = FileUtility
.FindPackageAssetFullPath("VSWhere a:packages", "vswhere.exe")
.FirstOrDefault();
}

public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations()
{
Expand All @@ -37,7 +45,7 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
}
}

private static bool IsCandidateToDiscovery(string path)
private static bool IsCandidateForDiscovery(string path)
{
if (File.Exists(path) && VisualStudioEditor.IsWindows && Regex.IsMatch(path, "devenv.exe$", RegexOptions.IgnoreCase))
return true;
Expand All @@ -55,7 +63,7 @@ public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioI
if (string.IsNullOrEmpty(editorPath))
return false;

if (!IsCandidateToDiscovery(editorPath))
if (!IsCandidateForDiscovery(editorPath))
return false;

// On windows we use the executable directly, so we can query extra information
Expand Down Expand Up @@ -131,9 +139,7 @@ internal class VsWhereCatalog

private static IEnumerable<VisualStudioInstallation> QueryVsWhere()
{
var progpath = FileUtility
.FindPackageAssetFullPath("VSWhere a:packages", "vswhere.exe")
.FirstOrDefault();
var progpath = _vsWherePath;

if (string.IsNullOrWhiteSpace(progpath))
return Enumerable.Empty<VisualStudioInstallation>();
Expand Down
14 changes: 14 additions & 0 deletions Editor/KnownAssemblies.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

namespace Microsoft.Unity.VisualStudio.Editor
{
internal static class KnownAssemblies
{
public const string Bridge = "SyntaxTree.VisualStudio.Unity.Bridge";
public const string Messaging = "SyntaxTree.VisualStudio.Unity.Messaging";
public const string UnityVS = "UnityVS.VersionSpecific";
}
}
11 changes: 11 additions & 0 deletions Editor/KnownAssemblies.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Editor/Plugins/AppleEventIntegration.bundle/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>19H2</string>
<string>19H1030</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -27,19 +27,19 @@
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>12A7300</string>
<string>12D4e</string>
<key>DTPlatformName</key>
<string>macosx</string>
<key>DTPlatformVersion</key>
<string>10.15.6</string>
<string>11.1</string>
<key>DTSDKBuild</key>
<string>19G68</string>
<string>20C63</string>
<key>DTSDKName</key>
<string>macosx10.15</string>
<string>macosx11.1</string>
<key>DTXcode</key>
<string>1201</string>
<string>1240</string>
<key>DTXcodeBuild</key>
<string>12A7300</string>
<string>12D4e</string>
<key>LSMinimumSystemVersion</key>
<string>10.13</string>
<key>NSHumanReadableCopyright</key>
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions Editor/ProjectGeneration/ProjectGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private static bool ShouldSyncOnReimportedAsset(string asset)
private void RefreshCurrentInstallation()
{
var editor = CodeEditor.CurrentEditor as VisualStudioEditor;
editor?.TryGetVisualStudioInstallationForPath(CodeEditor.CurrentEditorInstallation, out m_CurrentInstallation);
editor?.TryGetVisualStudioInstallationForPath(CodeEditor.CurrentEditorInstallation, searchInstallations: true, out m_CurrentInstallation);
}

public void Sync()
Expand Down Expand Up @@ -370,7 +370,7 @@ private void SyncSolutionFileIfNotChanged(string path, string newContents)
{
return TypeCache
.GetTypesDerivedFrom<AssetPostprocessor>()
.Where(t => t.Assembly.GetName().Name != "SyntaxTree.VisualStudio.Unity.Bridge") // never call into the bridge if loaded with the package
.Where(t => t.Assembly.GetName().Name != KnownAssemblies.Bridge) // never call into the bridge if loaded with the package
.Select(t => t.GetMethod(name, SR.BindingFlags.Public | SR.BindingFlags.NonPublic | SR.BindingFlags.Static))
.Where(m => m != null);
}
Expand Down
Loading

0 comments on commit b0f2251

Please sign in to comment.