MCPcopy Create free account
hub / github.com/microsoft/typescript-go / getOwnOrInheritedDelta

Function getOwnOrInheritedDelta

internal/format/span.go:88–106  ·  view source on GitHub ↗

* * For cases like * if (a || * b ||$ * c) {...} * If we hit Enter at $ we want line ' b ||' to be indented. * Formatting will be applied to the last two lines. * Node that fully encloses these lines is binary expression 'a ||...'. * Initial indentation for this node will be 0. *

(n *ast.Node, options lsutil.FormatCodeSettings, sourceFile *ast.SourceFile)

Source from the content-addressed store, hash-verified

86 * to the initial indentation.
87 */
88func getOwnOrInheritedDelta(n *ast.Node, options lsutil.FormatCodeSettings, sourceFile *ast.SourceFile) int {
89 previousLine := -1
90 var child *ast.Node
91 for n != nil {
92 line := scanner.GetECMALineOfPosition(sourceFile, withTokenStart(n, sourceFile).Pos())
93 if previousLine != -1 && line != previousLine {
94 break
95 }
96
97 if ShouldIndentChildNode(options, n, child, sourceFile) {
98 return options.IndentSize // !!! nil check???
99 }
100
101 previousLine = line
102 child = n
103 n = n.Parent
104 }
105 return 0
106}
107
108func rangeHasNoErrors(_ core.TextRange) bool {
109 return false

Callers 1

FormatSpanFunction · 0.85

Calls 4

GetECMALineOfPositionFunction · 0.92
withTokenStartFunction · 0.85
ShouldIndentChildNodeFunction · 0.85
PosMethod · 0.65

Tested by

no test coverage detected