@@ -3,8 +3,37 @@ import * as clipboard from 'copy-paste';
3
3
import { LanguageClient , RequestType , NotificationType } from 'vscode-languageclient' ;
4
4
import Window = vscode . window ;
5
5
6
+ export namespace ConvertToCSharpClassRequest {
7
+ export const type : RequestType < string , any , void > = { get method ( ) { return 'powerShell/convertToCSharpClass' ; } } ;
8
+ }
9
+
10
+ export namespace ConvertToPowerShellClassRequest {
11
+ export const type : RequestType < string , any , void > = { get method ( ) { return 'powerShell/convertToPowerShellClass' ; } } ;
12
+ }
13
+
6
14
export function registerPowerShellPasteAsClass ( client : LanguageClient ) : void {
7
15
var disposable = vscode . commands . registerCommand ( 'PowerShell.PowerShellPasteAsClass' , ( ) => {
8
- Window . showInformationMessage ( clipboard . paste ( ) ) ;
16
+ let items : vscode . QuickPickItem [ ] = [ ] ;
17
+ items . push ( { label : 'PowerShell' , description : 'Paste from clipboard as a PowerShell class' } ) ;
18
+ items . push ( { label : 'C#' , description : 'Paste from clipboard as a C# class' } ) ;
19
+
20
+ vscode . window . showQuickPick ( items ) . then ( ( qpSelection ) => {
21
+ if ( ! qpSelection ) {
22
+ return ;
23
+ }
24
+
25
+ var targetRequest = ConvertToPowerShellClassRequest . type ;
26
+ if ( qpSelection . label == 'C#' ) {
27
+ targetRequest = ConvertToCSharpClassRequest . type ;
28
+ }
29
+
30
+ client . sendRequest ( targetRequest , clipboard . paste ( ) ) . then ( ( result ) => {
31
+ var editor = Window . activeTextEditor ;
32
+ var selection = editor . selection ;
33
+ editor . edit ( ( editBuilder ) => {
34
+ editBuilder . insert ( new vscode . Position ( selection . start . line , 0 ) , result )
35
+ } ) ;
36
+ } ) ;
37
+ } ) ;
9
38
} ) ;
10
39
}
0 commit comments