mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Add fourslash tests & address CR comments
This commit is contained in:
@@ -1663,24 +1663,25 @@ namespace FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
private getIndentation(fileName: string, position: number, indentStyle: ts.IndentStyle): number {
|
||||
private getIndentation(fileName: string, position: number, indentStyle: ts.IndentStyle, baseIndentSize: number): number {
|
||||
|
||||
const formatOptions = ts.clone(this.formatCodeOptions);
|
||||
formatOptions.IndentStyle = indentStyle;
|
||||
formatOptions.BaseIndentSize = baseIndentSize;
|
||||
|
||||
return this.languageService.getIndentationAtPosition(fileName, position, formatOptions);
|
||||
}
|
||||
|
||||
public verifyIndentationAtCurrentPosition(numberOfSpaces: number, indentStyle: ts.IndentStyle = ts.IndentStyle.Smart) {
|
||||
const actual = this.getIndentation(this.activeFile.fileName, this.currentCaretPosition, indentStyle);
|
||||
public verifyIndentationAtCurrentPosition(numberOfSpaces: number, indentStyle: ts.IndentStyle = ts.IndentStyle.Smart, baseIndentSize = 0) {
|
||||
const actual = this.getIndentation(this.activeFile.fileName, this.currentCaretPosition, indentStyle, baseIndentSize);
|
||||
const lineCol = this.getLineColStringAtPosition(this.currentCaretPosition);
|
||||
if (actual !== numberOfSpaces) {
|
||||
this.raiseError(`verifyIndentationAtCurrentPosition failed at ${lineCol} - expected: ${numberOfSpaces}, actual: ${actual}`);
|
||||
}
|
||||
}
|
||||
|
||||
public verifyIndentationAtPosition(fileName: string, position: number, numberOfSpaces: number, indentStyle: ts.IndentStyle = ts.IndentStyle.Smart) {
|
||||
const actual = this.getIndentation(fileName, position, indentStyle);
|
||||
public verifyIndentationAtPosition(fileName: string, position: number, numberOfSpaces: number, indentStyle: ts.IndentStyle = ts.IndentStyle.Smart, baseIndentSize = 0) {
|
||||
const actual = this.getIndentation(fileName, position, indentStyle, baseIndentSize);
|
||||
const lineCol = this.getLineColStringAtPosition(position);
|
||||
if (actual !== numberOfSpaces) {
|
||||
this.raiseError(`verifyIndentationAtPosition failed at ${lineCol} - expected: ${numberOfSpaces}, actual: ${actual}`);
|
||||
@@ -2938,8 +2939,8 @@ namespace FourSlashInterface {
|
||||
this.state.verifyIndentationAtCurrentPosition(numberOfSpaces);
|
||||
}
|
||||
|
||||
public indentationAtPositionIs(fileName: string, position: number, numberOfSpaces: number, indentStyle = ts.IndentStyle.Smart) {
|
||||
this.state.verifyIndentationAtPosition(fileName, position, numberOfSpaces, indentStyle);
|
||||
public indentationAtPositionIs(fileName: string, position: number, numberOfSpaces: number, indentStyle = ts.IndentStyle.Smart, baseIndentSize = 0) {
|
||||
this.state.verifyIndentationAtPosition(fileName, position, numberOfSpaces, indentStyle, baseIndentSize);
|
||||
}
|
||||
|
||||
public textAtCaretIs(text: string) {
|
||||
|
||||
@@ -396,10 +396,8 @@ namespace ts.formatting {
|
||||
if (startLine !== parentStartLine || startPos === column) {
|
||||
// Use the base indent size if it is greater than
|
||||
// the indentation of the inherited predecessor.
|
||||
if (options.BaseIndentSize > column) {
|
||||
return options.BaseIndentSize;
|
||||
}
|
||||
return column;
|
||||
const baseIndentSize = SmartIndenter.getBaseIndentation(options);
|
||||
return baseIndentSize > column ? baseIndentSize : column;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace ts.formatting {
|
||||
// no indentation when the indent style is set to none,
|
||||
// so we can return fast
|
||||
if (options.IndentStyle === IndentStyle.None) {
|
||||
return getBaseIndentation(options);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const precedingToken = findPrecedingToken(position, sourceFile);
|
||||
@@ -27,7 +27,7 @@ namespace ts.formatting {
|
||||
// no indentation in string \regex\template literals
|
||||
const precedingTokenIsLiteral = isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind);
|
||||
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) {
|
||||
return getBaseIndentation(options);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const lineAtPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
|
||||
@@ -103,7 +103,7 @@ namespace ts.formatting {
|
||||
return getIndentationForNodeWorker(current, currentStart, /*ignoreActualIndentationRange*/ undefined, indentationDelta, sourceFile, options);
|
||||
}
|
||||
|
||||
function getBaseIndentation(options: EditorOptions) {
|
||||
export function getBaseIndentation(options: EditorOptions) {
|
||||
return options.BaseIndentSize || 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user