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

Method getFormattedTextOfNode

internal/ls/change/trackerimpl.go:92–112  ·  view source on GitHub ↗

** Note: this may mutate `nodeIn`. */

(nodeIn *ast.Node, targetSourceFile *ast.SourceFile, sourceFile *ast.SourceFile, pos int, options NodeOptions)

Source from the content-addressed store, hash-verified

90
91/** Note: this may mutate `nodeIn`. */
92func (t *Tracker) getFormattedTextOfNode(nodeIn *ast.Node, targetSourceFile *ast.SourceFile, sourceFile *ast.SourceFile, pos int, options NodeOptions) string {
93 text, sourceFileLike := t.getNonformattedText(nodeIn, targetSourceFile)
94 // !!! if (validate) validate(node, text);
95 formatOptions := getFormatCodeSettingsForWriting(t.formatSettings, targetSourceFile)
96
97 var initialIndentation, delta int
98 if options.indentation == nil {
99 initialIndentation = format.GetIndentation(pos, sourceFile, formatOptions, options.Prefix == t.newLine || format.GetLineStartPositionForPosition(pos, targetSourceFile) == pos)
100 } else {
101 initialIndentation = *options.indentation
102 }
103
104 if options.delta != nil {
105 delta = *options.delta
106 } else if formatOptions.IndentSize != 0 && format.ShouldIndentChildNode(formatOptions, nodeIn, nil, nil) {
107 delta = formatOptions.IndentSize
108 }
109
110 changes := format.FormatNodeGivenIndentation(t.ctx, sourceFileLike, sourceFileLike.AsSourceFile(), targetSourceFile.LanguageVariant, initialIndentation, delta)
111 return core.ApplyBulkEdits(text, changes)
112}
113
114func getFormatCodeSettingsForWriting(options lsutil.FormatCodeSettings, sourceFile *ast.SourceFile) lsutil.FormatCodeSettings {
115 shouldAutoDetectSemicolonPreference := options.Semicolons == lsutil.SemicolonPreferenceIgnore

Callers 1

computeNewTextMethod · 0.95

Calls 8

getNonformattedTextMethod · 0.95
GetIndentationFunction · 0.92
ShouldIndentChildNodeFunction · 0.92
ApplyBulkEditsFunction · 0.92
AsSourceFileMethod · 0.80

Tested by

no test coverage detected