Skip to content

Commit a31dbed

Browse files
author
Dino Viehland
committed
Merge pull request #537 from zooba/environment-extensions
Environments window extensibility
2 parents 459cdc4 + 3f0fe78 commit a31dbed

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed

Python/Product/EnvironmentsList/EnvironmentsList.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
<Compile Include="DBExtension.xaml.cs">
227227
<DependentUpon>DBExtension.xaml</DependentUpon>
228228
</Compile>
229+
<Compile Include="IEnvironmentViewExtensionProvider.cs" />
229230
<Compile Include="Pep440Version.cs" />
230231
<Compile Include="PipExtension.xaml.cs">
231232
<DependentUpon>PipExtension.xaml</DependentUpon>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* ****************************************************************************
2+
*
3+
* Copyright (c) Microsoft Corporation.
4+
*
5+
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6+
* copy of the license can be found in the License.html file at the root of this distribution. If
7+
* you cannot locate the Apache License, Version 2.0, please send an email to
8+
* [email protected]. By using this source code in any fashion, you are agreeing to be bound
9+
* by the terms of the Apache License, Version 2.0.
10+
*
11+
* You must not remove this notice, or any other, from this software.
12+
*
13+
* ***************************************************************************/
14+
15+
namespace Microsoft.PythonTools.EnvironmentsList {
16+
public interface IEnvironmentViewExtensionProvider {
17+
IEnvironmentViewExtension CreateExtension(EnvironmentView view);
18+
}
19+
}

Python/Product/PythonTools/Dev14OrLater/source.extension.vsixmanifest

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="|%CurrentProject%;_GetTargetPath|" />
3535
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="|Microsoft.PythonTools.Analysis;_GetTargetPath|" />
3636
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="|Microsoft.PythonTools.Debugger;_GetTargetPath|" />
37+
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="|Microsoft.PythonTools.EnvironmentsList;_GetTargetPath|" />
3738
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="|Microsoft.PythonTools.VSInterpreters;_GetTargetPath|" />
3839
<Asset Type="Microsoft.VisualStudio.MefComponent" Path="|TestAdapter;_GetTargetPath|" />
3940
<Asset Type="UnitTestExtension" Path="|TestAdapter;_GetTargetPath|" />

Python/Product/PythonTools/Properties/AssemblyInfo.cs

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using System.Resources;
1818
using System.Runtime.CompilerServices;
1919
using System.Runtime.InteropServices;
20+
using Microsoft.VisualStudio.Shell;
21+
2022

2123
// General Information about an assembly is controlled through the following
2224
// set of attributes. Change these attribute values to modify the information
@@ -29,6 +31,10 @@
2931
[assembly: CLSCompliant(false)]
3032
[assembly: NeutralResourcesLanguage("en-US")]
3133

