This commit is contained in:
Gabriela Araujo Britto 2021-11-16 16:37:46 -08:00
parent 3e59096506
commit 64e0bd4263
3 changed files with 13 additions and 9 deletions

View file

@ -1953,6 +1953,7 @@ namespace ts {
}
function emitTabStop(hint: EmitHint, node: Node, snippet: TabStop) {
// A tab stop should only be attached to an empty node, i.e. a node that doesn't emit any text.
Debug.assert(node.kind === SyntaxKind.EmptyStatement,
`A tab stop cannot be attached to a node of kind ${Debug.formatSyntaxKind(node.kind)}.`);
Debug.assert(hint !== EmitHint.EmbeddedStatement,

View file

@ -1052,15 +1052,6 @@ namespace ts.textChanges {
? "" : options.suffix);
}
export function getFormatCodeSettingsForWriting({ options }: formatting.FormatContext, sourceFile: SourceFile): FormatCodeSettings {
const shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === SemicolonPreference.Ignore;
const shouldRemoveSemicolons = options.semicolons === SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !probablyUsesSemicolons(sourceFile);
return {
...options,
semicolons: shouldRemoveSemicolons ? SemicolonPreference.Remove : SemicolonPreference.Ignore,
};
}
/** Note: this may mutate `nodeIn`. */
function getFormattedTextOfNode(nodeIn: Node, sourceFile: SourceFile, pos: number, { indentation, prefix, delta }: InsertNodeOptions, newLineCharacter: string, formatContext: formatting.FormatContext, validate: ValidateNonFormattedText | undefined): string {
const { node, text } = getNonformattedText(nodeIn, sourceFile, newLineCharacter);

View file

@ -3290,5 +3290,17 @@ namespace ts {
: getLocaleSpecificMessage(diag);
}
/**
* Get format code settings for a code writing context (e.g. when formatting text changes or completions code).
*/
export function getFormatCodeSettingsForWriting({ options }: formatting.FormatContext, sourceFile: SourceFile): FormatCodeSettings {
const shouldAutoDetectSemicolonPreference = !options.semicolons || options.semicolons === SemicolonPreference.Ignore;
const shouldRemoveSemicolons = options.semicolons === SemicolonPreference.Remove || shouldAutoDetectSemicolonPreference && !probablyUsesSemicolons(sourceFile);
return {
...options,
semicolons: shouldRemoveSemicolons ? SemicolonPreference.Remove : SemicolonPreference.Ignore,
};
}
// #endregion
}