Skip to content

Commit 124a77c

Browse files
Remove 'ZeroBased' from all APIs, now that all APIs are zero based.
1 parent 8ba9180 commit 124a77c

14 files changed

Lines changed: 81 additions & 81 deletions

src/compiler/emitter.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ module ts {
133133
};
134134
}
135135

136-
function getZeroBasedLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) {
137-
return getZeroBasedLineAndCharacterOfPosition(currentSourceFile, pos).line;
136+
function getBasedLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) {
137+
return getLineAndCharacterOfPosition(currentSourceFile, pos).line;
138138
}
139139

140140
function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) {
141141
// If the leading comments start on different line than the start of node, write new line
142142
if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
143-
getZeroBasedLineOfLocalPosition(currentSourceFile, node.pos) !== getZeroBasedLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
143+
getBasedLineOfLocalPosition(currentSourceFile, node.pos) !== getBasedLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
144144
writer.writeLine();
145145
}
146146
}
@@ -169,18 +169,18 @@ 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 = getZeroBasedLineAndCharacterOfPosition(currentSourceFile, comment.pos);
172+
var firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos);
173173
var lineCount = getLineStarts(currentSourceFile).length;
174174
var firstCommentLineIndent: number;
175175
for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
176176
var nextLineStart = (currentLine + 1) === lineCount
177177
? currentSourceFile.text.length + 1
178-
: getStartPositionOfZeroBasedLine(currentLine + 1, currentSourceFile);
178+
: getStartPositionOfLine(currentLine + 1, currentSourceFile);
179179

180180
if (pos !== comment.pos) {
181181
// If we are not emitting first line, we need to write the spaces to adjust the alignment
182182
if (firstCommentLineIndent === undefined) {
183-
firstCommentLineIndent = calculateIndent(getStartPositionOfZeroBasedLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos);
183+
firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos);
184184
}
185185

186186
// These are number of spaces writer is going to write at current indent
@@ -1734,7 +1734,7 @@ module ts {
17341734
}
17351735

17361736
function recordSourceMapSpan(pos: number) {
1737-
var sourceLinePos = getZeroBasedLineAndCharacterOfPosition(currentSourceFile, pos);
1737+
var sourceLinePos = getLineAndCharacterOfPosition(currentSourceFile, pos);
17381738

17391739
// Convert the location to be one-based.
17401740
sourceLinePos.line++;
@@ -2979,13 +2979,13 @@ module ts {
29792979
}
29802980

29812981
function isOnSameLine(node1: Node, node2: Node) {
2982-
return getZeroBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node1.pos)) ===
2983-
getZeroBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos));
2982+
return getBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node1.pos)) ===
2983+
getBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos));
29842984
}
29852985

29862986
function nodeEndIsOnSameLineAsNodeStart(node1: Node, node2: Node) {
2987-
return getZeroBasedLineOfLocalPosition(currentSourceFile, node1.end) ===
2988-
getZeroBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos));
2987+
return getBasedLineOfLocalPosition(currentSourceFile, node1.end) ===
2988+
getBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos));
29892989
}
29902990