34+
[assembly: ProvideCodeBase(AssemblyName = "Microsoft.PythonTools.Analysis", CodeBase = "Microsoft.PythonTools.Analysis.dll", Version = AssemblyVersionInfo.StableVersion)]
35+
[assembly: ProvideCodeBase(AssemblyName = "Microsoft.PythonTools.EnvironmentsList", CodeBase = "Microsoft.PythonTools.EnvironmentsList.dll", Version = AssemblyVersionInfo.StableVersion)]
36+
[assembly: ProvideCodeBase(AssemblyName = "Microsoft.PythonTools.VSInterpreters", CodeBase = "Microsoft.PythonTools.VSInterpreters.dll", Version = AssemblyVersionInfo.StableVersion)]
37+
3238
[assembly: InternalsVisibleTo("Microsoft.PythonTools.TestAdapter, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
3339

3440
[assembly: InternalsVisibleTo("AnalysisTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

Python/Product/PythonTools/PythonTools.csproj

+15
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Project>{b20e082b-4d3c-457d-b2bd-60420b434573}</Project>
7777
<Name>Microsoft.PythonTools.EnvironmentsList</Name>
7878
<IncludeInVSIX>True</IncludeInVSIX>
79+
<Private>False</Private>
7980
</ProjectReference>
8081
<ProjectReference Include="..\VSInterpreters\VSInterpreters.csproj">
8182
<Project>{815db0cd-c0dd-4997-b43c-abee4dbeffe7}</Project>
@@ -1434,4 +1435,18 @@
14341435
</Resource>
14351436
</ItemGroup>
14361437
</Target>
1438+
1439+
<!-- We build these assemblies into separate folders to avoid incremental cleaning issues,
1440+
but then CreatePkgDef can't find them for the ProvideCodeBase attributes. So we copy
1441+
into the PythonTools output folder temporarily to generate the pkgdef file. -->
1442+
<Target Name="_CopyForCreatePkgDef" BeforeTargets="GeneratePkgDef">
1443+
<Copy SourceFiles="$(OutputPath)..\Analysis\Microsoft.PythonTools.Analysis.dll;
1444+
$(OutputPath)..\EnvironmentsList\Microsoft.PythonTools.EnvironmentsList.dll;
1445+
$(OutputPath)..\VSInterpreters\Microsoft.PythonTools.VSInterpreters.dll" DestinationFolder="$(OutputPath)">
1446+
<Output TaskParameter="CopiedFiles" ItemName="_CopiedForCreatePkgdef" />
1447+
</Copy>
1448+
</Target>
1449+
<Target Name="_DeleteAfterCreatePkgDef" AfterTargets="GeneratePkgDef">
1450+
<Delete Files="@(_CopiedForCreatePkgdef)" />
1451+
</Target>
14371452
</Project>

Python/Product/PythonTools/PythonTools/InterpreterList/InterpreterListToolWindow.cs

+37
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,43 @@ private void List_ViewCreated(object sender, EnvironmentViewEventArgs e) {
125125
if (_withDb != null) {
126126
view.Extensions.Add(new DBExtensionProvider(_withDb));
127127
}
128+
129+
var model = _site.GetComponentModel();
130+
if (model != null) {
131+
try {
132+
foreach (var provider in model.GetExtensions<IEnvironmentViewExtensionProvider>()) {
133+
try {
134+
var ext = provider.CreateExtension(view);
135+
if (ext != null) {
136+
view.Extensions.Add(ext);
137+
}
138+
} catch (Exception ex) {
139+
LogLoadException(provider, ex);
140+
}
141+
}
142+
} catch (Exception ex2) {
143+
LogLoadException(null, ex2);
144+
}
145+
}
146+
}
147+
148+
private void LogLoadException(IEnvironmentViewExtensionProvider provider, Exception ex) {
149+
string message;
150+
if (provider == null) {
151+
message = SR.GetString(SR.ErrorLoadingEnvironmentViewExtensions, ex);
152+
} else {
153+
message = SR.GetString(SR.ErrorLoadingEnvironmentViewExtension, provider.GetType().FullName, ex);
154+
}
155+
156+
Debug.Fail(message);
157+
var log = _site.GetService(typeof(SVsActivityLog)) as IVsActivityLog;
158+
if (log != null) {
159+
log.LogEntry(
160+
(uint)__ACTIVITYLOG_ENTRYTYPE.ALE_ERROR,
161+
SR.ProductName,
162+
message
163+
);
164+
}
128165
}
129166

130167
private void PipExtensionProvider_GetElevateSetting(object sender, ValueEventArgs<bool> e) {

Python/Product/PythonTools/PythonTools/Project/ProjectResources.cs

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ internal class SR : CommonSR {
185185
public const string InsertSnippet = "InsertSnippet";
186186
public const string SurroundWith = "SurroundWith";
187187

188+
public const string ErrorLoadingEnvironmentViewExtensions = "ErrorLoadingEnvironmentViewExtensions";
189+
public const string ErrorLoadingEnvironmentViewExtension = "ErrorLoadingEnvironmentViewExtension";
190+
188191
private static readonly Lazy<ResourceManager> _manager = new Lazy<ResourceManager>(
189192
() => new System.Resources.ResourceManager("Microsoft.PythonTools.Resources", typeof(SR).Assembly),
190193
LazyThreadSafetyMode.ExecutionAndPublication

Python/Product/PythonTools/Resources.resx

+8
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,12 @@ Packages that cannot be installed using pip may prevent all listed packages from
576576
<data name="ImportWizardUwpProjectCustomization" xml:space="preserve">
577577
<value>Python UWP Project</value>
578578
</data>
579+
<data name="ErrorLoadingEnvironmentViewExtension" xml:space="preserve">
580+
<value>An error occurred loading '{0}' for the environments window.
581+
{1}</value>
582+
</data>
583+
<data name="ErrorLoadingEnvironmentViewExtensions" xml:space="preserve">
584+
<value>An error occurred loading extensions for the environments window.
585+
{1}</value>
586+
</data>
579587
</root>

0 commit comments

Comments
 (0)