获取 CodeMirror 中特定行中使用的缩进

Get indentation used in specific line in CodeMirror

我正在使用CodeMirror,我想提供一些简单的代码转换功能。

我需要的是知道我所在行的缩进,例如:

function test() {
  var x = 0; //I need to get that this line has 2 spaces.
  var y = function() {
    return true; //And that this one has 4 spaces -or a tab.
  }
}

是否有通过 CodeMirror API 或任何相关黑客获取它的标准方法?

由于 CodeMirror 主要用于语法分析(标记等),我试图分析行标记并将其与光标数据结合起来,但我想要求更彻底和清晰的东西。

令牌的状态包含 indented 属性,它为令牌的缩进提供此类信息:

var token = editor.getTokenAt(editor.getCursor());
console.log(token.state.indented);