Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Nodejs/Product/Nodejs/NodejsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows.Forms;
Expand Down Expand Up @@ -109,6 +110,16 @@ internal sealed partial class NodejsPackage : CommonPackage {
// after the initialization
private List<EnvDTE.CommandEvents> _subscribedCommandEvents = new List<EnvDTE.CommandEvents>();

private static readonly Version _minRequiredTypescriptVersion = new Version("1.8");

private readonly Lazy<bool> _hasRequiredTypescriptVersion = new Lazy<bool>(() => {
Version version;
var versionString = GetTypeScriptToolsVersion();
return !string.IsNullOrEmpty(versionString)
&& Version.TryParse(versionString, out version)
&& version.CompareTo(_minRequiredTypescriptVersion) > -1;
});

/// <summary>
/// Default constructor of the package.
/// Inside this method you can place any initialization code that does not require
Expand Down Expand Up @@ -188,6 +199,14 @@ protected override void Initialize() {
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();

if (!_hasRequiredTypescriptVersion.Value) {
MessageBox.Show(
Project.SR.GetString(Project.SR.TypeScriptMinVersionNotInstalled, _minRequiredTypescriptVersion.ToString()),
Project.SR.ProductName,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

SubscribeToVsCommandEvents(
(int)VSConstants.VSStd97CmdID.AddNewProject,
delegate { NewProjectFromExistingWizard.IsAddNewProjectCmd = true; },
Expand Down Expand Up @@ -616,5 +635,43 @@ private void LogLooseFileAnalysisLevel() {
_logger.LogEvent(NodejsToolsLogEvent.AnalysisLevel, (int)val);
}
}

private static string GetTypeScriptToolsVersion() {
var toolsVersion = string.Empty;
try {
object installDirAsObject = null;
var shell = NodejsPackage.Instance.GetService(typeof(SVsShell)) as IVsShell;
if (shell != null) {
shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory, out installDirAsObject);
}

var idePath = CommonUtils.NormalizeDirectoryPath((string)installDirAsObject) ?? string.Empty;
if (string.IsNullOrEmpty(idePath)) {
return toolsVersion;
}

var typeScriptServicesPath = Path.Combine(idePath, @"CommonExtensions\Microsoft\TypeScript\typescriptServices.js");
if (!File.Exists(typeScriptServicesPath)) {
return toolsVersion;
}

var regex = new Regex(@"toolsVersion = ""(?<version>\d.\d?)"";");
var fileText = File.ReadAllText(typeScriptServicesPath);
var match = regex.Match(fileText);

var version = match.Groups["version"].Value;
if (!string.IsNullOrWhiteSpace(version)) {
toolsVersion = version;
}
} catch (Exception ex) {
if (ex.IsCriticalException()) {
throw;
}

Debug.WriteLine(string.Format("Failed to obtain TypeScript tools version: {0}", ex.ToString()));
}

return toolsVersion;
}
}
}
38 changes: 0 additions & 38 deletions Nodejs/Product/Nodejs/Options/NodejsIntellisenseOptionsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,43 +88,5 @@ public override void SaveSettingsToStorage() {
SaveBool(ShowTypingsInfoBarSetting, ShowTypingsInfoBar);
SaveBool(SaveChangesToConfigFileSetting, SaveChangesToConfigFile);
}

private static string GetTypeScriptToolsVersion() {
var toolsVersion = string.Empty;
try {
object installDirAsObject = null;
var shell = NodejsPackage.Instance.GetService(typeof(SVsShell)) as IVsShell;
if (shell != null) {
shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory, out installDirAsObject);
}

var idePath = CommonUtils.NormalizeDirectoryPath((string)installDirAsObject) ?? string.Empty;
if (string.IsNullOrEmpty(idePath)) {
return toolsVersion;
}

var typeScriptServicesPath = Path.Combine(idePath, @"CommonExtensions\Microsoft\TypeScript\typescriptServices.js");
if (!File.Exists(typeScriptServicesPath)) {
return toolsVersion;
}

var regex = new Regex(@"toolsVersion = ""(?<version>\d.\d?)"";");
var fileText = File.ReadAllText(typeScriptServicesPath);
var match = regex.Match(fileText);

var version = match.Groups["version"].Value;
if (!string.IsNullOrWhiteSpace(version)) {
toolsVersion = version;
}
} catch (Exception ex) {
if (ex.IsCriticalException()) {
throw;
}

Debug.WriteLine(string.Format("Failed to obtain TypeScript tools version: {0}", ex.ToString()));
}

return toolsVersion;
}
}
}
1 change: 1 addition & 0 deletions Nodejs/Product/Nodejs/Project/ProjectResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ internal class SR : CommonSR {
internal const string TypingsInfoBarSpan2 = "TypingsInfoBarSpan2";
internal const string TypingsInfoBarSpan3 = "TypingsInfoBarSpan3";
internal const string TypingsOpenOptionsText = "TypingsOpenOptionsText";
internal const string TypeScriptMinVersionNotInstalled = "TypeScriptMinVersionNotInstalled";
internal const string TypingsToolCouldNotStart = "TypingsToolCouldNotStart";
internal const string TypingsToolInstallFailed = "TypingsToolInstallFailed";
internal const string TypingsToolNotInstalledError = "TypingsToolNotInstalledError";
Expand Down
3 changes: 3 additions & 0 deletions Nodejs/Product/Nodejs/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,7 @@ You will need to restart Visual Studio after installation.</value>
<data name="CouldNotGetTypeScriptLanguagePreferences" xml:space="preserve">
<value>Could not retrieve Typescript language preferences. NTVS is not able to load. Please ensure Typescript is properly installed.</value>
</data>
<data name="TypeScriptMinVersionNotInstalled" xml:space="preserve">
<value>Node.js Tools requires TypeScript for Visual Studio {0} or higher. Please ensure TypeScript is installed</value>
</data>
</root>