Add tests for projectinfo command

This commit is contained in:
Zhengbo Li 2015-06-01 17:45:28 -07:00
parent 040dbd9def
commit 70675162dc
6 changed files with 59 additions and 10 deletions

View File

@ -1818,6 +1818,21 @@ module FourSlash {
}
}
private verifyProjectInfo(expected: string[]) {
if (this.testType == FourSlashTestType.Server) {
let actual = (<ts.server.SessionClient>this.languageService).getProjectInfo(
this.activeFile.fileName,
/* needFileNameList */ true
);
assert.equal(
expected.join(","),
actual.fileNameList.map( file => {
return file.replace(this.basePath + "/", "")
}).join(",")
);
}
}
public verifySemanticClassifications(expected: { classificationType: string; text: string }[]) {
var actual = this.languageService.getSemanticClassifications(this.activeFile.fileName,
ts.createTextSpan(0, this.activeFile.content.length));

View File

@ -171,6 +171,21 @@ module ts.server {
documentation: [{ kind: "text", text: response.body.documentation }]
};
}
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {
var args: protocol.ProjectInfoRequestArgs = {
file: fileName,
needFileNameList: !!needFileNameList
};
var request = this.processRequest<protocol.ProjectInfoRequest>(CommandNames.ProjectInfo, args);
var response = this.processResponse<protocol.ProjectInfoResponse>(request);
return {
configFileName: response.body.configFileName,
fileNameList: response.body.fileNameList
};
}
getCompletionsAtPosition(fileName: string, position: number): CompletionInfo {
var lineOffset = this.positionToOneBasedLineOffset(fileName, position);

View File

@ -90,25 +90,29 @@ declare module ts.server.protocol {
/**
* Arguments for ProjectInfoResponse messages.
*/
export interface ProjectInfoRequestArgs {
/**
* The file for the request (absolute pathname required).
*/
file: string;
export interface ProjectInfoRequestArgs extends FileRequestArgs {
/**
* Indicate if the file name list of the project is needed
*/
needFileNameList: boolean;
}
export interface ProjectInfoRequest extends Request {
arguments: ProjectInfoRequestArgs
}
/**
* Response message for "projectInfo" request
*/
export interface ProjectInfoResponse {
export interface ProjectInfo {
configFileName: string;
fileNameList?: string[];
}
export interface ProjectInfoResponse extends Response {
body?: ProjectInfo;
}
/**
* Request whose sole parameter is a file name.
*/

View File

@ -339,18 +339,19 @@ module ts.server {
});
}
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfoResponse {
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {
fileName = ts.normalizePath(fileName)
let project = this.projectService.getProjectForFile(fileName)
let projectInfoResponse: protocol.ProjectInfoResponse = {
let projectInfo: protocol.ProjectInfo = {
configFileName: project.projectFilename
}
if (needFileNameList) {
projectInfoResponse.fileNameList = project.getFileNameList();
projectInfo.fileNameList = project.getFileNameList();
}
return projectInfoResponse;
return projectInfo;
}
getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody {

View File

@ -455,6 +455,10 @@ module FourSlashInterface {
public getSemanticDiagnostics(expected: string) {
FourSlash.currentTestState.getSemanticDiagnostics(expected);
}
public ProjectInfo(expected: string []) {
FourSlash.currentTestState.verifyProjectInfo(expected);
}
}
export class edit {

View File

@ -0,0 +1,10 @@
/// <reference path="../fourslash.ts"/>
// @Filename: a.ts
//// import test from "b"
// @Filename: b.ts
//// export var test = "test String"
goTo.file("a.ts")
verify.ProjectInfo(["lib.d.ts", "b.ts", "a.ts"])