1313using System . Threading . Tasks ;
1414using Microsoft . NodejsTools . Npm ;
1515using Microsoft . NodejsTools . ProjectWizard ;
16+ using Microsoft . NodejsTools . TypeScript ;
1617using Microsoft . VisualStudio ;
1718using Microsoft . VisualStudio . Imaging ;
1819using Microsoft . VisualStudio . Imaging . Interop ;
@@ -188,7 +189,7 @@ protected override void AddNewFileNodeToHierarchy(HierarchyNode parentNode, stri
188189
189190 private static bool IsProjectTypeScriptSourceFile ( string path )
190191 {
191- return StringComparer . OrdinalIgnoreCase . Equals ( Path . GetExtension ( path ) , NodejsConstants . TypeScriptExtension )
192+ return TypeScriptHelpers . IsTypeScriptFile ( path )
192193 && ! StringComparer . OrdinalIgnoreCase . Equals ( Path . GetExtension ( path ) , NodejsConstants . TypeScriptDeclarationExtension )
193194 && ! NodejsConstants . ContainsNodeModulesOrBowerComponentsFolder ( path ) ;
194195 }
@@ -197,7 +198,8 @@ internal static bool IsNodejsFile(string strFileName)
197198 {
198199 var ext = Path . GetExtension ( strFileName ) ;
199200
200- return StringComparer . OrdinalIgnoreCase . Equals ( ext , NodejsConstants . JavaScriptExtension ) ;
201+ return StringComparer . OrdinalIgnoreCase . Equals ( ext , NodejsConstants . JavaScriptExtension ) ||
202+ StringComparer . OrdinalIgnoreCase . Equals ( ext , NodejsConstants . JavaScriptJsxExtension ) ;
201203 }
202204
203205 internal override string GetItemType ( string filename )
@@ -208,13 +210,12 @@ internal override string GetItemType(string filename)
208210 Path . Combine ( this . ProjectHome , filename ) ;
209211
210212 var node = this . FindNodeByFullPath ( absFileName ) as NodejsFileNode ;
211- if ( node != null && node . ItemNode . ItemTypeName != null )
213+ if ( node ? . ItemNode ? . ItemTypeName != null )
212214 {
213215 return node . ItemNode . ItemTypeName ;
214216 }
215217
216- // TODO: make sure this also works for .tsx
217- if ( StringComparer . OrdinalIgnoreCase . Equals ( Path . GetExtension ( filename ) , NodejsConstants . TypeScriptExtension ) )
218+ if ( TypeScriptHelpers . IsTypeScriptFile ( filename ) )
218219 {
219220 return NodejsConstants . TypeScriptCompileItemType ;
220221 }
@@ -271,7 +272,14 @@ protected override bool DisableCmdInCurrentMode(Guid commandGroup, uint command)
271272 return false ;
272273 }
273274
274- public override string [ ] CodeFileExtensions => new [ ] { NodejsConstants . JavaScriptExtension } ;
275+ private static readonly string [ ] codeFileExtensions = new [ ] {
276+ NodejsConstants . JavaScriptExtension ,
277+ NodejsConstants . JavaScriptJsxExtension ,
278+ NodejsConstants . TypeScriptExtension ,
279+ NodejsConstants . TypeScriptJsxExtension
280+ } ;
281+
282+ public override string [ ] CodeFileExtensions => codeFileExtensions ;
275283
276284 protected internal override FolderNode CreateFolderNode ( ProjectElement element )
277285 {
@@ -281,13 +289,11 @@ protected internal override FolderNode CreateFolderNode(ProjectElement element)
281289 public override CommonFileNode CreateCodeFileNode ( ProjectElement item )
282290 {
283291 var fileName = item . Url ;
284- if ( ! string . IsNullOrWhiteSpace ( fileName )
285- && Path . GetExtension ( fileName ) . Equals ( NodejsConstants . TypeScriptExtension , StringComparison . OrdinalIgnoreCase ) )
292+ if ( ! string . IsNullOrWhiteSpace ( fileName ) && TypeScriptHelpers . IsTypeScriptFile ( fileName ) )
286293 {
287294 return new NodejsTypeScriptFileNode ( this , item ) ;
288295 }
289- var res = new NodejsFileNode ( this , item ) ;
290- return res ;
296+ return new NodejsFileNode ( this , item ) ;
291297 }
292298
293299 public override string GetProjectName ( )
@@ -361,8 +367,9 @@ protected override NodeProperties CreatePropertiesObject()
361367 public override bool IsCodeFile ( string fileName )
362368 {
363369 var ext = Path . GetExtension ( fileName ) ;
364- return ext . Equals ( NodejsConstants . JavaScriptExtension , StringComparison . OrdinalIgnoreCase ) ||
365- ext . Equals ( NodejsConstants . TypeScriptExtension , StringComparison . OrdinalIgnoreCase ) ;
370+ return StringComparer . OrdinalIgnoreCase . Equals ( ext , NodejsConstants . JavaScriptExtension ) ||
371+ StringComparer . OrdinalIgnoreCase . Equals ( ext , NodejsConstants . JavaScriptJsxExtension ) ||
372+ TypeScriptHelpers . IsTypeScriptFile ( fileName ) ;
366373 }
367374
368375 protected override void Reload ( )
0 commit comments