You've already forked com.unity.ide.cursor
mirror of
https://github.com/boxqkrtm/com.unity.ide.cursor.git
synced 2026-05-15 14:50:08 +00:00
fix error
This commit is contained in:
@@ -13,30 +13,23 @@ using UnityEngine;
|
||||
using SimpleJSON;
|
||||
using IOPath = System.IO.Path;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
internal class VisualStudioCodeInstallation : VisualStudioInstallation
|
||||
{
|
||||
namespace Microsoft.Unity.VisualStudio.Editor {
|
||||
internal class VisualStudioCodeInstallation : VisualStudioInstallation {
|
||||
private static readonly IGenerator _generator = new SdkStyleProjectGeneration();
|
||||
|
||||
public override bool SupportsAnalyzers
|
||||
{
|
||||
get
|
||||
{
|
||||
public override bool SupportsAnalyzers {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override Version LatestLanguageVersionSupported
|
||||
{
|
||||
get
|
||||
{
|
||||
public override Version LatestLanguageVersionSupported {
|
||||
get {
|
||||
return new Version(11, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetExtensionPath()
|
||||
{
|
||||
private string GetExtensionPath() {
|
||||
var vscode = IsPrerelease ? ".vscode-insiders" : ".vscode";
|
||||
var extensionsPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), vscode, "extensions");
|
||||
if (!Directory.Exists(extensionsPath))
|
||||
@@ -48,8 +41,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public override string[] GetAnalyzers()
|
||||
{
|
||||
public override string[] GetAnalyzers() {
|
||||
var vstuPath = GetExtensionPath();
|
||||
if (string.IsNullOrEmpty(vstuPath))
|
||||
return Array.Empty<string>();
|
||||
@@ -57,34 +49,29 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return GetAnalyzers(vstuPath);
|
||||
}
|
||||
|
||||
public override IGenerator ProjectGenerator
|
||||
{
|
||||
get
|
||||
{
|
||||
public override IGenerator ProjectGenerator {
|
||||
get {
|
||||
return _generator;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsCandidateForDiscovery(string path)
|
||||
{
|
||||
private static bool IsCandidateForDiscovery(string path) {
|
||||
#if UNITY_EDITOR_OSX
|
||||
return Directory.Exists(path) && Regex.IsMatch(path, ".*Code.*.app$", RegexOptions.IgnoreCase);
|
||||
return Directory.Exists(path) && Regex.IsMatch(path, ".*Cursor.*.app$", RegexOptions.IgnoreCase);
|
||||
#elif UNITY_EDITOR_WIN
|
||||
return File.Exists(path) && Regex.IsMatch(path, ".*Code.*.exe$", RegexOptions.IgnoreCase);
|
||||
return File.Exists(path) && Regex.IsMatch(path, ".*Cursor.*.exe$", RegexOptions.IgnoreCase);
|
||||
#else
|
||||
return File.Exists(path) && path.EndsWith("code", StringComparison.OrdinalIgnoreCase);
|
||||
return File.Exists(path) && path.EndsWith("cursor", StringComparison.OrdinalIgnoreCase);
|
||||
#endif
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class VisualStudioCodeManifest
|
||||
{
|
||||
internal class VisualStudioCodeManifest {
|
||||
public string name;
|
||||
public string version;
|
||||
}
|
||||
|
||||
public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation)
|
||||
{
|
||||
public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation) {
|
||||
installation = null;
|
||||
|
||||
if (string.IsNullOrEmpty(editorPath))
|
||||
@@ -96,8 +83,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
Version version = null;
|
||||
var isPrerelease = false;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
var manifestBase = GetRealPath(editorPath);
|
||||
|
||||
#if UNITY_EDITOR_WIN
|
||||
@@ -117,21 +103,17 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return false;
|
||||
|
||||
var manifestFullPath = IOPath.Combine(manifestBase, "resources", "app", "package.json");
|
||||
if (File.Exists(manifestFullPath))
|
||||
{
|
||||
if (File.Exists(manifestFullPath)) {
|
||||
var manifest = JsonUtility.FromJson<VisualStudioCodeManifest>(File.ReadAllText(manifestFullPath));
|
||||
Version.TryParse(manifest.version.Split('-').First(), out version);
|
||||
isPrerelease = manifest.version.ToLower().Contains("insider");
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
} catch (Exception) {
|
||||
// do not fail if we are not able to retrieve the exact version number
|
||||
}
|
||||
|
||||
isPrerelease = isPrerelease || editorPath.ToLower().Contains("insider");
|
||||
installation = new VisualStudioCodeInstallation()
|
||||
{
|
||||
installation = new VisualStudioCodeInstallation() {
|
||||
IsPrerelease = isPrerelease,
|
||||
Name = "Cursor" + (isPrerelease ? " - Insider" : string.Empty) + (version != null ? $" [{version.ToString(3)}]" : string.Empty),
|
||||
Path = editorPath,
|
||||
@@ -141,16 +123,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations()
|
||||
{
|
||||
public static IEnumerable<IVisualStudioInstallation> GetVisualStudioInstallations() {
|
||||
var candidates = new List<string>();
|
||||
|
||||
#if UNITY_EDITOR_WIN
|
||||
var localAppPath = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs");
|
||||
var programFiles = IOPath.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
|
||||
|
||||
foreach (var basePath in new[] {localAppPath, programFiles})
|
||||
{
|
||||
foreach (var basePath in new[] { localAppPath, programFiles }) {
|
||||
candidates.Add(IOPath.Combine(basePath, "Microsoft VS Code Insiders", "Code - Insiders.exe"));
|
||||
}
|
||||
#elif UNITY_EDITOR_OSX
|
||||
@@ -166,8 +146,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
candidates.AddRange(GetXdgCandidates());
|
||||
#endif
|
||||
|
||||
foreach (var candidate in candidates.Distinct())
|
||||
{
|
||||
foreach (var candidate in candidates.Distinct()) {
|
||||
if (TryDiscoverInstallation(candidate, out var installation))
|
||||
yield return installation;
|
||||
}
|
||||
@@ -222,16 +201,13 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return new String(cbuf, 0, chars);
|
||||
}
|
||||
#else
|
||||
internal static string GetRealPath(string path)
|
||||
{
|
||||
internal static string GetRealPath(string path) {
|
||||
return path;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void CreateExtraFiles(string projectDirectory)
|
||||
{
|
||||
try
|
||||
{
|
||||
public override void CreateExtraFiles(string projectDirectory) {
|
||||
try {
|
||||
var vscodeDirectory = IOPath.Combine(projectDirectory.NormalizePathSeparators(), ".vscode");
|
||||
Directory.CreateDirectory(vscodeDirectory);
|
||||
|
||||
@@ -240,9 +216,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
CreateRecommendedExtensionsFile(vscodeDirectory, enablePatch);
|
||||
CreateSettingsFile(vscodeDirectory, enablePatch);
|
||||
CreateLaunchFile(vscodeDirectory, enablePatch);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
} catch (IOException) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,11 +231,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
]
|
||||
}";
|
||||
|
||||
private static void CreateLaunchFile(string vscodeDirectory, bool enablePatch)
|
||||
{
|
||||
private static void CreateLaunchFile(string vscodeDirectory, bool enablePatch) {
|
||||
var launchFile = IOPath.Combine(vscodeDirectory, "launch.json");
|
||||
if (File.Exists(launchFile))
|
||||
{
|
||||
if (File.Exists(launchFile)) {
|
||||
if (enablePatch)
|
||||
PatchLaunchFile(launchFile);
|
||||
|
||||
@@ -271,10 +243,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
File.WriteAllText(launchFile, DefaultLaunchFileContent);
|
||||
}
|
||||
|
||||
private static void PatchLaunchFile(string launchFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
private static void PatchLaunchFile(string launchFile) {
|
||||
try {
|
||||
const string configurationsKey = "configurations";
|
||||
const string typeKey = "type";
|
||||
|
||||
@@ -282,8 +252,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
var launch = JSONNode.Parse(content);
|
||||
|
||||
var configurations = launch[configurationsKey] as JSONArray;
|
||||
if (configurations == null)
|
||||
{
|
||||
if (configurations == null) {
|
||||
configurations = new JSONArray();
|
||||
launch.Add(configurationsKey, configurations);
|
||||
}
|
||||
@@ -295,18 +264,14 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
configurations.Add(defaultContent[configurationsKey][0]);
|
||||
|
||||
WriteAllTextFromJObject(launchFile, launch);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
} catch (Exception) {
|
||||
// do not fail if we cannot patch the launch.json file
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSettingsFile(string vscodeDirectory, bool enablePatch)
|
||||
{
|
||||
private void CreateSettingsFile(string vscodeDirectory, bool enablePatch) {
|
||||
var settingsFile = IOPath.Combine(vscodeDirectory, "settings.json");
|
||||
if (File.Exists(settingsFile))
|
||||
{
|
||||
if (File.Exists(settingsFile)) {
|
||||
if (enablePatch)
|
||||
PatchSettingsFile(settingsFile);
|
||||
|
||||
@@ -379,10 +344,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
File.WriteAllText(settingsFile, content);
|
||||
}
|
||||
|
||||
private void PatchSettingsFile(string settingsFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
private void PatchSettingsFile(string settingsFile) {
|
||||
try {
|
||||
const string excludesKey = "files.exclude";
|
||||
const string solutionKey = "dotnet.defaultSolution";
|
||||
|
||||
@@ -397,8 +360,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
var patched = false;
|
||||
|
||||
// Remove files.exclude for solution+project files in the project root
|
||||
foreach (var exclude in excludes)
|
||||
{
|
||||
foreach (var exclude in excludes) {
|
||||
if (!bool.TryParse(exclude.Value, out var exc) || !exc)
|
||||
continue;
|
||||
|
||||
@@ -417,8 +379,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
// Check default solution
|
||||
var defaultSolution = settings[solutionKey];
|
||||
var solutionFile = IOPath.GetFileName(ProjectGenerator.SolutionFile());
|
||||
if (defaultSolution == null || defaultSolution.Value != solutionFile)
|
||||
{
|
||||
if (defaultSolution == null || defaultSolution.Value != solutionFile) {
|
||||
settings[solutionKey] = solutionFile;
|
||||
patched = true;
|
||||
}
|
||||
@@ -430,9 +391,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
excludes.Remove(patch);
|
||||
|
||||
WriteAllTextFromJObject(settingsFile, settings);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
} catch (Exception) {
|
||||
// do not fail if we cannot patch the settings.json file
|
||||
}
|
||||
}
|
||||
@@ -445,12 +404,10 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
}
|
||||
";
|
||||
|
||||
private static void CreateRecommendedExtensionsFile(string vscodeDirectory, bool enablePatch)
|
||||
{
|
||||
private static void CreateRecommendedExtensionsFile(string vscodeDirectory, bool enablePatch) {
|
||||
// see https://tattoocoder.com/recommending-vscode-extensions-within-your-open-source-projects/
|
||||
var extensionFile = IOPath.Combine(vscodeDirectory, "extensions.json");
|
||||
if (File.Exists(extensionFile))
|
||||
{
|
||||
if (File.Exists(extensionFile)) {
|
||||
if (enablePatch)
|
||||
PatchRecommendedExtensionsFile(extensionFile);
|
||||
|
||||
@@ -460,18 +417,15 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
File.WriteAllText(extensionFile, DefaultRecommendedExtensionsContent);
|
||||
}
|
||||
|
||||
private static void PatchRecommendedExtensionsFile(string extensionFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
private static void PatchRecommendedExtensionsFile(string extensionFile) {
|
||||
try {
|
||||
const string recommendationsKey = "recommendations";
|
||||
|
||||
var content = File.ReadAllText(extensionFile);
|
||||
var extensions = JSONNode.Parse(content);
|
||||
|
||||
var recommendations = extensions[recommendationsKey] as JSONArray;
|
||||
if (recommendations == null)
|
||||
{
|
||||
if (recommendations == null) {
|
||||
recommendations = new JSONArray();
|
||||
extensions.Add(recommendationsKey, recommendations);
|
||||
}
|
||||
@@ -481,25 +435,20 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
|
||||
recommendations.Add(MicrosoftUnityExtensionId);
|
||||
WriteAllTextFromJObject(extensionFile, extensions);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
} catch (Exception) {
|
||||
// do not fail if we cannot patch the extensions.json file
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteAllTextFromJObject(string file, JSONNode node)
|
||||
{
|
||||
private static void WriteAllTextFromJObject(string file, JSONNode node) {
|
||||
using (var fs = File.Open(file, FileMode.Create))
|
||||
using (var sw = new StreamWriter(fs))
|
||||
{
|
||||
using (var sw = new StreamWriter(fs)) {
|
||||
// Keep formatting/indent in sync with default contents
|
||||
sw.Write(node.ToString(aIndent: 4));
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Open(string path, int line, int column, string solution)
|
||||
{
|
||||
public override bool Open(string path, int line, int column, string solution) {
|
||||
line = Math.Max(1, line);
|
||||
column = Math.Max(0, column);
|
||||
|
||||
@@ -513,8 +462,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ProcessStartInfo ProcessStartInfoFor(string application, string arguments)
|
||||
{
|
||||
private static ProcessStartInfo ProcessStartInfoFor(string application, string arguments) {
|
||||
#if UNITY_EDITOR_OSX
|
||||
// wrap with built-in OSX open feature
|
||||
arguments = $"-n \"{application}\" --args {arguments}";
|
||||
@@ -525,8 +473,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
public static void Initialize() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user