Skip to content

Commit 1aa4014

Browse files
committed
Optimize latency when opening a file with Visual Studio
1 parent 5722c17 commit 1aa4014

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,27 @@ public bool OpenProject(string path, int line, int column)
228228
if (!IsProjectGeneratedFor(path, generator, out var missingFlag))
229229
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.");
230230

231-
var solution = GetOrGenerateSolutionFile(generator);
231+
if (!generator.HasSolutionBeenGenerated())
232+
{
233+
// If no solution has been generated, run a sync before opening the solution
234+
generator.Sync();
235+
return OpenFromInstallation(installation, path, line, column);
236+
}
237+
else
238+
{
239+
// Else chances are high that the solution is up-to-date, proactively open the solution for better latency
240+
var result = OpenFromInstallation(installation, path, line, column);
241+
242+
// But run a sync to make sure everything is up-to-date. Best case we'll do nothing (apart from checking compilation objects), worst case VS will reload touched projects.
243+
generator.Sync();
244+
245+
return result;
246+
}
247+
}
248+
249+
private static bool OpenFromInstallation(IVisualStudioInstallation installation, string path, int line, int column)
250+
{
251+
var solution = installation.ProjectGenerator.SolutionFile();
232252
return installation.Open(path, line, column, solution);
233253
}
234254

@@ -291,11 +311,5 @@ private static bool IsProjectGeneratedFor(string path, IGenerator generator, out
291311
missingFlag = flag;
292312
return false;
293313
}
294-
295-
private static string GetOrGenerateSolutionFile(IGenerator generator)
296-
{
297-
generator.Sync();
298-
return generator.SolutionFile();
299-
}
300314
}
301315
}

0 commit comments

Comments
 (0)