Skip to content

Commit 4ee75b2

Browse files
committed
Add new PowerShellEditorServices.VSCode module
This change introduces a new module named PowerShellEditorServices.VSCode which provides functionality that is meant to be used only with the PowerShell extension for Visual Studio Code. It also adds the necessary infrastructure to load this module when the language service starts up.
1 parent 764082f commit 4ee75b2

File tree

8 files changed

+234
-6
lines changed

8 files changed

+234
-6
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ task SetupDotNet -Before Restore, Clean, Build, TestHost, TestServer, TestProtoc
2222

2323
$requiredSdkVersion = "1.0.0"
2424

25-
$needsInstall = $true
2625
$dotnetPath = "$PSScriptRoot/.dotnet"
2726
$dotnetExePath = if ($script:IsUnix) { "$dotnetPath/dotnet" } else { "$dotnetPath/dotnet.exe" }
2827
$originalDotNetExePath = $dotnetExePath
@@ -98,8 +97,9 @@ task Restore -If { "Restore" -in $BuildTask -or (NeedsRestore(".\src")) -or (Nee
9897
task Clean {
9998
exec { & $script:dotnetExe clean }
10099
Remove-Item .\module\PowerShellEditorServices\bin -Recurse -Force -ErrorAction Ignore
100+
Remove-Item .\module\PowerShellEditorServices.VSCode\bin -Recurse -Force -ErrorAction Ignore
101101
Get-ChildItem -Recurse src\*.nupkg | Remove-Item -Force -ErrorAction Ignore
102-
Get-ChildItem .\module\PowerShellEditorServices\*.zip | Remove-Item -Force -ErrorAction Ignore
102+
Get-ChildItem .\module\PowerShellEditorServices*.zip | Remove-Item -Force -ErrorAction Ignore
103103
Get-ChildItem .\module\PowerShellEditorServices\Commands\en-US\*-help.xml | Remove-Item -Force -ErrorAction Ignore
104104
}
105105

@@ -144,6 +144,7 @@ task TestPowerShellApi -If { !$script:IsUnix } {
144144

145145
task Build {
146146
exec { & $script:dotnetExe build -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj $script:TargetFrameworksParam }
147+
exec { & $script:dotnetExe build -c $Configuration .\src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj $script:TargetFrameworksParam }
147148
}
148149

149150
function UploadTestLogs {
@@ -188,15 +189,26 @@ task CITest (job Test -Safe), {
188189
}
189190

190191
task LayoutModule -After Build {
192+
# Lay out the PowerShellEditorServices module's binaries
191193
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\ -Type Directory | Out-Null
192194
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop -Type Directory | Out-Null
193195
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Core -Type Directory | Out-Null
194196

197+
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
195198
if (!$script:IsUnix) {
196199
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
197200
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\Newtonsoft.Json.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
198201
}
199-
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
202+
203+
# Lay out the PowerShellEditorServices.VSCode module's binaries
204+
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices.VSCode\bin\ -Type Directory | Out-Null
205+
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices.VSCode\bin\Desktop -Type Directory | Out-Null
206+
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices.VSCode\bin\Core -Type Directory | Out-Null
207+
208+
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.VSCode\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices.VSCode*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices.VSCode\bin\Core\
209+
if (!$script:IsUnix) {
210+
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.VSCode\bin\$Configuration\net451\* -Filter Microsoft.PowerShell.EditorServices.VSCode*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices.VSCode\bin\Desktop\
211+
}
200212
}
201213

202214
task BuildCmdletHelp {
@@ -211,10 +223,10 @@ task PackageNuGet {
211223

212224
task PackageModule {
213225
[System.IO.Compression.ZipFile]::CreateFromDirectory(
214-
"$PSScriptRoot/module/PowerShellEditorServices",
226+
"$PSScriptRoot/module/",
215227
"$PSScriptRoot/module/PowerShellEditorServices-$($script:FullVersion).zip",
216228
[System.IO.Compression.CompressionLevel]::Optimal,
217-
$true)
229+
$false)
218230
}
219231

220232
task UploadArtifacts -If ($script:IsCIBuild) {

PowerShellEditorServices.sln

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.9
4+
VisualStudioVersion = 15.0.26430.12
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F594E7FD-1E72-4E51-A496-B019C2BA3180}"
77
EndProject
@@ -26,6 +26,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.Pr
2626
EndProject
2727
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.Test.Protocol", "test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj", "{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4}"
2828
EndProject
29+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerShellEditorServices.VSCode", "src\PowerShellEditorServices.VSCode\PowerShellEditorServices.VSCode.csproj", "{3B38E8DA-8BFF-4264-AF16-47929E6398A3}"
30+
EndProject
2931
Global
3032
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3133
Debug|Any CPU = Debug|Any CPU
@@ -120,6 +122,18 @@ Global
120122
{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4}.Release|x64.Build.0 = Release|Any CPU
121123
{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4}.Release|x86.ActiveCfg = Release|Any CPU
122124
{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4}.Release|x86.Build.0 = Release|Any CPU
125+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
126+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
127+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Debug|x64.ActiveCfg = Debug|Any CPU
128+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Debug|x64.Build.0 = Debug|Any CPU
129+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Debug|x86.ActiveCfg = Debug|Any CPU
130+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Debug|x86.Build.0 = Debug|Any CPU
131+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
132+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|Any CPU.Build.0 = Release|Any CPU
133+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x64.ActiveCfg = Release|Any CPU
134+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x64.Build.0 = Release|Any CPU
135+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x86.ActiveCfg = Release|Any CPU
136+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3}.Release|x86.Build.0 = Release|Any CPU
123137
EndGlobalSection
124138
GlobalSection(SolutionProperties) = preSolution
125139
HideSolutionNode = FALSE
@@ -132,5 +146,6 @@ Global
132146
{6A20B9E9-DE66-456E-B4F5-ACFD1A95C3CA} = {422E561A-8118-4BE7-A54F-9309E4F03AAE}
133147
{F8A0946A-5D25-4651-8079-B8D5776916FB} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
134148
{E3A5CF5D-6E41-44AC-AE0A-4C227E4BACD4} = {422E561A-8118-4BE7-A54F-9309E4F03AAE}
149+
{3B38E8DA-8BFF-4264-AF16-47929E6398A3} = {F594E7FD-1E72-4E51-A496-B019C2BA3180}
135150
EndGlobalSection
136151
EndGlobal
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#
2+
# Module manifest for module 'PowerShellEditorServices.VSCode'
3+
#
4+
# Generated by: daviwil
5+
#
6+
# Generated on: 6/16/2017
7+
#
8+
9+
@{
10+
11+
# Script module or binary module file associated with this manifest.
12+
RootModule = 'PowerShellEditorServices.VSCode.psm1'
13+
14+
# Version number of this module.
15+
ModuleVersion = '0.1.0'
16+
17+
# Supported PSEditions
18+
# CompatiblePSEditions = @()
19+
20+
# ID used to uniquely identify this module
21+
GUID = '8794484f-cfc3-40f1-b88f-a934f403e679'
22+
23+
# Author of this module
24+
Author = 'Microsoft'
25+
26+
# Company or vendor of this module
27+
CompanyName = 'Microsoft'
28+
29+
# Copyright statement for this module
30+
Copyright = '(c) 2017 Microsoft. All rights reserved.'
31+
32+
# Description of the functionality provided by this module
33+
Description = 'Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.'
34+
35+
# Minimum version of the Windows PowerShell engine required by this module
36+
# PowerShellVersion = ''
37+
38+
# Name of the Windows PowerShell host required by this module
39+
# PowerShellHostName = ''
40+
41+
# Minimum version of the Windows PowerShell host required by this module
42+
# PowerShellHostVersion = ''
43+
44+
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45+
# DotNetFrameworkVersion = ''
46+
47+
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48+
# CLRVersion = ''
49+
50+
# Processor architecture (None, X86, Amd64) required by this module
51+
# ProcessorArchitecture = ''
52+
53+
# Modules that must be imported into the global environment prior to importing this module
54+
# RequiredModules = @()
55+
56+
# Assemblies that must be loaded prior to importing this module
57+
# RequiredAssemblies = @()
58+
59+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60+
# ScriptsToProcess = @()
61+
62+
# Type files (.ps1xml) to be loaded when importing this module
63+
# TypesToProcess = @()
64+
65+
# Format files (.ps1xml) to be loaded when importing this module
66+
# FormatsToProcess = @()
67+
68+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69+
# NestedModules = @()
70+
71+
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72+
FunctionsToExport = @()
73+
74+
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
75+
CmdletsToExport = @()
76+
77+
# Variables to export from this module
78+
VariablesToExport = '*'
79+
80+
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
81+
AliasesToExport = @()
82+
83+
# DSC resources to export from this module
84+
# DscResourcesToExport = @()
85+
86+
# List of all modules packaged with this module
87+
# ModuleList = @()
88+
89+
# List of all files packaged with this module
90+
# FileList = @()
91+
92+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
93+
PrivateData = @{
94+
95+
PSData = @{
96+
97+
# Tags applied to this module. These help with module discovery in online galleries.
98+
# Tags = @()
99+
100+
# A URL to the license for this module.
101+
LicenseUri = 'https://github.com/PowerShell/PowerShellEditorServices/blob/master/LICENSE'
102+
103+
# A URL to the main website for this project.
104+
ProjectUri = 'https://github.com/PowerShell/PowerShellEditorServices'
105+
106+
# A URL to an icon representing this module.
107+
# IconUri = ''
108+
109+
# ReleaseNotes of this module
110+
# ReleaseNotes = ''
111+
112+
} # End of PSData hashtable
113+
114+
} # End of PrivateData hashtable
115+
116+
# HelpInfo URI of this module
117+
# HelpInfoURI = ''
118+
119+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
120+
# DefaultCommandPrefix = ''
121+
122+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) Microsoft. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
#
5+
6+
if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") {
7+
Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.VSCode.dll"
8+
}
9+
else {
10+
Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.VSCode.dll"
11+
}
12+
13+
if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) {
14+
[Microsoft.PowerShell.EditorServices.VSCode.ComponentRegistration]::Register($psEditor.Components)
15+
}
16+
else {
17+
Write-Verbose '$psEditor object not found in the session, components will not be registered.'
18+
}

module/Start-EditorServices.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ $editorServicesHost =
159159
-HostVersion $HostVersion `
160160
-LogPath $LogPath `
161161
-LogLevel $LogLevel `
162+
-AdditionalModules @() `
162163
-LanguageServicePort $languageServicePort `
163164
-DebugServicePort $debugServicePort `
164165
-BundledModulesPath $BundledModulesPath `

src/PowerShellEditorServices.Host/EditorServicesHost.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class EditorServicesHost
4343
private ProfilePaths profilePaths;
4444
private string bundledModulesPath;
4545
private DebugAdapter debugAdapter;
46+
private string[] additionalModules;
4647
private EditorSession editorSession;
4748
private HashSet<string> featureFlags;
4849
private LanguageServer languageServer;
@@ -78,13 +79,15 @@ public EditorServicesHost(
7879
string bundledModulesPath,
7980
bool enableConsoleRepl,
8081
bool waitForDebugger,
82+
string[] additionalModules,
8183
string[] featureFlags)
8284
{
8385
Validate.IsNotNull(nameof(hostDetails), hostDetails);
8486

8587
this.hostDetails = hostDetails;
8688
this.enableConsoleRepl = enableConsoleRepl;
8789
this.bundledModulesPath = bundledModulesPath;
90+
this.additionalModules = additionalModules ?? new string[0];
8891
this.featureFlags = new HashSet<string>(featureFlags ?? new string[0]);
8992

9093
#if DEBUG
@@ -216,6 +219,17 @@ await this.editorSession.PowerShellContext.ImportCommandsModule(
216219
@"..\..\Commands"));
217220

218221
this.languageServer.Start();
222+
223+
// TODO: This can be moved to the point after the $psEditor object
224+
// gets initialized when that is done earlier than LanguageServer.Initialize
225+
foreach (string module in this.additionalModules)
226+
{
227+
await this.editorSession.PowerShellContext.ExecuteCommand<System.Management.Automation.PSObject>(
228+
new System.Management.Automation.PSCommand().AddCommand("Import-Module").AddArgument(module),
229+
false,
230+
true);
231+
}
232+
219233
protocolEndpoint.Start();
220234
}
221235

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using System;
7+
using Microsoft.PowerShell.EditorServices.Components;
8+
using Microsoft.PowerShell.EditorServices.Utility;
9+
10+
namespace Microsoft.PowerShell.EditorServices.VSCode
11+
{
12+
public static class ComponentRegistration
13+
{
14+
public static void Register(IComponentRegistry components)
15+
{
16+
ILogger logger = components.Get<ILogger>();
17+
logger.Write(LogLevel.Normal, "PowerShell Editor Services VS Code module loaded.");
18+
}
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), PowerShellEditorServices.Common.props))\PowerShellEditorServices.Common.props" />
3+
4+
<PropertyGroup>
5+
<AssemblyTitle>PowerShell Editor Services, Visual Studio Code Extensions</AssemblyTitle>
6+
<Description>Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.</Description>
7+
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
8+
<AssemblyName>Microsoft.PowerShell.EditorServices.VSCode</AssemblyName>
9+
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\PowerShellEditorServices\PowerShellEditorServices.csproj" />
14+
<ProjectReference Include="..\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj" />
15+
<ProjectReference Include="..\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj" />
16+
</ItemGroup>
17+
18+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
19+
<DefineConstants>$(DefineConstants);CoreCLR</DefineConstants>
20+
</PropertyGroup>
21+
22+
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
23+
<Reference Include="System" />
24+
<Reference Include="Microsoft.CSharp" />
25+
</ItemGroup>
26+
</Project>

0 commit comments

Comments
 (0)