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
6 changes: 4 additions & 2 deletions Nodejs/Product/Nodejs/Guids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static class Guids {
public const string NodejsNpmCmdSetString = "9F4B31B4-09AC-4937-A2E7-F4BC02BB7DBA";
public const string NodejsProjectFactoryString = "3AF33F2E-1136-4D97-BBB7-1795711AC8B8";
public const string NodejsBaseProjectFactoryString = "9092AA53-FB77-4645-B42D-1CCCA6BD08BD";
public const string TypeScriptLanguageInfoString = "87bdf188-e6e8-4fcf-a82a-9b8506e01847";
public const string TypeScriptLanguageInfoString = "4a0dddb5-7a95-4fbf-97cc-616d07737a77";
public const string TypeScriptDebuggerLanguageInfoString = "87bdf188-e6e8-4fcf-a82a-9b8506e01847";
public const string JadeEditorFactoryString = "6CB69EF8-1329-4DC0-84B4-FA134EA59BE3";
public const string DefaultLanguageServiceString = "{8239BEC4-EE87-11D0-8C98-00C04FC2AB22}";

Expand All @@ -60,7 +61,8 @@ static class Guids {
public static readonly Guid NodejsEditorFactory = new Guid(NodejsEditorFactoryString);
public static readonly Guid NodejsDebugLanguage = new Guid(NodejsDebugLanguageString);
public static readonly Guid NodejsNpmCmdSet = new Guid(NodejsNpmCmdSetString);
public static readonly Guid TypeScriptDebugLanguage = new Guid(TypeScriptLanguageInfoString);
public static readonly Guid TypeScriptLanguageInfo = new Guid(TypeScriptLanguageInfoString);
public static readonly Guid TypeScriptDebugLanguage = new Guid(TypeScriptDebuggerLanguageInfoString);

public static readonly Guid ScriptDebugLanguage = new Guid(ScriptDebugLanguageString);

Expand Down
25 changes: 16 additions & 9 deletions Nodejs/Product/Nodejs/LanguagePreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
//
//*********************************************************//

using System;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.TextManager.Interop;

namespace Microsoft.NodejsTools {
class LanguagePreferences : IVsTextManagerEvents2 {
LANGPREFERENCES _preferences;
class LanguagePreferences : IVsTextManagerEvents4 {
internal LANGPREFERENCES3 _preferences;

public LanguagePreferences(LANGPREFERENCES preferences) {
public LanguagePreferences(LANGPREFERENCES3 preferences) {
_preferences = preferences;
}

Expand All @@ -47,12 +48,18 @@ public int OnUnregisterView(IVsTextView pView) {
return VSConstants.S_OK;
}

public int OnUserPreferencesChanged2(VIEWPREFERENCES2[] viewPrefs, FRAMEPREFERENCES2[] framePrefs, LANGPREFERENCES2[] langPrefs, FONTCOLORPREFERENCES2[] colorPrefs) {
if (langPrefs != null && langPrefs.Length > 0 && langPrefs[0].guidLang == this._preferences.guidLang) {
_preferences.IndentStyle = langPrefs[0].IndentStyle;
_preferences.fAutoListMembers = langPrefs[0].fAutoListMembers;
_preferences.fAutoListParams = langPrefs[0].fAutoListParams;
_preferences.fHideAdvancedAutoListMembers = langPrefs[0].fHideAdvancedAutoListMembers;
public int OnUserPreferencesChanged4(VIEWPREFERENCES3[] pViewPrefs, LANGPREFERENCES3[] pLangPrefs, FONTCOLORPREFERENCES2[] pColorPrefs) {
IVsTextManager4 textMgr = (IVsTextManager4)NodejsPackage.Instance.GetService(typeof(SVsTextManager));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can textMgr ever be null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't null check anywhere, and I wouldn't expect it to ever be null (except maybe inside of some of the mock test cases?)


if (pLangPrefs != null && pLangPrefs.Length > 0 && pLangPrefs[0].guidLang == _preferences.guidLang) {
_preferences.IndentStyle = pLangPrefs[0].IndentStyle;
_preferences.fAutoListMembers = pLangPrefs[0].fAutoListMembers;
_preferences.fAutoListParams = pLangPrefs[0].fAutoListParams;
_preferences.fHideAdvancedAutoListMembers = pLangPrefs[0].fHideAdvancedAutoListMembers;

// Synchronize settings back to TS language service
pLangPrefs[0].guidLang = Guids.TypeScriptLanguageInfo;
textMgr.SetUserPreferences4(null, pLangPrefs, null);
}
return VSConstants.S_OK;
}
Expand Down
18 changes: 12 additions & 6 deletions Nodejs/Product/Nodejs/Nodejs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
<Reference Include="envdte80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="microsoft.visualstudio.textmanager.interop.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.TextManager.Interop.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
Expand Down Expand Up @@ -155,12 +161,8 @@
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.11.0">
<EmbedInteropTypes>true</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" Condition="'$(VSTarget)' != '11.0'">
<EmbedInteropTypes>true</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.VisualStudio.Shell.Interop.11.0" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.TemplateWizardInterface, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.Text.Data, Version=$(VSTarget).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.Text.Logic, Version=$(VSTarget).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Expand Down Expand Up @@ -321,6 +323,10 @@
</Compile>
<Compile Include="NpmUI\PackageCatalogEntryViewModel.cs" />
<Compile Include="Options\AnalysisLevel.cs" />
<Compile Include="Options\NodejsFormattingDialogPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Options\TypeScriptRegistrySwitches.cs" />
<Compile Include="Options\TypingsInfoBar.cs" />
<Compile Include="Options\NodejsDiagnosticsOptionsPage.cs">
<SubType>Component</SubType>
Expand Down
22 changes: 13 additions & 9 deletions Nodejs/Product/Nodejs/NodejsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using Microsoft.NodejsTools.Analysis;
using Microsoft.NodejsTools.Commands;
using Microsoft.NodejsTools.Debugger.DataTips;
using Microsoft.NodejsTools.Debugger.DebugEngine;
Expand All @@ -41,7 +39,6 @@
using Microsoft.NodejsTools.Telemetry;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Debugger.Interop;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
Expand Down Expand Up @@ -200,7 +197,7 @@ protected override void Initialize() {
delegate { NewProjectFromExistingWizard.IsAddNewProjectCmd = false; }
);

var langService = new NodejsLanguageInfo(this);
var langService = new NodejsLanguageInfo(this);
((IServiceContainer)this).AddService(langService.GetType(), langService, true);

((IServiceContainer)this).AddService(typeof(ClipboardServiceBase), new ClipboardService(), true);
Expand All @@ -225,14 +222,12 @@ protected override void Initialize() {
}
RegisterCommands(commands, Guids.NodejsCmdSet);

IVsTextManager textMgr = (IVsTextManager)Instance.GetService(typeof(SVsTextManager));
IVsTextManager4 textMgr = (IVsTextManager4)Instance.GetService(typeof(SVsTextManager));

var langPrefs = new LANGPREFERENCES[1];
langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences(null, null, langPrefs, null));
LANGPREFERENCES3[] langPrefs = GetNodejsLanguagePreferencesFromTypeScript(textMgr);
_langPrefs = new LanguagePreferences(langPrefs[0]);

var textManagerEvents2Guid = typeof(IVsTextManagerEvents2).GUID;
var textManagerEvents2Guid = typeof(IVsTextManagerEvents4).GUID;
IConnectionPoint textManagerEvents2ConnectionPoint;
((IConnectionPointContainer)textMgr).FindConnectionPoint(ref textManagerEvents2Guid, out textManagerEvents2ConnectionPoint);
uint cookie;
Expand All @@ -256,6 +251,15 @@ protected override void Initialize() {
Environment.SetEnvironmentVariable(NodejsConstants.NodeToolsProcessIdEnvironmentVariable, Process.GetCurrentProcess().Id.ToString());
}

private static LANGPREFERENCES3[] GetNodejsLanguagePreferencesFromTypeScript(IVsTextManager4 textMgr) {
var langPrefs = new LANGPREFERENCES3[1];
langPrefs[0].guidLang = Guids.TypeScriptLanguageInfo;
ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences4(null, langPrefs, null));
langPrefs[0].guidLang = typeof(NodejsLanguageInfo).GUID;
textMgr.SetUserPreferences4(null, langPrefs, null);
return langPrefs;
}

private void SubscribeToVsCommandEvents(
int eventId,
EnvDTE._dispCommandEvents_BeforeExecuteEventHandler beforeExecute = null,
Expand Down
4 changes: 2 additions & 2 deletions Nodejs/Product/Nodejs/Options/NodejsDialogPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal NodejsDialogPage(string category) {
_category = category;
}

internal void SaveBool(string name, bool value) {
internal virtual void SaveBool(string name, bool value) {
SaveString(name, value.ToString());
}

Expand Down Expand Up @@ -80,7 +80,7 @@ internal void SaveDateTime(string name, DateTime value) {
return null;
}

internal bool? LoadBool(string name) {
internal virtual bool? LoadBool(string name) {
string res = LoadString(name);
if (res == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
//
//*********************************************************//

using System;
using System.Runtime.InteropServices;

namespace Microsoft.NodejsTools.Options {
[ComVisible(true)]
public class NodejsFormattingBracesOptionsPage : NodejsDialogPage {
public class NodejsFormattingBracesOptionsPage : NodejsFormattingDialogPage {
private NodejsFormattingBracesOptionsControl _window;

public NodejsFormattingBracesOptionsPage()
Expand Down Expand Up @@ -51,8 +50,8 @@ public override void ResetSettings(){
BraceOnNewLineForFunctions = BraceOnNewLineForControlBlocks = false;
}

private const string BraceOnNewLineForFunctionsSetting = "BraceOnNewLineForFunctions";
private const string BraceOnNewLineForControlBlocksSetting = "BraceOnNewLineForControlBlocks";
private const string BraceOnNewLineForFunctionsSetting = TypeScriptRegistrySwitches.PlaceOpenBraceOnNewLineForFunctions;
private const string BraceOnNewLineForControlBlocksSetting = TypeScriptRegistrySwitches.PlaceOpenBraceOnNewLineForControlBlocks;

public override void LoadSettingsFromStorage(){
// Load settings from storage.
Expand Down
60 changes: 60 additions & 0 deletions Nodejs/Product/Nodejs/Options/NodejsFormattingDialogPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//*********************************************************//
// Copyright (c) Microsoft. All rights reserved.
//
// Apache 2.0 License
//
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//*********************************************************//

using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Settings;
using Microsoft.VisualStudio.Shell.Interop;

namespace Microsoft.NodejsTools.Options {
public class NodejsFormattingDialogPage : NodejsDialogPage {
private readonly ISettingsManager _settingsManager;
private const string TypeScriptBaseName = "TextEditor.TypeScript.Specific.";

public NodejsFormattingDialogPage(string category) : base(category) {
uint handle;
string registryRoot;
var registry = NodejsPackage.Instance.GetService(typeof(SLocalRegistry)) as ILocalRegistry4;
var regKey = registry.GetLocalRegistryRootEx((uint)__VsLocalRegistryType.RegType_UserSettings, out handle, out registryRoot);
_settingsManager = (ISettingsManager)NodejsPackage.Instance.GetService(typeof(SVsSettingsPersistenceManager));
}

internal override void SaveBool(string name, bool value) {
var keyName = GetKeyName(name);
var registryValue = value ? 1 : 0;
_settingsManager.SetValueAsync(keyName, registryValue, isMachineLocal: false);
}

internal override bool? LoadBool(string name) {
var value = _settingsManager.GetValueOrDefault<int?>(GetKeyName(name));
if (value == null) {
return null;
} else {
return value != 0;
}
}

private static string GetKeyName(string name) {
if (name.EndsWith("_TEMP")) {
name = name.Remove(name.Length - 5);
}
return TypeScriptBaseName + name;
}

[Guid("9B164E40-C3A2-4363-9BC5-EB4039DEF653")]
private class SVsSettingsPersistenceManager { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
//
//*********************************************************//

using System;
using System.Runtime.InteropServices;

namespace Microsoft.NodejsTools.Options {
[ComVisible(true)]
public class NodejsFormattingGeneralOptionsPage : NodejsDialogPage {
public class NodejsFormattingGeneralOptionsPage : NodejsFormattingDialogPage {
private NodejsFormattingGeneralOptionsControl _window;

public NodejsFormattingGeneralOptionsPage()
Expand Down Expand Up @@ -51,10 +50,10 @@ public override void ResetSettings(){
FormatOnEnter = FormatOnSemiColon = FormatOnCloseBrace = FormatOnPaste = true;
}

private const string FormatOnEnterSetting = "FormatOnEnter";
private const string FormatOnSemiColonSetting = "FormatOnSemiColon";
private const string FormatOnCloseBraceSetting = "FormatOnCloseBrace";
private const string FormatOnPasteSetting = "FormatOnPaste";
private const string FormatOnEnterSetting = TypeScriptRegistrySwitches.FormatCompletedLineOnEnter;
private const string FormatOnSemiColonSetting = TypeScriptRegistrySwitches.FormatCompletedStatementOnSemicolon;
private const string FormatOnCloseBraceSetting = TypeScriptRegistrySwitches.FormatCompletedBlockOnRightCurlyBrace;
private const string FormatOnPasteSetting = TypeScriptRegistrySwitches.FormatOnPaste;

public override void LoadSettingsFromStorage(){
// Load settings from storage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
//
//*********************************************************//

using System;
using System.Runtime.InteropServices;

namespace Microsoft.NodejsTools.Options {
[ComVisible(true)]
public class NodejsFormattingSpacingOptionsPage : NodejsDialogPage {
public class NodejsFormattingSpacingOptionsPage : NodejsFormattingDialogPage {
private NodejsFormattingSpacingOptionsControl _window;

public NodejsFormattingSpacingOptionsPage()
Expand Down Expand Up @@ -54,12 +53,12 @@ public override void ResetSettings() {
SpaceAfterOpeningAndBeforeClosingNonEmptyParens = false;
}

private const string SpaceAfterCommaSetting = "SpaceAfterComma";
private const string SpaceAfterSemicolonInForSetting = "SpaceAfterSemicolonInFor";
private const string SpaceBeforeAndAfterBinaryOperatorSetting = "SpaceBeforeAndAfterBinaryOperator";
private const string SpaceAfterKeywordsInControlFlowSetting = "SpaceAfterKeywordsInControlFlow";
private const string SpaceAfterFunctionKeywordForAnonymousFunctionsSetting = "SpaceAfterFunctionKeywordForAnonymousFunctions";
private const string SpaceAfterOpeningAndBeforeClosingNonEmptyParensSetting = "SpaceAfterOpeningAndBeforeClosingNonEmptyParens";
private const string SpaceAfterCommaSetting = TypeScriptRegistrySwitches.InsertSpaceAfterCommaDelimiter;
private const string SpaceAfterSemicolonInForSetting = TypeScriptRegistrySwitches.InsertSpaceAfterSemicolonInForStatements;
private const string SpaceBeforeAndAfterBinaryOperatorSetting = TypeScriptRegistrySwitches.InsertSpaceBeforeAndAfterBinaryOperators;
private const string SpaceAfterKeywordsInControlFlowSetting = TypeScriptRegistrySwitches.InsertSpaceAfterKeywordsInControlFlowStatements;
private const string SpaceAfterFunctionKeywordForAnonymousFunctionsSetting = TypeScriptRegistrySwitches.InsertSpaceAfterFunctionKeywordForAnonymousFunctions;
private const string SpaceAfterOpeningAndBeforeClosingNonEmptyParensSetting = TypeScriptRegistrySwitches.InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis;

public override void LoadSettingsFromStorage() {
// Load settings from storage.
Expand Down
Loading