** Note: this may mutate `nodeIn`. */
(nodeIn *ast.Node, targetSourceFile *ast.SourceFile, sourceFile *ast.SourceFile, pos int, options NodeOptions)
| 90 | |
| 91 | /** Note: this may mutate `nodeIn`. */ |
| 92 | func (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 | |
| 114 | func getFormatCodeSettingsForWriting(options lsutil.FormatCodeSettings, sourceFile *ast.SourceFile) lsutil.FormatCodeSettings { |
| 115 | shouldAutoDetectSemicolonPreference := options.Semicolons == lsutil.SemicolonPreferenceIgnore |
no test coverage detected