mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
Rename our one-based methods to more clearly indicate that that's what base they use.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 + "): ";
|
||||
}
|
||||
|
||||
@@ -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 + ")";
|
||||
}
|
||||
|
||||
|
||||
@@ -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('<MoveCaretToLineAndChar LineNumber="' + lineCharPos.line + '" CharNumber="' + lineCharPos.character + '" />');
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user