11import vscode = require( 'vscode' ) ;
22import { LanguageClient , RequestType , NotificationType } from 'vscode-languageclient' ;
33import Window = vscode . window ;
4+ import { IFeature } from '../feature' ;
45
5- export function registerCodeActionCommands ( client : LanguageClient ) : void {
6- vscode . commands . registerCommand ( 'PowerShell.ApplyCodeActionEdits' , ( edit : any ) => {
7- console . log ( "Applying edits" ) ;
8- console . log ( edit ) ;
9- var editor = Window . activeTextEditor ;
10- var filePath = editor . document . fileName ;
11- var workspaceEdit = new vscode . WorkspaceEdit ( ) ;
12- workspaceEdit . set (
13- vscode . Uri . file ( filePath ) ,
14- [
15- new vscode . TextEdit (
16- new vscode . Range (
17- edit . StartLineNumber - 1 ,
18- edit . StartColumnNumber - 1 ,
19- edit . EndLineNumber - 1 ,
20- edit . EndColumnNumber - 1 ) ,
21- edit . Text )
22- ] ) ;
23- vscode . workspace . applyEdit ( workspaceEdit ) ;
24- } ) ;
6+ export class CodeActionsFeature implements IFeature {
7+ private command : vscode . Disposable ;
8+ private languageClient : LanguageClient ;
9+
10+ constructor ( ) {
11+ this . command = vscode . commands . registerCommand ( 'PowerShell.ApplyCodeActionEdits' , ( edit : any ) => {
12+ var editor = Window . activeTextEditor ;
13+ var filePath = editor . document . fileName ;
14+ var workspaceEdit = new vscode . WorkspaceEdit ( ) ;
15+ workspaceEdit . set (
16+ vscode . Uri . file ( filePath ) ,
17+ [
18+ new vscode . TextEdit (
19+ new vscode . Range (
20+ edit . StartLineNumber - 1 ,
21+ edit . StartColumnNumber - 1 ,
22+ edit . EndLineNumber - 1 ,
23+ edit . EndColumnNumber - 1 ) ,
24+ edit . Text )
25+ ] ) ;
26+ vscode . workspace . applyEdit ( workspaceEdit ) ;
27+ } ) ;
28+ }
29+
30+ public setLanguageClient ( languageclient : LanguageClient ) {
31+ this . languageClient = languageclient ;
32+ }
33+
34+ public dispose ( ) {
35+ this . command . dispose ( ) ;
36+ }
2537}
0 commit comments