Skip to content

Commit fd141e3

Browse files
author
Paul van Brenk
committed
Add better support for .jsx
1 parent 855cc41 commit fd141e3

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

Nodejs/Product/Nodejs/NodejsConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Microsoft.NodejsTools
88
internal static class NodejsConstants
99
{
1010
internal const string JavaScriptExtension = ".js";
11+
internal const string JavaScriptJsxExtension = ".jsx";
1112
internal const string TypeScriptExtension = ".ts";
1213
internal const string TypeScriptJsxExtension = ".tsx";
1314
internal const string TypeScriptDeclarationExtension = ".d.ts";

Nodejs/Product/Nodejs/Project/NodejsProjectNode.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ internal static bool IsNodejsFile(string strFileName)
198198
{
199199
var ext = Path.GetExtension(strFileName);
200200

201-
return StringComparer.OrdinalIgnoreCase.Equals(ext, NodejsConstants.JavaScriptExtension);
201+
return StringComparer.OrdinalIgnoreCase.Equals(ext, NodejsConstants.JavaScriptExtension) ||
202+
StringComparer.OrdinalIgnoreCase.Equals(ext, NodejsConstants.JavaScriptJsxExtension);
202203
}
203204

204205
internal override string GetItemType(string filename)
@@ -209,7 +210,7 @@ internal override string GetItemType(string filename)
209210
Path.Combine(this.ProjectHome, filename);
210211

211212
var node = this.FindNodeByFullPath(absFileName) as NodejsFileNode;
212-
if (node != null && node.ItemNode.ItemTypeName != null)
213+
if (node?.ItemNode?.ItemTypeName != null)
213214
{
214215
return node.ItemNode.ItemTypeName;
215216
}
@@ -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
{
@@ -359,7 +367,8 @@ protected override NodeProperties CreatePropertiesObject()
359367
public override bool IsCodeFile(string fileName)
360368
{
361369
var ext = Path.GetExtension(fileName);
362-
return StringComparer.OrdinalIgnoreCase.Equals(NodejsConstants.JavaScriptExtension) ||
370+
return StringComparer.OrdinalIgnoreCase.Equals(ext, NodejsConstants.JavaScriptExtension) ||
371+
StringComparer.OrdinalIgnoreCase.Equals(ext, NodejsConstants.JavaScriptJsxExtension) ||
363372
TypeScriptHelpers.IsTypeScriptFile(fileName);
364373
}
365374

Nodejs/Product/TestAdapter/TestContainerDiscoverer.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ internal bool IsTestFile(string pathToFile)
177177
{
178178
var testCaseFile = pathToFile;
179179
var project = GetTestProjectFromFile(pathToFile);
180-
if (null == project)
180+
if (project == null)
181181
{
182182
//The file is not included in the project.
183183
//Don't look for tests in it.
@@ -198,7 +198,7 @@ internal bool IsTestFile(string pathToFile)
198198
return false;
199199
}
200200
}
201-
else if (!NodejsConstants.JavaScriptExtension.Equals(Path.GetExtension(pathToFile), StringComparison.OrdinalIgnoreCase))
201+
else if (!StringComparer.OrdinalIgnoreCase.Equals(Path.GetExtension(pathToFile), NodejsConstants.JavaScriptExtension))
202202
{
203203
return false;
204204
}
@@ -620,6 +620,18 @@ private IVsProject GetTestProjectFromFile(string filename)
620620
/// <param name="project">The project which the event is being raised for</param>
621621
private bool OnTestContainersChanged(IVsProject project)
622622
{
623+
// https://pytools.codeplex.com/workitem/1271
624+
// When test explorer kicks off a run it kicks off a test discovery
625+
// phase, which kicks off a build, which results in us saving files.
626+
// If we raise the files changed event then test explorer immediately turns
627+
// around and queries us for the changed files. Then it continues
628+
// along with the test discovery phase it was already initiating, and
629+
// discovers that no changes have occured - because it already updated
630+
// to the latest changes when we informed it our containers had changed.
631+
// Therefore if we are both building and detecting changes then we
632+
// don't want to raise the event, instead it'll query us in a little
633+
// bit and get the most recent changes.
634+
623635
if (project != null &&
624636
project.TryGetProjectPath(out var projectPath) &&
625637
this.knownProjects.TryGetValue(projectPath, out var projectInfo) &&

0 commit comments

Comments
 (0)