performance optimize for opening file (#36)

This commit is contained in:
goethe
2026-02-12 17:34:39 +08:00
committed by GitHub
parent 53e1baac3c
commit a97262d3f7

View File

@@ -44,8 +44,11 @@ namespace Microsoft.Unity.VisualStudio.Editor
[InitializeOnLoadMethod] [InitializeOnLoadMethod]
static void LegacyVisualStudioCodePackageDisabler() static void LegacyVisualStudioCodePackageDisabler()
{ {
// disable legacy Visual Studio Code packages #if UNITY_2021_1_OR_NEWER
var editor = CodeEditor.Editor.GetCodeEditorForPath("code.cmd"); var editor = CodeEditor.Editor.GetCodeEditorForPath("code.cmd");
#else
var editor = CodeEditor.CurrentEditor;
#endif
if (editor == null) if (editor == null)
return; return;
@@ -138,7 +141,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
var newReuseWindow = EditorGUILayout.Toggle(new GUIContent("Reuse existing Cursor window", "When enabled, opens files in an existing Cursor window if found. When disabled, always opens a new window."), reuseWindow); var newReuseWindow = EditorGUILayout.Toggle(new GUIContent("Reuse existing Cursor window", "When enabled, opens files in an existing Cursor window if found. When disabled, always opens a new window."), reuseWindow);
if (newReuseWindow != reuseWindow) if (newReuseWindow != reuseWindow)
EditorPrefs.SetBool(VisualStudioCursorInstallation.ReuseExistingWindowKey, newReuseWindow); EditorPrefs.SetBool(VisualStudioCursorInstallation.ReuseExistingWindowKey, newReuseWindow);
EditorGUILayout.Space(); EditorGUILayout.Space();
} }
@@ -226,7 +229,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
var editorPath = CodeEditor.CurrentEditorInstallation; var editorPath = CodeEditor.CurrentEditorInstallation;
if (!Discovery.TryDiscoverInstallation(editorPath, out var installation)) { // Performance optimization: Use cached installation lookup instead of discovering every time
if (!TryGetVisualStudioInstallationForPath(editorPath, lookupDiscoveredInstallations: true, out var installation))
{
Debug.LogWarning($"Visual Studio executable {editorPath} is not found. Please change your settings in Edit > Preferences > External Tools."); Debug.LogWarning($"Visual Studio executable {editorPath} is not found. Please change your settings in Edit > Preferences > External Tools.");
return false; return false;
} }
@@ -238,7 +243,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
if (!IsProjectGeneratedFor(path, generator, out var missingFlag)) if (!IsProjectGeneratedFor(path, generator, out var missingFlag))
Debug.LogWarning($"You are trying to open {path} outside a generated project. This might cause problems with IntelliSense and debugging. To avoid this, you can change your .csproj preferences in Edit > Preferences > External Tools and enable {GetProjectGenerationFlagDescription(missingFlag)} generation."); Debug.LogWarning($"You are trying to open {path} outside a generated project. This might cause problems with IntelliSense and debugging. To avoid this, you can change your .csproj preferences in Edit > Preferences > External Tools and enable {GetProjectGenerationFlagDescription(missingFlag)} generation.");
var solution = GetOrGenerateSolutionFile(generator); // Performance optimization: Only sync if solution doesn't exist
var solution = GetOrGenerateSolutionFileIfNeeded(generator);
return installation.Open(path, line, column, solution); return installation.Open(path, line, column, solution);
} }
@@ -307,5 +313,15 @@ namespace Microsoft.Unity.VisualStudio.Editor
generator.Sync(); generator.Sync();
return generator.SolutionFile(); return generator.SolutionFile();
} }
// Performance optimization: Only sync if solution file doesn't exist
private static string GetOrGenerateSolutionFileIfNeeded(IGenerator generator)
{
if (!generator.HasSolutionBeenGenerated())
{
generator.Sync();
}
return generator.SolutionFile();
}
} }
} }