Skip to content

Using the smartIndenter #1754

@fdecampredon

Description

@fdecampredon

To develop a codemirror mode for typescript, I'm forced to use the indenter independently of the language service, to do so I do :

var sourceFile = ts.createSourceFile(Math.random()+ '.ts', text, ts.ScriptTarget.Latest, Math.random() + '');
var indent = indenter.getIndentation(position, sourceFile,  {
  IndentSize: options.indentUnit,
  TabSize: options.tabSize,
  NewLineCharacter: '\n',
  ConvertTabsToSpaces: !options.indentWithTabs
});

However it constantly error in getTokenPosOfNode, apparently it fails to find the sourceFile, after some investigation it seems that some node does not have parent. I had to tranform the obtained sourceFile with :

function setParents(parent: ts.Node) {
    parent.getChildren().forEach(node => {
        if (!node.parent) {
            node.parent = parent;
        }
        setParents(node);
    })
}

Is there a something in the lifecycle that I should do ? Or is it a bug ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions