mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Add tests for projectinfo command
This commit is contained in:
parent
040dbd9def
commit
70675162dc
@ -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));
|
||||
|
||||
@ -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);
|
||||
|
||||
16
src/server/protocol.d.ts
vendored
16
src/server/protocol.d.ts
vendored
@ -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.
|
||||
*/
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
10
tests/cases/fourslash/server/projectInfo.ts
Normal file
10
tests/cases/fourslash/server/projectInfo.ts
Normal 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"])
|
||||
Loading…
x
Reference in New Issue
Block a user