Skip to content

Commit

Permalink
Fixes microsoft#1415: Load package when the PythonToolsService is req…
Browse files Browse the repository at this point in the history
…uested.
  • Loading branch information
zooba committed Jul 18, 2016
1 parent 35cc0fe commit 6fbae20
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Python/Product/PythonTools/PythonTools/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,24 @@ internal static PythonToolsService GetPythonToolsService(this IServiceProvider s
if (serviceProvider == null) {
return null;
}
return (PythonToolsService)serviceProvider.GetService(typeof(PythonToolsService));
var pyService = (PythonToolsService)serviceProvider.GetService(typeof(PythonToolsService));
if (pyService == null) {
var shell = (IVsShell)serviceProvider.GetService(typeof(SVsShell));

var pkgGuid = GuidList.guidPythonToolsPackage;
IVsPackage pkg;
if (!ErrorHandler.Succeeded(shell.IsPackageLoaded(ref pkgGuid, out pkg)) && pkg != null) {
throw new InvalidOperationException("Python Tools Package was loaded but could not get service");
}
var hr = shell.LoadPackage(ref pkgGuid, out pkg);
if (!ErrorHandler.Succeeded(hr)) {
Debug.Fail(string.Format("Failed to load Python Tools Package: 0x{0:X08}", hr));
ErrorHandler.ThrowOnFailure(hr);
}

pyService = (PythonToolsService)serviceProvider.GetService(typeof(PythonToolsService));
}
return pyService;
}

internal static IComponentModel GetComponentModel(this IServiceProvider serviceProvider) {
Expand Down

0 comments on commit 6fbae20

Please sign in to comment.