Fix writing new nodes, update protocol

This commit is contained in:
Andrew Branch committed 2019-09-11 18:26:26 -07:00
1 parent 149eaf67ee
commit 4555bb815b
3 files changed
+17 -8

No files matched your search

+7
View File
@@ -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 {
+4 -4
View File
@@ -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;
+6 -4
View File
@@ -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,
};
}