Skip to content

Commit f4d9585

Browse files
committed
Disable legacy package
1 parent dbca1f6 commit f4d9585

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

Packages/com.unity.ide.visualstudio/Editor/Discovery.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*--------------------------------------------------------------------------------------------*/
66

7-
using System;
87
using System.Collections.Generic;
98
using System.IO;
10-
using System.Linq;
11-
using UnityEngine;
129

1310
namespace Microsoft.Unity.VisualStudio.Editor
1411
{
@@ -24,19 +21,6 @@ public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallation
2421

2522
foreach (var installation in VisualStudioCodeInstallation.GetVisualStudioInstallations())
2623
yield return installation;
27-
28-
if (IsLegacyVSCodePackageLoaded())
29-
{
30-
Debug.LogWarning("[Visual Studio Editor] package has now built-in support for the whole Visual Studio family of products, including Visual Studio code. Please remove the legacy [Visual Studio Code Editor] package to avoid incompatibilities.");
31-
}
32-
}
33-
34-
private static bool IsLegacyVSCodePackageLoaded()
35-
{
36-
return AppDomain
37-
.CurrentDomain
38-
.GetAssemblies()
39-
.Any(a => a.FullName.StartsWith("Unity.VSCode.Editor"));
4024
}
4125

4226
public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation)

Packages/com.unity.ide.visualstudio/Editor/VisualStudioCodeInstallation.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,17 @@ public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioI
9696

9797
try
9898
{
99-
var manifestBase = editorPath;
99+
string manifestBase;
100+
100101
if (VisualStudioEditor.IsWindows) // on Windows, editorPath is a file, resources as subdirectory
101102
manifestBase = IOPath.GetDirectoryName(editorPath);
102103
else if (VisualStudioEditor.IsOSX) // on Mac, editorPath is a directory
103104
manifestBase = IOPath.Combine(editorPath, "Contents");
104105
else // on Linux, editorPath is a file, in a bin sub-directory
105-
manifestBase = Directory.GetParent(editorPath).Parent.FullName;
106+
manifestBase = Directory.GetParent(editorPath)?.Parent?.FullName;
107+
108+
if (manifestBase == null)
109+
return false;
106110

107111
var manifestFullPath = IOPath.Combine(manifestBase, @"resources", "app", "package.json");
108112
if (File.Exists(manifestFullPath))

Packages/com.unity.ide.visualstudio/Editor/VisualStudioEditor.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ static VisualStudioEditor()
4343
_discoverInstallations = AsyncOperation<Dictionary<string, IVisualStudioInstallation>>.Run(DiscoverInstallations);
4444
}
4545

46+
[InitializeOnLoadMethod]
47+
static void LegacyVisualStudioCodePackageDisabler()
48+
{
49+
// disable legacy Visual Studio Code packages
50+
var editor = CodeEditor.Editor.GetCodeEditorForPath("code.cmd");
51+
if (editor == null)
52+
return;
53+
54+
if (editor is VisualStudioEditor)
55+
return;
56+
57+
CodeEditor.Unregister(editor);
58+
}
59+
4660
private static Dictionary<string, IVisualStudioInstallation> DiscoverInstallations()
4761
{
4862
try

0 commit comments

Comments
 (0)