Unify padding impls and consistently use them

This commit is contained in:
Wesley Wigham 2020-02-19 17:21:51 -08:00
parent 77d3a69039
commit 4a34294908
No known key found for this signature in database
GPG Key ID: D59F87F60C5400C9
4 changed files with 16 additions and 23 deletions

View File

@ -2051,4 +2051,19 @@ namespace ts {
}
}
}
export function padLeft(s: string, length: number) {
while (s.length < length) {
s = " " + s;
}
return s;
}
export function padRight(s: string, length: number) {
while (s.length < length) {
s = s + " ";
}
return s;
}
}

View File

@ -383,13 +383,6 @@ namespace ts {
return formatStyle + text + resetEscapeSequence;
}
function padLeft(s: string, length: number) {
while (s.length < length) {
s = " " + s;
}
return s;
}
function formatCodeSpan(file: SourceFile, start: number, length: number, indent: string, squiggleColor: ForegroundColorEscapeSequences, host: FormatDiagnosticsHost) {
const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start);
const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length);

View File

@ -33,21 +33,6 @@ namespace ts {
return options.pretty;
}
function padLeft(s: string, length: number) {
while (s.length < length) {
s = " " + s;
}
return s;
}
function padRight(s: string, length: number) {
while (s.length < length) {
s = s + " ";
}
return s;
}
function getOptionsForHelp(commandLine: ParsedCommandLine) {
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
return !!commandLine.options.all ?

View File

@ -1563,7 +1563,7 @@ namespace FourSlash {
const output: string[] = [];
for (let lineNumber = contextStart.line; lineNumber <= contextEnd.line; lineNumber++) {
const spanLine = contextString.substring(contextLineMap[lineNumber], contextLineMap[lineNumber + 1]);
output.push(lineNumbers ? `${`${lineNumber + 1}: `.padStart(lineNumberPrefixLength, " ")}${spanLine}` : spanLine);
output.push(lineNumbers ? `${ts.padLeft(`${lineNumber + 1}: `, lineNumberPrefixLength)}${spanLine}` : spanLine);
if (selection) {
if (lineNumber < selectionStart.line || lineNumber > selectionEnd.line) {
continue;