Skip to content

Commit 7576727

Browse files
sailroGitHub Enterprise
authored andcommitted
Merge pull request #196 from unity/open-latency
Optimize latency when opening a file with Visual Studio
2 parents 6012a0d + 0e349e8 commit 7576727

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

.yamato/CI.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ editors:
1010
platforms:
1111
- name: win
1212
type: Unity::VM
13-
image: scripting/scripting-bokken-images:latest
13+
image: package-ci/win10:v4
1414
flavor: b1.large
1515
envsetup: echo
1616
- name: mac
1717
type: Unity::VM::osx
18-
image: package-ci/mac:stable
18+
image: package-ci/macos-13:v4
1919
flavor: m1.mac
2020
envsetup: echo
2121
- name: linux
2222
type: Unity::VM
23-
image: package-ci/ubuntu:stable
23+
image: package-ci/ubuntu-22.04:v4
2424
flavor: b1.large
2525
envsetup: npm config set prefix '~/npm-global'
2626

@@ -113,7 +113,7 @@ run_vetting_test_project_{{ editor.version }}:
113113
name: Run vetting tests on {{ editor.version }}
114114
agent:
115115
type: Unity::VM
116-
image: package-ci/ubuntu:stable
116+
image: package-ci/ubuntu-22.04:v4
117117
flavor: b1.large
118118
variables:
119119
PATH: /home/bokken/bin:/home/bokken/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin:/home/bokken/.npm-global/bin::/home/bokken/npm-global/bin
@@ -203,7 +203,7 @@ publish_release:
203203
{% endfor %}
204204
agent:
205205
type: Unity::VM
206-
image: package-ci/win10:stable
206+
image: package-ci/win10:v4
207207
flavor: b1.large
208208
variables:
209209
UPMCI_ENABLE_PACKAGE_SIGNING: 1

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)