From f873af2acc36e5c02f92234457a8a1533719c467 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 1 Jul 2015 16:50:40 -0700 Subject: [PATCH 1/2] Adds extensibility point to allow other VS extensions to provide panes in the environments list. --- .../EnvironmentsList/EnvironmentsList.csproj | 1 + .../IEnvironmentViewExtensionProvider.cs | 19 +++++++++++ .../source.extension.vsixmanifest | 1 + .../PythonTools/Properties/AssemblyInfo.cs | 6 ++++ Python/Product/PythonTools/PythonTools.csproj | 15 +++++++++ .../InterpreterListToolWindow.cs | 33 +++++++++++++++++++ .../PythonTools/Project/ProjectResources.cs | 3 ++ Python/Product/PythonTools/Resources.resx | 8 +++++ 8 files changed, 86 insertions(+) create mode 100644 Python/Product/EnvironmentsList/IEnvironmentViewExtensionProvider.cs diff --git a/Python/Product/EnvironmentsList/EnvironmentsList.csproj b/Python/Product/EnvironmentsList/EnvironmentsList.csproj index 07a73838a1..2c5986108a 100644 --- a/Python/Product/EnvironmentsList/EnvironmentsList.csproj +++ b/Python/Product/EnvironmentsList/EnvironmentsList.csproj @@ -226,6 +226,7 @@ DBExtension.xaml + PipExtension.xaml diff --git a/Python/Product/EnvironmentsList/IEnvironmentViewExtensionProvider.cs b/Python/Product/EnvironmentsList/IEnvironmentViewExtensionProvider.cs new file mode 100644 index 0000000000..f523bd9f5c --- /dev/null +++ b/Python/Product/EnvironmentsList/IEnvironmentViewExtensionProvider.cs @@ -0,0 +1,19 @@ +/* **************************************************************************** + * + * Copyright (c) Microsoft Corporation. + * + * This source code is subject to terms and conditions of the Apache License, Version 2.0. A + * copy of the license can be found in the License.html file at the root of this distribution. If + * you cannot locate the Apache License, Version 2.0, please send an email to + * vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound + * by the terms of the Apache License, Version 2.0. + * + * You must not remove this notice, or any other, from this software. + * + * ***************************************************************************/ + +namespace Microsoft.PythonTools.EnvironmentsList { + public interface IEnvironmentViewExtensionProvider { + IEnvironmentViewExtension CreateExtension(EnvironmentView view); + } +} diff --git a/Python/Product/PythonTools/Dev14OrLater/source.extension.vsixmanifest b/Python/Product/PythonTools/Dev14OrLater/source.extension.vsixmanifest index ac8b01c1f0..fb4f770257 100644 --- a/Python/Product/PythonTools/Dev14OrLater/source.extension.vsixmanifest +++ b/Python/Product/PythonTools/Dev14OrLater/source.extension.vsixmanifest @@ -34,6 +34,7 @@ + diff --git a/Python/Product/PythonTools/Properties/AssemblyInfo.cs b/Python/Product/PythonTools/Properties/AssemblyInfo.cs index bd9f9d9732..0b5f518238 100644 --- a/Python/Product/PythonTools/Properties/AssemblyInfo.cs +++ b/Python/Product/PythonTools/Properties/AssemblyInfo.cs @@ -17,6 +17,8 @@ using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Microsoft.VisualStudio.Shell; + // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information @@ -29,6 +31,10 @@ [assembly: CLSCompliant(false)] [assembly: NeutralResourcesLanguage("en-US")] +[assembly: ProvideCodeBase(AssemblyName = "Microsoft.PythonTools.Analysis", CodeBase = "Microsoft.PythonTools.Analysis.dll", Version = AssemblyVersionInfo.StableVersion)] +[assembly: ProvideCodeBase(AssemblyName = "Microsoft.PythonTools.EnvironmentsList", CodeBase = "Microsoft.PythonTools.EnvironmentsList.dll", Version = AssemblyVersionInfo.StableVersion)] +[assembly: ProvideCodeBase(AssemblyName = "Microsoft.PythonTools.VSInterpreters", CodeBase = "Microsoft.PythonTools.VSInterpreters.dll", Version = AssemblyVersionInfo.StableVersion)] + [assembly: InternalsVisibleTo("Microsoft.PythonTools.TestAdapter, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] [assembly: InternalsVisibleTo("AnalysisTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] diff --git a/Python/Product/PythonTools/PythonTools.csproj b/Python/Product/PythonTools/PythonTools.csproj index e02e33bcac..35a366e58f 100644 --- a/Python/Product/PythonTools/PythonTools.csproj +++ b/Python/Product/PythonTools/PythonTools.csproj @@ -76,6 +76,7 @@ {b20e082b-4d3c-457d-b2bd-60420b434573} Microsoft.PythonTools.EnvironmentsList True + False {815db0cd-c0dd-4997-b43c-abee4dbeffe7} @@ -1434,4 +1435,18 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs b/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs index e2f368c93a..cd87251307 100644 --- a/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs +++ b/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs @@ -125,6 +125,39 @@ sealed class InterpreterListToolWindow : ToolWindowPane { if (_withDb != null) { view.Extensions.Add(new DBExtensionProvider(_withDb)); } + + var model = _site.GetComponentModel(); + if (model != null) { + try { + foreach (var provider in model.GetExtensions()) { + try { + var ext = provider.CreateExtension(view); + if (ext != null) { + view.Extensions.Add(ext); + } + } catch (Exception ex) { + LogLoadException(provider, ex); + } + } + } catch (Exception ex2) { + LogLoadException(null, ex2); + } + } + } + + private static void LogLoadException(IEnvironmentViewExtensionProvider provider, Exception ex) { + string message; + if (provider == null) { + message = SR.GetString(SR.ErrorLoadingEnvironmentViewExtensions, ex); + } else { + message = SR.GetString(SR.ErrorLoadingEnvironmentViewExtension, provider.GetType().FullName, ex); + } + + Debug.Fail(message); + try { + ActivityLog.LogError(SR.ProductName, message); + } catch (InvalidOperationException) { + } } private void PipExtensionProvider_GetElevateSetting(object sender, ValueEventArgs e) { diff --git a/Python/Product/PythonTools/PythonTools/Project/ProjectResources.cs b/Python/Product/PythonTools/PythonTools/Project/ProjectResources.cs index 06994d5d4d..89a2135e3a 100644 --- a/Python/Product/PythonTools/PythonTools/Project/ProjectResources.cs +++ b/Python/Product/PythonTools/PythonTools/Project/ProjectResources.cs @@ -185,6 +185,9 @@ internal class SR : CommonSR { public const string InsertSnippet = "InsertSnippet"; public const string SurroundWith = "SurroundWith"; + public const string ErrorLoadingEnvironmentViewExtensions = "ErrorLoadingEnvironmentViewExtensions"; + public const string ErrorLoadingEnvironmentViewExtension = "ErrorLoadingEnvironmentViewExtension"; + private static readonly Lazy _manager = new Lazy( () => new System.Resources.ResourceManager("Microsoft.PythonTools.Resources", typeof(SR).Assembly), LazyThreadSafetyMode.ExecutionAndPublication diff --git a/Python/Product/PythonTools/Resources.resx b/Python/Product/PythonTools/Resources.resx index 9612689718..95d3df53db 100644 --- a/Python/Product/PythonTools/Resources.resx +++ b/Python/Product/PythonTools/Resources.resx @@ -576,4 +576,12 @@ Packages that cannot be installed using pip may prevent all listed packages from Python UWP Project + + An error occurred loading '{0}' for the environments window. +{1} + + + An error occurred loading extensions for the environments window. +{1} + \ No newline at end of file From 3f0fe78ad0e81faa0e871e143fbf483bc898607b Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Thu, 2 Jul 2015 11:46:36 -0700 Subject: [PATCH 2/2] Switches to use IVsActivityLog for error logging. --- .../InterpreterList/InterpreterListToolWindow.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs b/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs index cd87251307..c250be0d09 100644 --- a/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs +++ b/Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs @@ -145,7 +145,7 @@ sealed class InterpreterListToolWindow : ToolWindowPane { } } - private static void LogLoadException(IEnvironmentViewExtensionProvider provider, Exception ex) { + private void LogLoadException(IEnvironmentViewExtensionProvider provider, Exception ex) { string message; if (provider == null) { message = SR.GetString(SR.ErrorLoadingEnvironmentViewExtensions, ex); @@ -154,9 +154,13 @@ sealed class InterpreterListToolWindow : ToolWindowPane { } Debug.Fail(message); - try { - ActivityLog.LogError(SR.ProductName, message); - } catch (InvalidOperationException) { + var log = _site.GetService(typeof(SVsActivityLog)) as IVsActivityLog; + if (log != null) { + log.LogEntry( + (uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR, + SR.ProductName, + message + ); } }