mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix writing new nodes, update protocol
This commit is contained in:
3 files changed
+17
-8
No files matched your search
@@ -2946,6 +2946,12 @@ namespace ts.server.protocol {
|
||||
Smart = "Smart",
|
||||
}
|
||||
|
||||
export enum SemicolonPreference {
|
||||
Ignore = "ignore",
|
||||
Insert = "insert",
|
||||
Remove = "remove",
|
||||
}
|
||||
|
||||
export interface EditorSettings {
|
||||
baseIndentSize?: number;
|
||||
indentSize?: number;
|
||||
@@ -2972,6 +2978,7 @@ namespace ts.server.protocol {
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
insertSpaceBeforeTypeAnnotation?: boolean;
|
||||
semicolonPreference?: SemicolonPreference
|
||||
}
|
||||
|
||||
export interface UserPreferences {
|
||||
|
||||
@@ -426,7 +426,7 @@ namespace ts.formatting {
|
||||
const leadingTrivia = formattingScanner.getCurrentLeadingTrivia();
|
||||
if (leadingTrivia) {
|
||||
indentTriviaItems(leadingTrivia, initialIndentation, /*indentNextTokenOrTrivia*/ false,
|
||||
item => processRange(item, sourceFile.getLineAndCharacterOfPosition(item.pos), enclosingNode, enclosingNode, /*dynamicIndentation*/ undefined!));
|
||||
item => processRange(item, sourceFile.getLineAndCharacterOfPosition(item.pos), enclosingNode, enclosingNode, /*dynamicIndentation*/ undefined!));
|
||||
trimTrailingWhitespacesForRemainingRange();
|
||||
}
|
||||
}
|
||||
@@ -477,7 +477,7 @@ namespace ts.formatting {
|
||||
parent: Node,
|
||||
parentDynamicIndentation: DynamicIndentation,
|
||||
effectiveParentStartLine: number
|
||||
): { indentation: number, delta: number } {
|
||||
): { indentation: number, delta: number; } {
|
||||
const delta = SmartIndenter.shouldIndentChildNode(options, node) ? options.indentSize! : 0;
|
||||
|
||||
if (effectiveParentStartLine === startLine) {
|
||||
@@ -867,7 +867,7 @@ namespace ts.formatting {
|
||||
if (currentTokenInfo.leadingTrivia) {
|
||||
const commentIndentation = dynamicIndentation.getIndentationForComment(currentTokenInfo.token.kind, tokenIndentation, container);
|
||||
indentNextTokenOrTrivia = indentTriviaItems(currentTokenInfo.leadingTrivia, commentIndentation, indentNextTokenOrTrivia,
|
||||
item => insertIndentation(item.pos, commentIndentation, /*lineAdded*/ false));
|
||||
item => insertIndentation(item.pos, commentIndentation, /*lineAdded*/ false));
|
||||
}
|
||||
|
||||
// indent token only if is it is in target range and does not overlap with any error ranges
|
||||
@@ -1317,7 +1317,7 @@ namespace ts.formatting {
|
||||
return SyntaxKind.Unknown;
|
||||
}
|
||||
|
||||
let internedSizes: { tabSize: number; indentSize: number };
|
||||
let internedSizes: { tabSize: number; indentSize: number; };
|
||||
let internedTabsIndentation: string[] | undefined;
|
||||
let internedSpacesIndentation: string[] | undefined;
|
||||
|
||||
|
||||
@@ -835,10 +835,12 @@ namespace ts.textChanges {
|
||||
function getFormatCodeSettingsForWriting(context: formatting.FormatContext, sourceFile: SourceFile): FormatCodeSettings {
|
||||
return {
|
||||
...context.options,
|
||||
// If the user has no semicolon preference defined, try to match whatever’s in the source file
|
||||
semicolonPreference: !context.options.semicolonPreference || context.options.semicolonPreference === SemicolonPreference.Ignore
|
||||
? probablyUsesSemicolons(sourceFile) ? SemicolonPreference.Ignore : SemicolonPreference.Remove
|
||||
: context.options.semicolonPreference,
|
||||
// If the user has no semicolon preference defined and the file doesn’t use semicolons,
|
||||
// make the formatter remove them. Otherwise, ignore semicolons in the formatter because
|
||||
// the writer will insert them by default.
|
||||
semicolonPreference: context.options.semicolonPreference === SemicolonPreference.Remove || (!context.options.semicolonPreference || context.options.semicolonPreference === SemicolonPreference.Ignore) && !probablyUsesSemicolons(sourceFile)
|
||||
? SemicolonPreference.Remove
|
||||
: SemicolonPreference.Ignore,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user