File tree 12 files changed +126
-15
lines changed
12 files changed +126
-15
lines changed Original file line number Diff line number Diff line change 7
7
' cmd-b' : ' typescript:go-to-declaration'
8
8
' ctrl-;' : ' typescript:context-actions'
9
9
' cmd-;' : ' typescript:context-actions'
10
+ ' f2' : ' typescript:rename-variable'
Original file line number Diff line number Diff line change @@ -23,3 +23,10 @@ function onDiskAndTs(editor) {
23
23
return false ;
24
24
}
25
25
exports . onDiskAndTs = onDiskAndTs ;
26
+ function getFilePathPosition ( ) {
27
+ var editor = atom . workspace . getActiveTextEditor ( ) ;
28
+ var filePath = editor . getPath ( ) ;
29
+ var position = getEditorPosition ( editor ) ;
30
+ return { filePath : filePath , position : position } ;
31
+ }
32
+ exports . getFilePathPosition = getFilePathPosition ;
Original file line number Diff line number Diff line change @@ -30,3 +30,10 @@ export function onDiskAndTs(editor: AtomCore.IEditor) {
30
30
}
31
31
return false ;
32
32
}
33
+
34
+ export function getFilePathPosition ( ) : { filePath : string ; position : number } {
35
+ var editor = atom . workspace . getActiveTextEditor ( ) ;
36
+ var filePath = editor . getPath ( ) ;
37
+ var position = getEditorPosition ( editor ) ;
38
+ return { filePath, position } ;
39
+ }
Original file line number Diff line number Diff line change @@ -83,10 +83,20 @@ function registerCommands() {
83
83
} ) ;
84
84
atom . commands . add ( 'atom-text-editor' , 'typescript:rename-variable' , function ( e ) {
85
85
atom . notifications . addInfo ( 'coming soon. UI test only' ) ;
86
- renameView . panelView . renameThis ( {
87
- text : 'someText' ,
88
- onCancel : function ( ) { return console . log ( 'cancel' ) ; } ,
89
- onCommit : function ( newText ) { return console . log ( newText ) ; }
86
+ parent . getRenameInfo ( atomUtils . getFilePathPosition ( ) ) . then ( function ( res ) {
87
+ if ( ! res . canRename ) {
88
+ atom . notifications . addInfo ( 'AtomTS: Rename not available at cursor location' ) ;
89
+ return ;
90
+ }
91
+ renameView . panelView . renameThis ( {
92
+ text : res . displayName ,
93
+ onCancel : function ( ) {
94
+ console . log ( 'cancel' ) ;
95
+ } ,
96
+ onCommit : function ( newText ) {
97
+ console . log ( newText ) ;
98
+ }
99
+ } ) ;
90
100
} ) ;
91
101
} ) ;
92
102
}
Original file line number Diff line number Diff line change @@ -112,11 +112,30 @@ export function registerCommands() {
112
112
atom . commands . add ( 'atom-text-editor' , 'typescript:rename-variable' , ( e ) => {
113
113
// TODO: get text
114
114
atom . notifications . addInfo ( 'coming soon. UI test only' ) ;
115
- renameView . panelView . renameThis ( {
116
- text : 'someText' ,
117
- onCancel : ( ) => console . log ( 'cancel' ) ,
118
- onCommit : ( newText ) => console . log ( newText )
115
+
116
+ /*function restoreEditor() {
117
+ // TODO: if (activePane.isDestroyed()) return;
118
+
119
+ var v = atom.views.getView(activeEditor);
120
+ v.focus();
121
+ }*/
122
+ parent . getRenameInfo ( atomUtils . getFilePathPosition ( ) ) . then ( ( res ) => {
123
+ if ( ! res . canRename ) {
124
+ atom . notifications . addInfo ( 'AtomTS: Rename not available at cursor location' ) ;
125
+ return ;
126
+ }
127
+ renameView . panelView . renameThis ( {
128
+ text : res . displayName ,
129
+ onCancel : ( ) => {
130
+ console . log ( 'cancel' ) ;
131
+ } ,
132
+ onCommit : ( newText ) => {
133
+ console . log ( newText ) ;
134
+ }
135
+ } ) ;
119
136
} ) ;
137
+
138
+
120
139
} ) ;
121
140
122
141
/// Register autocomplete commands to show documentations
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ var RenameView = (function (_super) {
11
11
__extends ( RenameView , _super ) ;
12
12
function RenameView ( ) {
13
13
_super . apply ( this , arguments ) ;
14
+ this . editorAtRenameStart = null ;
14
15
}
15
16
RenameView . prototype . init = function ( ) {
16
17
var _this = this ;
@@ -38,11 +39,17 @@ var RenameView = (function (_super) {
38
39
} ) ;
39
40
} ;
40
41
RenameView . prototype . clearView = function ( ) {
42
+ if ( this . editorAtRenameStart && ! this . editorAtRenameStart . isDestroyed ( ) ) {
43
+ var view = atom . views . getView ( this . editorAtRenameStart ) ;
44
+ view . focus ( ) ;
45
+ }
41
46
panel . hide ( ) ;
42
47
this . options = { } ;
48
+ this . editorAtRenameStart = null ;
43
49
} ;
44
50
RenameView . prototype . renameThis = function ( options ) {
45
51
this . options = options ;
52
+ this . editorAtRenameStart = atom . workspace . getActiveEditor ( ) ;
46
53
panel . show ( ) ;
47
54
this . newNameEditor . model . setText ( options . text ) ;
48
55
this . newNameEditor . model . selectAll ( ) ;
Original file line number Diff line number Diff line change @@ -44,14 +44,20 @@ export class RenameView
44
44
} ) ;
45
45
}
46
46
47
+ public editorAtRenameStart :AtomCore . IEditor = null ;
47
48
public clearView ( ) {
49
+ if ( this . editorAtRenameStart && ! this . editorAtRenameStart . isDestroyed ( ) ) {
50
+ var view = atom . views . getView ( this . editorAtRenameStart ) ;
51
+ view . focus ( ) ;
52
+ }
48
53
panel . hide ( ) ;
49
54
this . options = < any > { } ;
55
+ this . editorAtRenameStart = null ;
50
56
}
51
57
52
58
public renameThis ( options : RenameViewOptions ) {
53
-
54
59
this . options = options ;
60
+ this . editorAtRenameStart = atom . workspace . getActiveEditor ( ) ;
55
61
panel . show ( ) ;
56
62
this . newNameEditor . model . setText ( options . text ) ;
57
63
this . newNameEditor . model . selectAll ( ) ;
Original file line number Diff line number Diff line change @@ -183,3 +183,23 @@ function errorsForFile(query) {
183
183
return { errors : diagnostics . map ( project . diagnosticToTSError ) } ;
184
184
}
185
185
exports . errorsForFile = errorsForFile ;
186
+ function getRenameInfo ( query ) {
187
+ var project = getOrCreateProject ( query . filePath ) ;
188
+ var info = project . languageService . getRenameInfo ( query . filePath , query . position ) ;
189
+ if ( info && info . canRename ) {
190
+ return {
191
+ canRename : true ,
192
+ localizedErrorMessage : info . localizedErrorMessage ,
193
+ displayName : info . displayName ,
194
+ fullDisplayName : info . fullDisplayName ,
195
+ kind : info . kind ,
196
+ kindModifiers : info . kindModifiers ,
197
+ } ;
198
+ }
199
+ else {
200
+ return {
201
+ canRename : false
202
+ } ;
203
+ }
204
+ }
205
+ exports . getRenameInfo = getRenameInfo ;
Original file line number Diff line number Diff line change @@ -309,3 +309,34 @@ export function errorsForFile(query: FilePathQuery): {
309
309
310
310
return { errors : diagnostics . map ( project . diagnosticToTSError ) } ;
311
311
}
312
+
313
+ export interface GetRenameInfoQuery extends FilePathPositionQuery { }
314
+ export interface GetRenameInfoResponse {
315
+ canRename : boolean ;
316
+ localizedErrorMessage ?: string ;
317
+ displayName ?: string ;
318
+ fullDisplayName ?: string ; // this includes the namespace name
319
+ kind ?: string ;
320
+ kindModifiers ?: string ;
321
+ // TODO: add text span information
322
+ }
323
+ export function getRenameInfo ( query : GetRenameInfoQuery ) : GetRenameInfoResponse {
324
+ var project = getOrCreateProject ( query . filePath ) ;
325
+ var info = project . languageService . getRenameInfo ( query . filePath , query . position ) ;
326
+ if ( info && info . canRename ) {
327
+ return {
328
+ canRename : true ,
329
+ localizedErrorMessage : info . localizedErrorMessage ,
330
+ displayName : info . displayName ,
331
+ fullDisplayName : info . fullDisplayName ,
332
+ kind : info . kind ,
333
+ kindModifiers : info . kindModifiers ,
334
+ // TODO: use info.triggerSpan
335
+ }
336
+ }
337
+ else {
338
+ return {
339
+ canRename : false
340
+ }
341
+ }
342
+ }
Original file line number Diff line number Diff line change @@ -540,7 +540,7 @@ declare module AtomCore {
540
540
subscribeToBuffer ( ) :void ;
541
541
subscribeToDisplayBuffer ( ) :void ;
542
542
getViewClass ( ) :any ; // return type are EditorView
543
- destroyed ( ) :void ;
543
+ isDestroyed ( ) :boolean ;
544
544
copy ( ) :IEditor ;
545
545
getTitle ( ) :string ;
546
546
getLongTitle ( ) :string ;
@@ -777,6 +777,7 @@ declare module AtomCore {
777
777
deserializeParams ( params :any ) :any ;
778
778
getViewClass ( ) :any ; // return type are PaneView
779
779
isActive ( ) :boolean ;
780
+ isDestroyed ( ) :boolean ;
780
781
focus ( ) :void ;
781
782
blur ( ) :void ;
782
783
activate ( ) :void ;
@@ -890,14 +891,14 @@ declare module AtomCore {
890
891
interface IWorkspaceStatic {
891
892
new ( ) :IWorkspace ;
892
893
}
893
-
894
+
894
895
interface IWorkspacePanelOptions {
895
896
item :any ;
896
897
visible ?:boolean ;
897
898
priority ?:number ;
898
899
}
899
-
900
- interface Panel {
900
+
901
+ interface Panel {
901
902
getItem ( ) :any ;
902
903
getPriority ( ) :any ;
903
904
isVisible ( ) :boolean ;
@@ -911,7 +912,7 @@ declare module AtomCore {
911
912
addRightPanel ( options :IWorkspacePanelOptions ) :Panel ;
912
913
addTopPanel ( options :IWorkspacePanelOptions ) :Panel ;
913
914
addModalPanel ( options :IWorkspacePanelOptions ) :Panel ;
914
-
915
+
915
916
deserializeParams ( params :any ) :any ;
916
917
serializeParams ( ) :{ paneContainer :any ; fullScreen :boolean ; } ;
917
918
eachEditor ( callback : Function ) : void ;
@@ -944,7 +945,7 @@ declare module AtomCore {
944
945
itemOpened ( item :any ) :void ;
945
946
onPaneItemDestroyed ( item :any ) :void ;
946
947
destroyed ( ) :void ;
947
-
948
+
948
949
onDidChangeActivePaneItem ( item :any ) :Disposable ;
949
950
}
950
951
Original file line number Diff line number Diff line change @@ -125,3 +125,4 @@ exports.getDefinitionsAtPosition = childQuery(projectService.getDefinitionsAtPos
125
125
exports . updateText = childQuery ( projectService . updateText ) ;
126
126
exports . errorsForFile = childQuery ( projectService . errorsForFile ) ;
127
127
exports . getSignatureHelps = childQuery ( projectService . getSignatureHelps ) ;
128
+ exports . getRenameInfo = childQuery ( projectService . getRenameInfo ) ;
Original file line number Diff line number Diff line change @@ -165,3 +165,4 @@ export var getDefinitionsAtPosition = childQuery(projectService.getDefinitionsAt
165
165
export var updateText = childQuery ( projectService . updateText ) ;
166
166
export var errorsForFile = childQuery ( projectService . errorsForFile ) ;
167
167
export var getSignatureHelps = childQuery ( projectService . getSignatureHelps ) ;
168
+ export var getRenameInfo = childQuery ( projectService . getRenameInfo ) ;
You can’t perform that action at this time.
0 commit comments