Skip to content

Commit

Permalink
Merge pull request #1015 from mjbvz/fix-smart-indent-settings-crash
Browse files Browse the repository at this point in the history
Fix smart indent settings crash

Closes #1016
  • Loading branch information
mjbvz committed Jun 11, 2016
2 parents c1af660 + 1a55148 commit d92bba0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Nodejs/Product/Nodejs/NodejsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ internal sealed partial class NodejsPackage : CommonPackage {
Environment.SetEnvironmentVariable(NodejsConstants.NodeToolsProcessIdEnvironmentVariable, Process.GetCurrentProcess().Id.ToString());
}

private static LANGPREFERENCES3[] GetNodejsLanguagePreferencesFromTypeScript(IVsTextManager4 textMgr) {
public static LANGPREFERENCES3[] GetNodejsLanguagePreferencesFromTypeScript(IVsTextManager4 textMgr) {
var langPrefs = new LANGPREFERENCES3[1];
langPrefs[0].guidLang = Guids.TypeScriptLanguageInfo;
ErrorHandler.ThrowOnFailure(textMgr.GetUserPreferences4(null, langPrefs, null));
Expand Down
19 changes: 7 additions & 12 deletions Nodejs/Product/Nodejs/SmartIndent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.OptionsExtensionMethods;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.NodejsTools {
sealed class SmartIndent : ISmartIndent {
Expand All @@ -45,20 +43,17 @@ sealed class SmartIndent : ISmartIndent {

#region ISmartIndent Members

public int? GetDesiredIndentation(VisualStudio.Text.ITextSnapshotLine line) {
var dte = (EnvDTE.DTE)NodejsPackage.GetGlobalService(typeof(EnvDTE.DTE));

var props = dte.get_Properties("TextEditor", "Node.js");
switch ((EnvDTE._vsIndentStyle)(int)props.Item("IndentStyle").Value) {
case EnvDTE._vsIndentStyle.vsIndentStyleNone:
public int? GetDesiredIndentation(ITextSnapshotLine line) {
switch (NodejsPackage.Instance.LangPrefs.IndentMode) {
case VisualStudio.TextManager.Interop.vsIndentStyle.vsIndentStyleNone:
return null;
case EnvDTE._vsIndentStyle.vsIndentStyleDefault:
case VisualStudio.TextManager.Interop.vsIndentStyle.vsIndentStyleDefault:
return DoBlockIndent(line);
case EnvDTE._vsIndentStyle.vsIndentStyleSmart:
case VisualStudio.TextManager.Interop.vsIndentStyle.vsIndentStyleSmart:
return DoSmartIndent(line);
default:
return null;
}

return null;
}

#endregion
Expand Down

0 comments on commit d92bba0

Please sign in to comment.