29912991
function emitCaseOrDefaultClause(node: CaseOrDefaultClause) {
@@ -4476,8 +4476,8 @@ module ts {
44764476

44774477
forEach(leadingComments, comment => {
44784478
if (lastComment) {
4479-
var lastCommentLine = getZeroBasedLineOfLocalPosition(currentSourceFile, lastComment.end);
4480-
var commentLine = getZeroBasedLineOfLocalPosition(currentSourceFile, comment.pos);
4479+
var lastCommentLine = getBasedLineOfLocalPosition(currentSourceFile, lastComment.end);
4480+
var commentLine = getBasedLineOfLocalPosition(currentSourceFile, comment.pos);
44814481

44824482
if (commentLine >= lastCommentLine + 2) {
44834483
// There was a blank line between the last comment and this comment. This
@@ -4495,8 +4495,8 @@ module ts {
44954495
// All comments look like they could have been part of the copyright header. Make
44964496
// sure there is at least one blank line between it and the node. If not, it's not
44974497
// a copyright header.
4498-
var lastCommentLine = getZeroBasedLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end);
4499-
var nodeLine = getZeroBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.pos));
4498+
var lastCommentLine = getBasedLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end);
4499+
var nodeLine = getBasedLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.pos));
45004500
if (nodeLine >= lastCommentLine + 2) {
45014501
// Valid detachedComments
45024502
emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);

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 getPositionOfZeroBasedLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number {
282-
return computePositionOfZeroBasedLineAndCharacter(getLineStarts(sourceFile), line, character);
281+
export function getPositionOfLineAndCharacter(sourceFile: SourceFile, line: number, character: number): number {
282+
return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character);
283283
}
284284

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

294-
export function computeZeroBasedLineAndCharacterOfPosition(lineStarts: number[], position: number) {
294+
export function computeLineAndCharacterOfPosition(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 getZeroBasedLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter {
310-
return computeZeroBasedLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
309+
export function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter {
310+
return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
311311
}
312312

313313
var hasOwnProperty = Object.prototype.hasOwnProperty;

src/compiler/tsc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module ts {
8686
var output = "";
8787

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

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

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ module ts {
105105
return <SourceFile>node;
106106
}
107107

108-
export function getStartPositionOfZeroBasedLine(line: number, sourceFile: SourceFile): number {
108+
export function getStartPositionOfLine(line: number, sourceFile: SourceFile): number {
109109
Debug.assert(line >= 0);
110110
return getLineStarts(sourceFile)[line];
111111
}
112112

113113
// This is a useful function for debugging purposes.
114114
export function nodePosToString(node: Node): string {
115115
var file = getSourceFileOfNode(node);
116-
var loc = getZeroBasedLineAndCharacterOfPosition(file, node.pos);
116+
var loc = getLineAndCharacterOfPosition(file, node.pos);
117117
return file.fileName + "(" + (loc.line + 1) + "," + (loc.character + 1) + ")";
118118
}
119119

src/harness/fourslash.ts

Lines changed: 2 additions & 2 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.computeZeroBasedLineAndCharacterOfPosition(lineStarts, pos);
398+
var lineCharPos = ts.computeLineAndCharacterOfPosition(lineStarts, pos);
399399
this.scenarioActions.push('<MoveCaretToLineAndChar LineNumber="' + (lineCharPos.line + 1) + '" CharNumber="' + (lineCharPos.character + 1) + '" />');
400400
}
401401

@@ -2112,7 +2112,7 @@ module FourSlash {
21122112
}
21132113

21142114
private getLineColStringAtPosition(position: number) {
2115-
var pos = this.languageServiceAdapterHost.positionToZeroBasedLineAndCharacter(this.activeFile.fileName, position);
2115+
var pos = this.languageServiceAdapterHost.positionToLineAndCharacter(this.activeFile.fileName, position);
21162116
return 'line ' + (pos.line + 1) + ', col ' + pos.character;
21172117
}
21182118

src/harness/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ module Harness {
11841184
}
11851185

11861186
export function getMinimalDiagnostic(err: ts.Diagnostic): HarnessDiagnostic {
1187-
var errorLineInfo = err.file ? err.file.getZeroBasedLineAndCharacterOfPosition(err.start) : { line: -1, character: -1 };
1187+
var errorLineInfo = err.file ? err.file.getLineAndCharacterOfPosition(err.start) : { line: -1, character: -1 };
11881188
return {
11891189
fileName: err.file && err.file.fileName,
11901190
start: err.start,

src/harness/harnessLanguageService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ module Harness.LanguageService {
169169
* @param line 0 based index
170170
* @param col 0 based index
171171
*/
172-
public positionToZeroBasedLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter {
172+
public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter {
173173
var script: ScriptInfo = this.fileNameToScript[fileName];
174174
assert.isNotNull(script);
175175

176-
return ts.computeZeroBasedLineAndCharacterOfPosition(script.lineMap, position);
176+
return ts.computeLineAndCharacterOfPosition(script.lineMap, position);
177177
}
178178
}
179179

@@ -221,7 +221,7 @@ module Harness.LanguageService {
221221
addScript(fileName: string, content: string): void { this.nativeHost.addScript(fileName, content); }
222222
updateScript(fileName: string, content: string): void { return this.nativeHost.updateScript(fileName, content); }
223223
editScript(fileName: string, minChar: number, limChar: number, newText: string): void { this.nativeHost.editScript(fileName, minChar, limChar, newText); }
224-
positionToZeroBasedLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToZeroBasedLineAndCharacter(fileName, position); }
224+
positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter { return this.nativeHost.positionToLineAndCharacter(fileName, position); }
225225

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

src/harness/typeWriter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TypeWriterWalker {
8585

8686
private log(node: ts.Node, type: ts.Type): void {
8787
var actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
88-
var lineAndCharacter = this.currentSourceFile.getZeroBasedLineAndCharacterOfPosition(actualPos);
88+
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterOfPosition(actualPos);
8989
var sourceText = ts.getTextOfNodeFromSourceText(this.currentSourceFile.text, node);
9090

9191
// If we got an unknown type, we temporarily want to fall back to just pretending the name

src/services/breakpoints.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ module ts.BreakpointResolver {
1414
}
1515

1616
var tokenAtLocation = getTokenAtPosition(sourceFile, position);
17-
var lineOfPosition = sourceFile.getZeroBasedLineAndCharacterOfPosition(position).line;
18-
if (sourceFile.getZeroBasedLineAndCharacterOfPosition(tokenAtLocation.getStart()).line > lineOfPosition) {
17+
var lineOfPosition = sourceFile.getLineAndCharacterOfPosition(position).line;
18+
if (sourceFile.getLineAndCharacterOfPosition(tokenAtLocation.getStart()).line > lineOfPosition) {
1919
// Get previous token if the token is returned starts on new line
2020
// eg: var x =10; |--- cursor is here
2121
// var y = 10;
@@ -24,7 +24,7 @@ module ts.BreakpointResolver {
2424
tokenAtLocation = findPrecedingToken(tokenAtLocation.pos, sourceFile);
2525

2626
// Its a blank line
27-
if (!tokenAtLocation || sourceFile.getZeroBasedLineAndCharacterOfPosition(tokenAtLocation.getEnd()).line !== lineOfPosition) {
27+
if (!tokenAtLocation || sourceFile.getLineAndCharacterOfPosition(tokenAtLocation.getEnd()).line !== lineOfPosition) {
2828
return undefined;
2929
}
3030
}
@@ -42,7 +42,7 @@ module ts.BreakpointResolver {
4242
}
4343

4444
function spanInNodeIfStartsOnSameLine(node: Node, otherwiseOnNode?: Node): TextSpan {
45-
if (node && lineOfPosition === sourceFile.getZeroBasedLineAndCharacterOfPosition(node.getStart()).line) {
45+
if (node && lineOfPosition === sourceFile.getLineAndCharacterOfPosition(node.getStart()).line) {
4646
return spanInNode(node);
4747
}
4848
return spanInNode(otherwiseOnNode);

0 commit comments

Comments
 (0)