Skip to content

Commit 35b489d

Browse files
Rename our one-based methods to more clearly indicate that that's what base they use.
1 parent cbeea38 commit 35b489d

8 files changed

Lines changed: 26 additions & 26 deletions

File tree

src/compiler/emitter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module ts {
134134
}
135135

136136
function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) {
137-
return getLineAndCharacterOfPosition(currentSourceFile, pos).line;
137+
return getOneBasedLineAndCharacterOfPosition(currentSourceFile, pos).line;
138138
}
139139

140140
function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) {
@@ -169,16 +169,16 @@ module ts {
169169

170170
function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){
171171
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
172-
var firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos);
172+
var firstCommentLineAndCharacter = getOneBasedLineAndCharacterOfPosition(currentSourceFile, comment.pos);
173173
var lastLine = getLineStarts(currentSourceFile).length;
174174
var firstCommentLineIndent: number;
175175
for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
176-
var nextLineStart = currentLine === lastLine ? (comment.end + 1) : getPositionFromLineAndCharacter(currentSourceFile, currentLine + 1, /*character*/1);
176+
var nextLineStart = currentLine === lastLine ? (comment.end + 1) : getPositionFromOneBasedLineAndCharacter(currentSourceFile, currentLine + 1, /*character*/1);
177177

178178
if (pos !== comment.pos) {
179179
// If we are not emitting first line, we need to write the spaces to adjust the alignment
180180
if (firstCommentLineIndent === undefined) {
181-
firstCommentLineIndent = calculateIndent(getPositionFromLineAndCharacter(currentSourceFile, firstCommentLineAndCharacter.line, /*character*/1),
181+
firstCommentLineIndent = calculateIndent(getPositionFromOneBasedLineAndCharacter(currentSourceFile, firstCommentLineAndCharacter.line, /*character*/1),
182182
comment.pos);
183183
}
184184

@@ -1733,7 +1733,7 @@ module ts {
17331733
}
17341734

17351735
function recordSourceMapSpan(pos: number) {
1736-
var sourceLinePos = getLineAndCharacterOfPosition(currentSourceFile, pos);
1736+
var sourceLinePos = getOneBasedLineAndCharacterOfPosition(currentSourceFile, pos);
17371737
var emittedLine = writer.getLine();
17381738
var emittedColumn = writer.getColumn();
17391739

src/compiler/scanner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ module ts {
278278
return result;
279279
}
280280

281-
export function getPositionFromLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number {
282-
return computePositionFromLineAndCharacter(getLineStarts(sourceFile), line, character);
281+
export function getPositionFromOneBasedLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number {
282+
return computePositionFromOneBasedLineAndCharacter(getLineStarts(sourceFile), line, character);
283283
}
284284

285-
export function computePositionFromLineAndCharacter(lineStarts: number[], line: number, character: number): number {
285+
export function computePositionFromOneBasedLineAndCharacter(lineStarts: number[], line: number, character: number): number {
286286
Debug.assert(line > 0 && line <= lineStarts.length);
287287
return lineStarts[line - 1] + character - 1;
288288
}
@@ -291,7 +291,7 @@ module ts {
291291
return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
292292
}
293293

294-
export function computeLineAndCharacterOfPosition(lineStarts: number[], position: number) {
294+
export function computeOneBasedLineAndCharacterOfPosition(lineStarts: number[], position: number) {
295295
var lineNumber = binarySearch(lineStarts, position);
296296
if (lineNumber < 0) {
297297
// If the actual position was not found,
@@ -306,8 +306,8 @@ module ts {
306306
};
307307
}
308308

309-
export function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter {
310-
return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
309+
export function getOneBasedLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter {
310+
return computeOneBasedLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
311311
}
312312

313313
var hasOwnProperty = Object.prototype.hasOwnProperty;

src/compiler/tsc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module ts {
7272
function countLines(program: Program): number {
7373
var count = 0;
7474
forEach(program.getSourceFiles(), file => {
75-
count += getLineAndCharacterOfPosition(file, file.end).line;
75+
count += getOneBasedLineAndCharacterOfPosition(file, file.end).line;
7676
});
7777
return count;
7878
}
@@ -86,7 +86,7 @@ module ts {
8686
var output = "";
8787

8888
if (diagnostic.file) {
89-
var loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
89+
var loc = getOneBasedLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
9090

9191
output += diagnostic.file.fileName + "(" + loc.line + "," + loc.character + "): ";
9292
}

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module ts {
108108
// This is a useful function for debugging purposes.
109109
export function nodePosToString(node: Node): string {
110110
var file = getSourceFileOfNode(node);
111-
var loc = getLineAndCharacterOfPosition(file, node.pos);
111+
var loc = getOneBasedLineAndCharacterOfPosition(file, node.pos);
112112
return file.fileName + "(" + loc.line + "," + loc.character + ")";
113113
}
114114

src/harness/fourslash.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ module FourSlash {
395395
this.currentCaretPosition = pos;
396396

397397
var lineStarts = ts.computeLineStarts(this.getFileContent(this.activeFile.fileName));
398-
var lineCharPos = ts.computeLineAndCharacterOfPosition(lineStarts, pos);
398+
var lineCharPos = ts.computeOneBasedLineAndCharacterOfPosition(lineStarts, pos);
399399
this.scenarioActions.push('<MoveCaretToLineAndChar LineNumber="' + lineCharPos.line + '" CharNumber="' + lineCharPos.character + '" />');
400400
}
401401

@@ -2033,7 +2033,7 @@ module FourSlash {
20332033
}
20342034

20352035
private getCurrentCaretFilePosition() {
2036-
var result = this.languageServiceAdapterHost.positionToZeroBasedLineCol(this.activeFile.fileName, this.currentCaretPosition);
2036+
var result = this.languageServiceAdapterHost.positionToZeroBasedLineAndCharacter(this.activeFile.fileName, this.currentCaretPosition);
20372037
if (result.line >= 0) {
20382038
result.line++;
20392039
}
@@ -2120,7 +2120,7 @@ module FourSlash {
21202120
}
21212121

21222122
private getLineColStringAtPosition(position: number) {
2123-
var pos = this.languageServiceAdapterHost.positionToZeroBasedLineCol(this.activeFile.fileName, position);
2123+
var pos = this.languageServiceAdapterHost.positionToZeroBasedLineAndCharacter(this.activeFile.fileName, position);
21242124
return 'line ' + (pos.line + 1) + ', col ' + pos.character;
21252125
}
21262126

src/harness/harnessLanguageService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,18 @@ module Harness.LanguageService {
175175
assert.isTrue(line >= 1);
176176
assert.isTrue(col >= 1);
177177

178-
return ts.computePositionFromLineAndCharacter(script.lineMap, line, col);
178+
return ts.computePositionFromOneBasedLineAndCharacter(script.lineMap, line, col);
179179
}
180180

181181
/**
182182
* @param line 0 based index
183183
* @param col 0 based index
184184
*/
185-
public positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter {
185+
public positionToZeroBasedLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter {
186186
var script: ScriptInfo = this.fileNameToScript[fileName];
187187
assert.isNotNull(script);
188188

189-
var result = ts.computeLineAndCharacterOfPosition(script.lineMap, position);
189+
var result = ts.computeOneBasedLineAndCharacterOfPosition(script.lineMap, position);
190190

191191
assert.isTrue(result.line >= 1);
192192
assert.isTrue(result.character >= 1);
@@ -239,7 +239,7 @@ module Harness.LanguageService {
239239
updateScript(fileName: string, content: string): void { return this.nativeHost.updateScript(fileName, content); }
240240
editScript(fileName: string, minChar: number, limChar: number, newText: string): void { this.nativeHost.editScript(fileName, minChar, limChar, newText); }
241241
lineColToPosition(fileName: string, line: number, col: number): number { return this.nativeHost.lineColToPosition(fileName, line, col); }
242-
positionToZeroBasedLineCol(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToZeroBasedLineCol(fileName, position); }
242+
positionToZeroBasedLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToZeroBasedLineAndCharacter(fileName, position); }
243243

244244
getCompilationSettings(): string { return JSON.stringify(this.nativeHost.getCompilationSettings()); }
245245
getCancellationToken(): ts.CancellationToken { return this.nativeHost.getCancellationToken(); }

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ module ts.formatting {
303303
}
304304

305305
function findColumnForFirstNonWhitespaceCharacterInLine(lineAndCharacter: LineAndCharacter, sourceFile: SourceFile, options: EditorOptions): number {
306-
var lineStart = sourceFile.getPositionFromLineAndCharacter(lineAndCharacter.line, 1);
306+
var lineStart = sourceFile.getPositionFromOneBasedLineAndCharacter(lineAndCharacter.line, 1);
307307
return findFirstNonWhitespaceColumn(lineStart, lineStart + lineAndCharacter.character, sourceFile, options);
308308
}
309309

src/services/services.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module ts {
6363
getNamedDeclarations(): Declaration[];
6464
getLineAndCharacterFromPosition(pos: number): LineAndCharacter;
6565
getLineStarts(): number[];
66-
getPositionFromLineAndCharacter(line: number, character: number): number;
66+
getPositionFromOneBasedLineAndCharacter(line: number, character: number): number;
6767
update(newText: string, textChangeRange: TextChangeRange): SourceFile;
6868
}
6969

@@ -751,15 +751,15 @@ module ts {
751751
}
752752

753753
public getLineAndCharacterFromPosition(position: number): LineAndCharacter {
754-
return getLineAndCharacterOfPosition(this, position);
754+
return getOneBasedLineAndCharacterOfPosition(this, position);
755755
}
756756

757757
public getLineStarts(): number[] {
758758
return getLineStarts(this);
759759
}
760760

761-
public getPositionFromLineAndCharacter(line: number, character: number): number {
762-
return getPositionFromLineAndCharacter(this, line, character);
761+
public getPositionFromOneBasedLineAndCharacter(line: number, character: number): number {
762+
return getPositionFromOneBasedLineAndCharacter(this, line, character);
763763
}
764764

765765
public getNamedDeclarations() {

0 commit comments

Comments
 (0)