From 35b489d7d1ca6da4c2440e65a7f0215bdc951499 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 16 Feb 2015 15:20:05 -0800 Subject: [PATCH] Rename our one-based methods to more clearly indicate that that's what base they use. --- src/compiler/emitter.ts | 10 +++++----- src/compiler/scanner.ts | 12 ++++++------ src/compiler/tsc.ts | 4 ++-- src/compiler/utilities.ts | 2 +- src/harness/fourslash.ts | 6 +++--- src/harness/harnessLanguageService.ts | 8 ++++---- src/services/formatting/smartIndenter.ts | 2 +- src/services/services.ts | 8 ++++---- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6a2338268e8..86a8ca584a2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -134,7 +134,7 @@ module ts { } function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { - return getLineAndCharacterOfPosition(currentSourceFile, pos).line; + return getOneBasedLineAndCharacterOfPosition(currentSourceFile, pos).line; } function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { @@ -169,16 +169,16 @@ module ts { function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - var firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); + var firstCommentLineAndCharacter = getOneBasedLineAndCharacterOfPosition(currentSourceFile, comment.pos); var lastLine = getLineStarts(currentSourceFile).length; var firstCommentLineIndent: number; for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - var nextLineStart = currentLine === lastLine ? (comment.end + 1) : getPositionFromLineAndCharacter(currentSourceFile, currentLine + 1, /*character*/1); + var nextLineStart = currentLine === lastLine ? (comment.end + 1) : getPositionFromOneBasedLineAndCharacter(currentSourceFile, currentLine + 1, /*character*/1); if (pos !== comment.pos) { // If we are not emitting first line, we need to write the spaces to adjust the alignment if (firstCommentLineIndent === undefined) { - firstCommentLineIndent = calculateIndent(getPositionFromLineAndCharacter(currentSourceFile, firstCommentLineAndCharacter.line, /*character*/1), + firstCommentLineIndent = calculateIndent(getPositionFromOneBasedLineAndCharacter(currentSourceFile, firstCommentLineAndCharacter.line, /*character*/1), comment.pos); } @@ -1733,7 +1733,7 @@ module ts { } function recordSourceMapSpan(pos: number) { - var sourceLinePos = getLineAndCharacterOfPosition(currentSourceFile, pos); + var sourceLinePos = getOneBasedLineAndCharacterOfPosition(currentSourceFile, pos); var emittedLine = writer.getLine(); var emittedColumn = writer.getColumn(); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index fbbd69bbd69..bf5c4116074 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -278,11 +278,11 @@ module ts { return result; } - export function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number { - return computePositionFromLineAndCharacter(getLineStarts(sourceFile), line, character); + export function getPositionFromOneBasedLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number { + return computePositionFromOneBasedLineAndCharacter(getLineStarts(sourceFile), line, character); } - export function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number { + export function computePositionFromOneBasedLineAndCharacter(lineStarts: number[], line: number, character: number): number { Debug.assert(line > 0 && line <= lineStarts.length); return lineStarts[line - 1] + character - 1; } @@ -291,7 +291,7 @@ module ts { return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text)); } - export function computeLineAndCharacterOfPosition(lineStarts: number[], position: number) { + export function computeOneBasedLineAndCharacterOfPosition(lineStarts: number[], position: number) { var lineNumber = binarySearch(lineStarts, position); if (lineNumber < 0) { // If the actual position was not found, @@ -306,8 +306,8 @@ module ts { }; } - export function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter { - return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position); + export function getOneBasedLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter { + return computeOneBasedLineAndCharacterOfPosition(getLineStarts(sourceFile), position); } var hasOwnProperty = Object.prototype.hasOwnProperty; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 3f7e6362e19..84d8a25e790 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -72,7 +72,7 @@ module ts { function countLines(program: Program): number { var count = 0; forEach(program.getSourceFiles(), file => { - count += getLineAndCharacterOfPosition(file, file.end).line; + count += getOneBasedLineAndCharacterOfPosition(file, file.end).line; }); return count; } @@ -86,7 +86,7 @@ module ts { var output = ""; if (diagnostic.file) { - var loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + var loc = getOneBasedLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); output += diagnostic.file.fileName + "(" + loc.line + "," + loc.character + "): "; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5a50e2799dc..6323ffd4313 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -108,7 +108,7 @@ module ts { // This is a useful function for debugging purposes. export function nodePosToString(node: Node): string { var file = getSourceFileOfNode(node); - var loc = getLineAndCharacterOfPosition(file, node.pos); + var loc = getOneBasedLineAndCharacterOfPosition(file, node.pos); return file.fileName + "(" + loc.line + "," + loc.character + ")"; } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 603a78b5f75..8511d042194 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -395,7 +395,7 @@ module FourSlash { this.currentCaretPosition = pos; var lineStarts = ts.computeLineStarts(this.getFileContent(this.activeFile.fileName)); - var lineCharPos = ts.computeLineAndCharacterOfPosition(lineStarts, pos); + var lineCharPos = ts.computeOneBasedLineAndCharacterOfPosition(lineStarts, pos); this.scenarioActions.push(''); } @@ -2033,7 +2033,7 @@ module FourSlash { } private getCurrentCaretFilePosition() { - var result = this.languageServiceAdapterHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition); + var result = this.languageServiceAdapterHost.positionToZeroBasedLineAndCharacter(this.activeFile.fileName, this.currentCaretPosition); if (result.line >= 0) { result.line++; } @@ -2120,7 +2120,7 @@ module FourSlash { } private getLineColStringAtPosition(position: number) { - var pos = this.languageServiceAdapterHost.positionToZeroBasedLineCol(this.activeFile.fileName, position); + var pos = this.languageServiceAdapterHost.positionToZeroBasedLineAndCharacter(this.activeFile.fileName, position); return 'line ' + (pos.line + 1) + ', col ' + pos.character; } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 2f95f5072d0..f0d788a1c6b 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -175,18 +175,18 @@ module Harness.LanguageService { assert.isTrue(line >= 1); assert.isTrue(col >= 1); - return ts.computePositionFromLineAndCharacter(script.lineMap, line, col); + return ts.computePositionFromOneBasedLineAndCharacter(script.lineMap, line, col); } /** * @param line 0 based index * @param col 0 based index */ - public positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter { + public positionToZeroBasedLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { var script: ScriptInfo = this.fileNameToScript[fileName]; assert.isNotNull(script); - var result = ts.computeLineAndCharacterOfPosition(script.lineMap, position); + var result = ts.computeOneBasedLineAndCharacterOfPosition(script.lineMap, position); assert.isTrue(result.line >= 1); assert.isTrue(result.character >= 1); @@ -239,7 +239,7 @@ module Harness.LanguageService { updateScript(fileName: string, content: string): void { return this.nativeHost.updateScript(fileName, content); } editScript(fileName: string, minChar: number, limChar: number, newText: string): void { this.nativeHost.editScript(fileName, minChar, limChar, newText); } lineColToPosition(fileName: string, line: number, col: number): number { return this.nativeHost.lineColToPosition(fileName, line, col); } - positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToZeroBasedLineCol(fileName, position); } + positionToZeroBasedLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToZeroBasedLineAndCharacter(fileName, position); } getCompilationSettings(): string { return JSON.stringify(this.nativeHost.getCompilationSettings()); } getCancellationToken(): ts.CancellationToken { return this.nativeHost.getCancellationToken(); } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 3aa97fe6ae6..efc279cfca6 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -303,7 +303,7 @@ module ts.formatting { } function findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter: LineAndCharacter, sourceFile: SourceFile, options: EditorOptions): number { - var lineStart = sourceFile.getPositionFromLineAndCharacter(lineAndCharacter.line, 1); + var lineStart = sourceFile.getPositionFromOneBasedLineAndCharacter(lineAndCharacter.line, 1); return findFirstNonWhitespaceColumn(lineStart, lineStart + lineAndCharacter.character, sourceFile, options); } diff --git a/src/services/services.ts b/src/services/services.ts index 6e3cdf0a344..07a0bac2dc6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -63,7 +63,7 @@ module ts { getNamedDeclarations(): Declaration[]; getLineAndCharacterFromPosition(pos: number): LineAndCharacter; getLineStarts(): number[]; - getPositionFromLineAndCharacter(line: number, character: number): number; + getPositionFromOneBasedLineAndCharacter(line: number, character: number): number; update(newText: string, textChangeRange: TextChangeRange): SourceFile; } @@ -751,15 +751,15 @@ module ts { } public getLineAndCharacterFromPosition(position: number): LineAndCharacter { - return getLineAndCharacterOfPosition(this, position); + return getOneBasedLineAndCharacterOfPosition(this, position); } public getLineStarts(): number[] { return getLineStarts(this); } - public getPositionFromLineAndCharacter(line: number, character: number): number { - return getPositionFromLineAndCharacter(this, line, character); + public getPositionFromOneBasedLineAndCharacter(line: number, character: number): number { + return getPositionFromOneBasedLineAndCharacter(this, line, character); } public getNamedDeclarations() {