Visual Studio 2013 JavaScript / TypeScript奇怪的缩进行为

时间:2014-04-21 14:02:04

标签: javascript visual-studio visual-studio-2013 resharper typescript

在处理我的TypeScript代码时,自动缩进代码存在问题。我使用VS2013和Resharper。

问题主要来自方法链。

例如使用promises:

someService.GetSomeProperties().then(x => {
    return otherService.doSomethingWithX(x.map(y => y.id));
}).then(x => {
    // Pressing enter sets the cursor to this position
        // Using document format (CTRL+K,CTRL+D) the code moves to this level
        return '';
}).then(x => { // Pressing enter from here
    // Moves the previous line to it's position and cursor here
    return 'a';
    }).then(x => {
        // However document format moves this code block to this indention level
        // as well
    }).then(x => {
        // Follow up chaining remains the same
    });

基于“症状”,这种行为似乎来自于一般的多行语句。

我查看了VS2013的选项和R#s,但我找不到任何对此行为有任何影响的选项。

有人知道如何解决它吗?

1 个答案:

答案 0 :(得分:2)

  

有人知道如何解决它吗?

如果你将then放在一个新行中(即每个顶级函数都有自己的行)并且总是使用分号,那么它是固定的:

someService.GetSomeProperties()
    .then(x => {
        return otherService.doSomethingWithX(x.map(y => y.id));
    })
    .then(x => {
        // Pressing enter sets the cursor to this position
        // Using document format (CTRL+K,CTRL+D) the code moves to this level
        return '';
    })
    .then(x => { // Pressing enter from here
        // Moves the previous line to it's position and cursor here
        return 'a';
    })
    .then(x => {
        // However document format moves this code block to this indention level
        // as well
    })
    .then(x => {
        // Follow up chaining remains the same
    });