Ensure formatter can always get a newline character (#38579)

* Ensure formatter can always get a newline character

* Make FormatContext.host optional since it’s not necessary if format options are all applied

* Make FormattingHost required again
This commit is contained in:
Andrew Branch
2020-05-19 13:14:32 -07:00
committed by GitHub
parent 611dd22b9a
commit 707e977056
12 changed files with 61 additions and 21 deletions

View File

@@ -306,7 +306,7 @@ interface Array<T> {}`
cancellationToken: { throwIfCancellationRequested: noop, isCancellationRequested: returnFalse },
preferences: emptyOptions,
host: notImplementedHost,
formatContext: formatting.getFormatContext(testFormatSettings)
formatContext: formatting.getFormatContext(testFormatSettings, notImplementedHost)
};
const diagnostics = languageService.getSuggestionDiagnostics(f.path);

View File

@@ -102,7 +102,7 @@ namespace ts {
startPosition: selectionRange.pos,
endPosition: selectionRange.end,
host: notImplementedHost,
formatContext: formatting.getFormatContext(testFormatSettings),
formatContext: formatting.getFormatContext(testFormatSettings, notImplementedHost),
preferences: emptyOptions,
};
const rangeToExtract = refactor.extractSymbol.getRangeToExtract(sourceFile, createTextSpanFromRange(selectionRange));
@@ -164,7 +164,7 @@ namespace ts {
startPosition: selectionRange.pos,
endPosition: selectionRange.end,
host: notImplementedHost,
formatContext: formatting.getFormatContext(testFormatSettings),
formatContext: formatting.getFormatContext(testFormatSettings, notImplementedHost),
preferences: emptyOptions,
};
const rangeToExtract = refactor.extractSymbol.getRangeToExtract(sourceFile, createTextSpanFromRange(selectionRange));

View File

@@ -19,7 +19,7 @@ namespace ts {
const newLineCharacter = getNewLineCharacter(printerOptions);
function getRuleProvider(placeOpenBraceOnNewLineForFunctions: boolean): formatting.FormatContext {
return formatting.getFormatContext(placeOpenBraceOnNewLineForFunctions ? { ...testFormatSettings, placeOpenBraceOnNewLineForFunctions: true } : testFormatSettings);
return formatting.getFormatContext(placeOpenBraceOnNewLineForFunctions ? { ...testFormatSettings, placeOpenBraceOnNewLineForFunctions: true } : testFormatSettings, notImplementedHost);
}
// validate that positions that were recovered from the printed text actually match positions that will be created if the same text is parsed.