Respond to code review comments

This commit is contained in:
Mohamed Hegazy 2015-05-01 14:58:23 -07:00
parent b6905aff0c
commit 1de5ea802b
6 changed files with 66 additions and 8 deletions

View file

@ -1573,7 +1573,8 @@ module FourSlash {
public goToTypeDefinition(definitionIndex: number) {
if (definitionIndex === 0) {
this.scenarioActions.push('<GoToTypeDefinition />');
} else {
}
else {
this.taoInvalidReason = 'GoToTypeDefinition not supported for non-zero definition indices';
}
@ -1610,8 +1611,18 @@ module FourSlash {
var assertFn = negative ? assert.notEqual : assert.equal;
var definitions = this.languageService.getDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
var actualCount = definitions && definitions.length || 0;
assertFn(definitions.length, expectedCount, this.messageAtLastKnownMarker("Definitions Count"));
assertFn(actualCount, expectedCount, this.messageAtLastKnownMarker("Definitions Count"));
}
public verifyTypeDefinitionsCount(negative: boolean, expectedCount: number) {
var assertFn = negative ? assert.notEqual : assert.equal;
var definitions = this.languageService.getTypeDefinitionAtPosition(this.activeFile.fileName, this.currentCaretPosition);
var actualCount = definitions && definitions.length || 0;
assertFn(actualCount, expectedCount, this.messageAtLastKnownMarker("Type definitions Count"));
}
public verifyDefinitionsName(negative: boolean, expectedName: string, expectedContainerName: string) {

View file

@ -3876,7 +3876,7 @@ module ts {
};
}
function getDefintionFromSymbol(symbol: Symbol, node: Node): DefinitionInfo[]{
function getDefinitionFromSymbol(symbol: Symbol, node: Node): DefinitionInfo[] {
let typeChecker = program.getTypeChecker();
let result: DefinitionInfo[] = [];
let declarations = symbol.getDeclarations();
@ -3939,7 +3939,6 @@ module ts {
return false;
}
}
/// Goto definition
@ -4016,7 +4015,7 @@ module ts {
declaration => createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName));
}
return getDefintionFromSymbol(symbol, node);
return getDefinitionFromSymbol(symbol, node);
}
/// Goto type
@ -4046,7 +4045,7 @@ module ts {
var result: DefinitionInfo[] = [];
forEach((<UnionType>type).types, t => {
if (t.symbol) {
result.push(...getDefintionFromSymbol(t.symbol, node));
result.push(...getDefinitionFromSymbol(t.symbol, node));
}
});
return result;
@ -4056,7 +4055,7 @@ module ts {
return undefined;
}
return getDefintionFromSymbol(type.symbol, node);
return getDefinitionFromSymbol(type.symbol, node);
}
function getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] {

View file

@ -561,7 +561,7 @@ module ts {
return this.forwardJSONCall(
"getDefinitionAtPosition('" + fileName + "', " + position + ")",
() => {
return this.languageService.getDefinitionAtPosition(fileName, position);
return this.languageService.getTypeDefinitionAtPosition(fileName, position);
});
}

View file

@ -238,6 +238,10 @@ module FourSlashInterface {
FourSlash.currentTestState.verifyDefinitionsCount(this.negative, expectedCount);
}
public typeDefinitionCountIs(expectedCount: number) {
FourSlash.currentTestState.verifyTypeDefinitionsCount(this.negative, expectedCount);
}
public definitionLocationExists() {
FourSlash.currentTestState.verifyDefinitionLocationExists(this.negative);
}

View file

@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
// @Filename: goToTypeDefinitioAliases_module1.ts
/////*definition*/module M {
//// export var p;
////}
////var m: typeof M;
// @Filename: goToTypeDefinitioAliases_module3.ts
/////*reference1*/M;
/////*reference2*/m;
goTo.marker('reference1');
goTo.type();
verify.caretAtMarker('definition');
goTo.marker('reference2');
goTo.type();
verify.caretAtMarker('definition');

View file

@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// @Filename: module1.ts
////var w: {a: number};
////var x = "string";
////var y: number | string;
////var z; // any
// @Filename: module2.ts
////w./*reference1*/a;
/////*reference2*/x;
/////*reference3*/y;
/////*reference4*/y;
goTo.marker('reference1');
verify.typeDefinitionCountIs(0);
goTo.marker('reference1');
verify.typeDefinitionCountIs(0);
goTo.marker('reference2');
verify.typeDefinitionCountIs(0);
goTo.marker('reference4');
verify.typeDefinitionCountIs(0);