@@ -5,94 +5,12 @@ function __export(m) {
5
5
var parent = require ( "../../../worker/parent" ) ;
6
6
var atomUtils = require ( "../atomUtils" ) ;
7
7
var autoCompleteProvider = require ( "../autoCompleteProvider" ) ;
8
- var path = require ( "path" ) ;
9
- var renameView = require ( "../views/renameView" ) ;
10
8
var contextView = require ( "../views/contextView" ) ;
11
- var fileSymbolsView = require ( "../views/fileSymbolsView" ) ;
12
- var projectSymbolsView = require ( "../views/projectSymbolsView" ) ;
13
9
var typeOverlayView_1 = require ( "../views/typeOverlayView" ) ;
14
10
var gotoHistory = require ( "../gotoHistory" ) ;
15
- var utils = require ( "../../lang/utils" ) ;
16
11
var mainPanelView_1 = require ( "../views/mainPanelView" ) ;
17
- var astView_1 = require ( "../views/astView" ) ;
18
- var dependencyView_1 = require ( "../views/dependencyView" ) ;
19
- var simpleSelectionView_1 = require ( "../views/simpleSelectionView" ) ;
20
- var escapeHtml = require ( "escape-html" ) ;
21
- var json2dtsCommands_1 = require ( "./json2dtsCommands" ) ;
22
12
__export ( require ( "../components/componentRegistry" ) ) ;
23
13
function registerCommands ( ) {
24
- json2dtsCommands_1 . registerJson2dtsCommands ( ) ;
25
- atom . commands . add ( 'atom-text-editor' , 'typescript:format-code' , function ( e ) {
26
- if ( ! atomUtils . commandForTypeScript ( e ) )
27
- return ;
28
- var editor = atom . workspace . getActiveTextEditor ( ) ;
29
- var filePath = editor . getPath ( ) ;
30
- var selection = editor . getSelectedBufferRange ( ) ;
31
- if ( selection . isEmpty ( ) ) {
32
- parent . formatDocument ( { filePath : filePath } ) . then ( function ( result ) {
33
- if ( ! result . edits . length )
34
- return ;
35
- editor . transact ( function ( ) {
36
- atomUtils . formatCode ( editor , result . edits ) ;
37
- } ) ;
38
- } ) ;
39
- }
40
- else {
41
- parent . formatDocumentRange ( { filePath : filePath , start : { line : selection . start . row , col : selection . start . column } , end : { line : selection . end . row , col : selection . end . column } } ) . then ( function ( result ) {
42
- if ( ! result . edits . length )
43
- return ;
44
- editor . transact ( function ( ) {
45
- atomUtils . formatCode ( editor , result . edits ) ;
46
- } ) ;
47
- } ) ;
48
- }
49
- } ) ;
50
- var handleGoToDeclaration = function ( e ) {
51
- if ( ! atomUtils . commandForTypeScript ( e ) )
52
- return ;
53
- parent . getDefinitionsAtPosition ( atomUtils . getFilePathPosition ( ) ) . then ( function ( res ) {
54
- var definitions = res . definitions ;
55
- if ( ! definitions || ! definitions . length ) {
56
- atom . notifications . addInfo ( 'AtomTS: No definition found.' ) ;
57
- return ;
58
- }
59
- if ( definitions . length > 1 ) {
60
- simpleSelectionView_1 . simpleSelectionView ( {
61
- items : definitions ,
62
- viewForItem : function ( item ) {
63
- return "\n <span>" + item . filePath + "</span>\n <div class=\"pull-right\">line: " + item . position . line + "</div>\n " ;
64
- } ,
65
- filterKey : 'filePath' ,
66
- confirmed : function ( definition ) {
67
- atom . workspace . open ( definition . filePath , {
68
- initialLine : definition . position . line ,
69
- initialColumn : definition . position . col
70
- } ) ;
71
- }
72
- } ) ;
73
- }
74
- else {
75
- var definition = definitions [ 0 ] ;
76
- atom . workspace . open ( definition . filePath , {
77
- initialLine : definition . position . line ,
78
- initialColumn : definition . position . col
79
- } ) ;
80
- }
81
- } ) ;
82
- } ;
83
- atom . commands . add ( 'atom-workspace' , 'typescript:go-to-declaration' , handleGoToDeclaration ) ;
84
- atom . commands . add ( 'atom-text-editor' , 'symbols-view:go-to-declaration' , handleGoToDeclaration ) ;
85
- atom . commands . add ( 'atom-workspace' , 'typescript:create-tsconfig.json-project-file' , function ( e ) {
86
- if ( ! atomUtils . commandForTypeScript ( e ) )
87
- return ;
88
- var editor = atom . workspace . getActiveTextEditor ( ) ;
89
- var filePath = editor . getPath ( ) ;
90
- parent . createProject ( { filePath : filePath } ) . then ( function ( res ) {
91
- if ( res . createdFilePath ) {
92
- atom . notifications . addSuccess ( "tsconfig.json file created: <br/> " + res . createdFilePath ) ;
93
- }
94
- } ) ;
95
- } ) ;
96
14
var theContextView ;
97
15
atom . commands . add ( 'atom-text-editor' , 'typescript:context-actions' , function ( e ) {
98
16
if ( ! theContextView )
@@ -102,54 +20,6 @@ function registerCommands() {
102
20
atom . commands . add ( 'atom-text-editor' , 'typescript:autocomplete' , function ( e ) {
103
21
autoCompleteProvider . triggerAutocompletePlus ( ) ;
104
22
} ) ;
105
- atom . commands . add ( 'atom-text-editor' , 'typescript:rename-refactor' , function ( e ) {
106
- var editor = atom . workspace . getActiveTextEditor ( ) ;
107
- if ( true ) {
108
- parent . getRenameInfo ( atomUtils . getFilePathPosition ( ) ) . then ( function ( res ) {
109
- if ( ! res . canRename ) {
110
- atom . notifications . addInfo ( 'AtomTS: Rename not available at cursor location' ) ;
111
- return ;
112
- }
113
- var paths = atomUtils . getOpenTypeScritEditorsConsistentPaths ( ) ;
114
- var openPathsMap = utils . createMap ( paths ) ;
115
- var refactorPaths = Object . keys ( res . locations ) ;
116
- var openFiles = refactorPaths . filter ( function ( p ) { return openPathsMap [ p ] ; } ) ;
117
- var closedFiles = refactorPaths . filter ( function ( p ) { return ! openPathsMap [ p ] ; } ) ;
118
- renameView . panelView . renameThis ( {
119
- autoSelect : true ,
120
- title : 'Rename Variable' ,
121
- text : res . displayName ,
122
- openFiles : openFiles ,
123
- closedFiles : closedFiles ,
124
- onCancel : function ( ) { } ,
125
- onValidate : function ( newText ) {
126
- if ( newText . replace ( / \s / g, '' ) !== newText . trim ( ) ) {
127
- return 'The new variable must not contain a space' ;
128
- }
129
- if ( ! newText . trim ( ) ) {
130
- return 'If you want to abort : Press esc to exit' ;
131
- }
132
- return '' ;
133
- } ,
134
- onCommit : function ( newText ) {
135
- newText = newText . trim ( ) ;
136
- atomUtils . getEditorsForAllPaths ( Object . keys ( res . locations ) )
137
- . then ( function ( editorMap ) {
138
- Object . keys ( res . locations ) . forEach ( function ( filePath ) {
139
- var editor = editorMap [ filePath ] ;
140
- editor . transact ( function ( ) {
141
- res . locations [ filePath ] . forEach ( function ( textSpan ) {
142
- var range = atomUtils . getRangeForTextSpan ( editor , textSpan ) ;
143
- editor . setTextInBufferRange ( range , newText ) ;
144
- } ) ;
145
- } ) ;
146
- } ) ;
147
- } ) ;
148
- }
149
- } ) ;
150
- } ) ;
151
- }
152
- } ) ;
153
23
atom . commands . add ( 'atom-workspace' , 'typescript:show-type' , function ( e ) {
154
24
var editor = atom . workspace . getActiveTextEditor ( ) ;
155
25
var editorView = atom . views . getView ( editor ) ;
@@ -190,105 +60,6 @@ function registerCommands() {
190
60
atom . commands . add ( 'atom-workspace' , 'typescript:go-to-previous' , function ( e ) {
191
61
gotoHistory . gotoPrevious ( ) ;
192
62
} ) ;
193
- atom . commands . add ( 'atom-workspace' , 'typescript:find-references' , function ( e ) {
194
- if ( ! atomUtils . commandForTypeScript ( e ) )
195
- return ;
196
- parent . getReferences ( atomUtils . getFilePathPosition ( ) ) . then ( function ( res ) {
197
- mainPanelView_1 . panelView . setReferences ( res . references ) ;
198
- simpleSelectionView_1 . simpleSelectionView ( {
199
- items : res . references ,
200
- viewForItem : function ( item ) {
201
- return "<div>\n <span>" + atom . project . relativize ( item . filePath ) + "</span>\n <div class=\"pull-right\">line: " + ( item . position . line + 1 ) + "</div>\n <ts-view>" + escapeHtml ( item . preview ) + "</ts-view>\n <div>" ;
202
- } ,
203
- filterKey : utils . getName ( function ( ) { return res . references [ 0 ] . filePath ; } ) ,
204
- confirmed : function ( definition ) {
205
- atom . workspace . open ( definition . filePath , {
206
- initialLine : definition . position . line ,
207
- initialColumn : definition . position . col
208
- } ) ;
209
- }
210
- } ) ;
211
- } ) ;
212
- } ) ;
213
- var theFileSymbolsView ;
214
- var showFileSymbols = utils . debounce ( function ( filePath ) {
215
- if ( ! theFileSymbolsView )
216
- theFileSymbolsView = new fileSymbolsView . FileSymbolsView ( ) ;
217
- parent . getNavigationBarItems ( { filePath : filePath } ) . then ( function ( res ) {
218
- theFileSymbolsView . setNavBarItems ( res . items , filePath ) ;
219
- theFileSymbolsView . show ( ) ;
220
- } ) ;
221
- } , 400 ) ;
222
- atom . commands . add ( '.platform-linux atom-text-editor, .platform-darwin atom-text-editor,.platform-win32 atom-text-editor' , 'symbols-view:toggle-file-symbols' , function ( e ) {
223
- var editor = atom . workspace . getActiveTextEditor ( ) ;
224
- if ( ! editor )
225
- return false ;
226
- if ( path . extname ( editor . getPath ( ) ) !== '.ts' && path . extname ( editor . getPath ( ) ) !== '.tsx' )
227
- return false ;
228
- e . abortKeyBinding ( ) ;
229
- var filePath = editor . getPath ( ) ;
230
- showFileSymbols ( filePath ) ;
231
- } ) ;
232
- var theProjectSymbolsView ;
233
- var showProjectSymbols = utils . debounce ( function ( filePath ) {
234
- if ( ! theProjectSymbolsView )
235
- theProjectSymbolsView = new projectSymbolsView . ProjectSymbolsView ( ) ;
236
- parent . getNavigateToItems ( { filePath : filePath } ) . then ( function ( res ) {
237
- theProjectSymbolsView . setNavBarItems ( res . items ) ;
238
- theProjectSymbolsView . show ( ) ;
239
- } ) ;
240
- } , 400 ) ;
241
- atom . commands . add ( 'atom-text-editor' , 'symbols-view:toggle-project-symbols' , function ( e ) {
242
- var editor = atom . workspace . getActiveTextEditor ( ) ;
243
- if ( ! editor )
244
- return false ;
245
- if ( path . extname ( editor . getPath ( ) ) !== '.ts' )
246
- return false ;
247
- e . abortKeyBinding ( ) ;
248
- var filePath = editor . getPath ( ) ;
249
- showProjectSymbols ( filePath ) ;
250
- } ) ;
251
- atomUtils . registerOpener ( {
252
- commandSelector : 'atom-text-editor' ,
253
- commandName : 'typescript:ast' ,
254
- uriProtocol : astView_1 . astURI ,
255
- getData : function ( ) {
256
- return {
257
- text : atom . workspace . getActiveTextEditor ( ) . getText ( ) ,
258
- filePath : atomUtils . getCurrentPath ( )
259
- } ;
260
- } ,
261
- onOpen : function ( data ) {
262
- return new astView_1 . AstView ( data . filePath , data . text , false ) ;
263
- }
264
- } ) ;
265
- atomUtils . registerOpener ( {
266
- commandSelector : 'atom-text-editor' ,
267
- commandName : 'typescript:ast-full' ,
268
- uriProtocol : astView_1 . astURIFull ,
269
- getData : function ( ) {
270
- return {
271
- text : atom . workspace . getActiveTextEditor ( ) . getText ( ) ,
272
- filePath : atomUtils . getCurrentPath ( )
273
- } ;
274
- } ,
275
- onOpen : function ( data ) {
276
- return new astView_1 . AstView ( data . filePath , data . text , true ) ;
277
- }
278
- } ) ;
279
- atomUtils . registerOpener ( {
280
- commandSelector : 'atom-workspace' ,
281
- commandName : 'typescript:dependency-view' ,
282
- uriProtocol : dependencyView_1 . dependencyURI ,
283
- getData : function ( ) {
284
- return {
285
- filePath : atomUtils . getCurrentPath ( )
286
- } ;
287
- } ,
288
- onOpen : function ( data ) {
289
- return new dependencyView_1 . DependencyView ( data . filePath ) ;
290
- }
291
- } ) ;
292
63
atom . commands . add ( 'atom-workspace' , 'typescript:sync' , function ( e ) {
293
64
if ( ! atomUtils . commandForTypeScript ( e ) )
294
65
return ;
0 commit comments