Skip to content

Commit 7067516

Browse files
committed
Add tests for projectinfo command
1 parent 040dbd9 commit 7067516

File tree

6 files changed

+59
-10
lines changed

6 files changed

+59
-10
lines changed

src/harness/fourslash.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,21 @@ module FourSlash {
18181818
}
18191819
}
18201820

1821+
private verifyProjectInfo(expected: string[]) {
1822+
if (this.testType == FourSlashTestType.Server) {
1823+
let actual = (<ts.server.SessionClient>this.languageService).getProjectInfo(
1824+
this.activeFile.fileName,
1825+
/* needFileNameList */ true
1826+
);
1827+
assert.equal(
1828+
expected.join(","),
1829+
actual.fileNameList.map( file => {
1830+
return file.replace(this.basePath + "/", "")
1831+
}).join(",")
1832+
);
1833+
}
1834+
}
1835+
18211836
public verifySemanticClassifications(expected: { classificationType: string; text: string }[]) {
18221837
var actual = this.languageService.getSemanticClassifications(this.activeFile.fileName,
18231838
ts.createTextSpan(0, this.activeFile.content.length));

src/server/client.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ module ts.server {
171171
documentation: [{ kind: "text", text: response.body.documentation }]
172172
};
173173
}
174+
175+
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {
176+
var args: protocol.ProjectInfoRequestArgs = {
177+
file: fileName,
178+
needFileNameList: !!needFileNameList
179+
};
180+
181+
var request = this.processRequest<protocol.ProjectInfoRequest>(CommandNames.ProjectInfo, args);
182+
var response = this.processResponse<protocol.ProjectInfoResponse>(request);
183+
184+
return {
185+
configFileName: response.body.configFileName,
186+
fileNameList: response.body.fileNameList
187+
};
188+
}
174189

175190
getCompletionsAtPosition(fileName: string, position: number): CompletionInfo {
176191
var lineOffset = this.positionToOneBasedLineOffset(fileName, position);

src/server/protocol.d.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,29 @@ declare module ts.server.protocol {
9090
/**
9191
* Arguments for ProjectInfoResponse messages.
9292
*/
93-
export interface ProjectInfoRequestArgs {
94-
/**
95-
* The file for the request (absolute pathname required).
96-
*/
97-
file: string;
93+
export interface ProjectInfoRequestArgs extends FileRequestArgs {
9894
/**
9995
* Indicate if the file name list of the project is needed
10096
*/
10197
needFileNameList: boolean;
10298
}
10399

100+
export interface ProjectInfoRequest extends Request {
101+
arguments: ProjectInfoRequestArgs
102+
}
103+
104104
/**
105105
* Response message for "projectInfo" request
106106
*/
107-
export interface ProjectInfoResponse {
107+
export interface ProjectInfo {
108108
configFileName: string;
109109
fileNameList?: string[];
110110
}
111111

112+
export interface ProjectInfoResponse extends Response {
113+
body?: ProjectInfo;
114+
}
115+
112116
/**
113117
* Request whose sole parameter is a file name.
114118
*/

src/server/session.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,19 @@ module ts.server {
339339
});
340340
}
341341

342-
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfoResponse {
342+
getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo {
343343
fileName = ts.normalizePath(fileName)
344344
let project = this.projectService.getProjectForFile(fileName)
345345

346-
let projectInfoResponse: protocol.ProjectInfoResponse = {
346+
let projectInfo: protocol.ProjectInfo = {
347347
configFileName: project.projectFilename
348348
}
349349

350350
if (needFileNameList) {
351-
projectInfoResponse.fileNameList = project.getFileNameList();
351+
projectInfo.fileNameList = project.getFileNameList();
352352
}
353-
return projectInfoResponse;
353+
354+
return projectInfo;
354355
}
355356

356357
getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody {

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ module FourSlashInterface {
455455
public getSemanticDiagnostics(expected: string) {
456456
FourSlash.currentTestState.getSemanticDiagnostics(expected);
457457
}
458+
459+
public ProjectInfo(expected: string []) {
460+
FourSlash.currentTestState.verifyProjectInfo(expected);
461+
}
458462
}
459463

460464
export class edit {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path="../fourslash.ts"/>
2+
3+
// @Filename: a.ts
4+
//// import test from "b"
5+
6+
// @Filename: b.ts
7+
//// export var test = "test String"
8+
9+
goTo.file("a.ts")
10+
verify.ProjectInfo(["lib.d.ts", "b.ts", "a.ts"])

0 commit comments

Comments
 (0)