Skip to content

Commit 783538c

Browse files
VS IntelliCode-related changes (#30731) (#30737)
* ensure configurePlugin gives a response * Update tests * Update baseline * Enable global plugin loading for external projects * Fix lint errors
1 parent 99e4865 commit 783538c

File tree

7 files changed

+78
-5
lines changed

7 files changed

+78
-5
lines changed

src/harness/client.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace ts.server {
9090
return <T>request;
9191
}
9292

93-
private processResponse<T extends protocol.Response>(request: protocol.Request): T {
93+
private processResponse<T extends protocol.Response>(request: protocol.Request, expectEmptyBody = false): T {
9494
let foundResponseMessage = false;
9595
let response!: T;
9696
while (!foundResponseMessage) {
@@ -118,7 +118,8 @@ namespace ts.server {
118118
throw new Error("Error " + response.message);
119119
}
120120

121-
Debug.assert(!!response.body, "Malformed response: Unexpected empty response body.");
121+
Debug.assert(expectEmptyBody || !!response.body, "Malformed response: Unexpected empty response body.");
122+
Debug.assert(!expectEmptyBody || !response.body, "Malformed response: Unexpected non-empty response body.");
122123

123124
return response;
124125
}
@@ -696,7 +697,8 @@ namespace ts.server {
696697
}
697698

698699
configurePlugin(pluginName: string, configuration: any): void {
699-
this.processRequest<protocol.ConfigurePluginRequest>("configurePlugin", { pluginName, configuration });
700+
const request = this.processRequest<protocol.ConfigurePluginRequest>("configurePlugin", { pluginName, configuration });
701+
this.processResponse<protocol.ConfigurePluginResponse>(request, /*expectEmptyBody*/ true);
700702
}
701703

702704
getIndentationAtPosition(_fileName: string, _position: number, _options: EditorOptions): number {

src/server/editorServices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,8 @@ namespace ts.server {
16071607
this.documentRegistry,
16081608
compilerOptions,
16091609
/*lastFileExceededProgramSize*/ this.getFilenameForExceededTotalSizeLimitForNonTsFiles(projectFileName, compilerOptions, files, externalFilePropertyReader),
1610-
options.compileOnSave === undefined ? true : options.compileOnSave);
1610+
options.compileOnSave === undefined ? true : options.compileOnSave,
1611+
/*projectFilePath*/ undefined, this.currentPluginConfigOverrides);
16111612
project.excludedFiles = excludedFiles;
16121613

16131614
this.addFilesToNonInferredProject(project, files, externalFilePropertyReader, typeAcquisition);

src/server/project.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,8 @@ namespace ts.server {
16101610
compilerOptions: CompilerOptions,
16111611
lastFileExceededProgramSize: string | undefined,
16121612
public compileOnSaveEnabled: boolean,
1613-
projectFilePath?: string) {
1613+
projectFilePath?: string,
1614+
pluginConfigOverrides?: Map<any>) {
16141615
super(externalProjectName,
16151616
ProjectKind.External,
16161617
projectService,
@@ -1621,6 +1622,7 @@ namespace ts.server {
16211622
compileOnSaveEnabled,
16221623
projectService.host,
16231624
getDirectoryPath(projectFilePath || normalizeSlashes(externalProjectName)));
1625+
this.enableGlobalPlugins(this.getCompilerOptions(), pluginConfigOverrides);
16241626
}
16251627

16261628
updateGraph() {

src/server/protocol.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,9 @@ namespace ts.server.protocol {
13921392
arguments: ConfigurePluginRequestArguments;
13931393
}
13941394

1395+
export interface ConfigurePluginResponse extends Response {
1396+
}
1397+
13951398
/**
13961399
* Information found in an "open" request.
13971400
*/

src/server/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,7 @@ namespace ts.server {
24122412
},
24132413
[CommandNames.ConfigurePlugin]: (request: protocol.ConfigurePluginRequest) => {
24142414
this.configurePlugin(request.arguments);
2415+
this.doOutput(/*info*/ undefined, CommandNames.ConfigurePlugin, request.seq, /*success*/ true);
24152416
return this.notRequired();
24162417
}
24172418
});

src/testRunner/unittests/tsserver/externalProjects.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,68 @@ namespace ts.projectSystem {
5050
});
5151
});
5252

53+
it("load global plugins", () => {
54+
const f1 = {
55+
path: "/a/file1.ts",
56+
content: "let x = [1, 2];"
57+
};
58+
const p1 = { projectFileName: "/a/proj1.csproj", rootFiles: [toExternalFile(f1.path)], options: {} };
59+
60+
const host = createServerHost([f1]);
61+
host.require = (_initialPath, moduleName) => {
62+
assert.equal(moduleName, "myplugin");
63+
return {
64+
module: () => ({
65+
create(info: server.PluginCreateInfo) {
66+
const proxy = Harness.LanguageService.makeDefaultProxy(info);
67+
proxy.getSemanticDiagnostics = filename => {
68+
const prev = info.languageService.getSemanticDiagnostics(filename);
69+
const sourceFile: SourceFile = info.project.getSourceFile(toPath(filename, /*basePath*/ undefined, createGetCanonicalFileName(info.serverHost.useCaseSensitiveFileNames)))!;
70+
prev.push({
71+
category: DiagnosticCategory.Warning,
72+
file: sourceFile,
73+
code: 9999,
74+
length: 3,
75+
messageText: `Plugin diagnostic`,
76+
start: 0
77+
});
78+
return prev;
79+
};
80+
return proxy;
81+
}
82+
}),
83+
error: undefined
84+
};
85+
};
86+
const session = createSession(host, { globalPlugins: ["myplugin"] });
87+
88+
session.executeCommand(<protocol.OpenExternalProjectsRequest>{
89+
seq: 1,
90+
type: "request",
91+
command: "openExternalProjects",
92+
arguments: { projects: [p1] }
93+
});
94+
95+
const projectService = session.getProjectService();
96+
checkNumberOfProjects(projectService, { externalProjects: 1 });
97+
assert.equal(projectService.externalProjects[0].getProjectName(), p1.projectFileName);
98+
99+
const handlerResponse = session.executeCommand(<protocol.SemanticDiagnosticsSyncRequest>{
100+
seq: 2,
101+
type: "request",
102+
command: "semanticDiagnosticsSync",
103+
arguments: {
104+
file: f1.path,
105+
projectFileName: p1.projectFileName
106+
}
107+
});
108+
109+
assert.isDefined(handlerResponse.response);
110+
const response = handlerResponse.response as protocol.Diagnostic[];
111+
assert.equal(response.length, 1);
112+
assert.equal(response[0].text, "Plugin diagnostic");
113+
});
114+
53115
it("remove not-listed external projects", () => {
54116
const f1 = {
55117
path: "/a/app.ts",

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6748,6 +6748,8 @@ declare namespace ts.server.protocol {
67486748
command: CommandTypes.ConfigurePlugin;
67496749
arguments: ConfigurePluginRequestArguments;
67506750
}
6751+
interface ConfigurePluginResponse extends Response {
6752+
}
67516753
/**
67526754
* Information found in an "open" request.
67536755
*/

0 commit comments

Comments
 (0)