mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
* ensure configurePlugin gives a response * Update tests * Update baseline * Enable global plugin loading for external projects * Fix lint errors
This commit is contained in:
@@ -90,7 +90,7 @@ namespace ts.server {
|
||||
return <T>request;
|
||||
}
|
||||
|
||||
private processResponse<T extends protocol.Response>(request: protocol.Request): T {
|
||||
private processResponse<T extends protocol.Response>(request: protocol.Request, expectEmptyBody = false): T {
|
||||
let foundResponseMessage = false;
|
||||
let response!: T;
|
||||
while (!foundResponseMessage) {
|
||||
@@ -118,7 +118,8 @@ namespace ts.server {
|
||||
throw new Error("Error " + response.message);
|
||||
}
|
||||
|
||||
Debug.assert(!!response.body, "Malformed response: Unexpected empty response body.");
|
||||
Debug.assert(expectEmptyBody || !!response.body, "Malformed response: Unexpected empty response body.");
|
||||
Debug.assert(!expectEmptyBody || !response.body, "Malformed response: Unexpected non-empty response body.");
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -696,7 +697,8 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
configurePlugin(pluginName: string, configuration: any): void {
|
||||
this.processRequest<protocol.ConfigurePluginRequest>("configurePlugin", { pluginName, configuration });
|
||||
const request = this.processRequest<protocol.ConfigurePluginRequest>("configurePlugin", { pluginName, configuration });
|
||||
this.processResponse<protocol.ConfigurePluginResponse>(request, /*expectEmptyBody*/ true);
|
||||
}
|
||||
|
||||
getIndentationAtPosition(_fileName: string, _position: number, _options: EditorOptions): number {
|
||||
|
||||
@@ -1607,7 +1607,8 @@ namespace ts.server {
|
||||
this.documentRegistry,
|
||||
compilerOptions,
|
||||
/*lastFileExceededProgramSize*/ this.getFilenameForExceededTotalSizeLimitForNonTsFiles(projectFileName, compilerOptions, files, externalFilePropertyReader),
|
||||
options.compileOnSave === undefined ? true : options.compileOnSave);
|
||||
options.compileOnSave === undefined ? true : options.compileOnSave,
|
||||
/*projectFilePath*/ undefined, this.currentPluginConfigOverrides);
|
||||
project.excludedFiles = excludedFiles;
|
||||
|
||||
this.addFilesToNonInferredProject(project, files, externalFilePropertyReader, typeAcquisition);
|
||||
|
||||
@@ -1610,7 +1610,8 @@ namespace ts.server {
|
||||
compilerOptions: CompilerOptions,
|
||||
lastFileExceededProgramSize: string | undefined,
|
||||
public compileOnSaveEnabled: boolean,
|
||||
projectFilePath?: string) {
|
||||
projectFilePath?: string,
|
||||
pluginConfigOverrides?: Map<any>) {
|
||||
super(externalProjectName,
|
||||
ProjectKind.External,
|
||||
projectService,
|
||||
@@ -1621,6 +1622,7 @@ namespace ts.server {
|
||||
compileOnSaveEnabled,
|
||||
projectService.host,
|
||||
getDirectoryPath(projectFilePath || normalizeSlashes(externalProjectName)));
|
||||
this.enableGlobalPlugins(this.getCompilerOptions(), pluginConfigOverrides);
|
||||
}
|
||||
|
||||
updateGraph() {
|
||||
|
||||
@@ -1392,6 +1392,9 @@ namespace ts.server.protocol {
|
||||
arguments: ConfigurePluginRequestArguments;
|
||||
}
|
||||
|
||||
export interface ConfigurePluginResponse extends Response {
|
||||
}
|
||||
|
||||
/**
|
||||
* Information found in an "open" request.
|
||||
*/
|
||||
|
||||
@@ -2412,6 +2412,7 @@ namespace ts.server {
|
||||
},
|
||||
[CommandNames.ConfigurePlugin]: (request: protocol.ConfigurePluginRequest) => {
|
||||
this.configurePlugin(request.arguments);
|
||||
this.doOutput(/*info*/ undefined, CommandNames.ConfigurePlugin, request.seq, /*success*/ true);
|
||||
return this.notRequired();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,6 +50,68 @@ namespace ts.projectSystem {
|
||||
});
|
||||
});
|
||||
|
||||
it("load global plugins", () => {
|
||||
const f1 = {
|
||||
path: "/a/file1.ts",
|
||||
content: "let x = [1, 2];"
|
||||
};
|
||||
const p1 = { projectFileName: "/a/proj1.csproj", rootFiles: [toExternalFile(f1.path)], options: {} };
|
||||
|
||||
const host = createServerHost([f1]);
|
||||
host.require = (_initialPath, moduleName) => {
|
||||
assert.equal(moduleName, "myplugin");
|
||||
return {
|
||||
module: () => ({
|
||||
create(info: server.PluginCreateInfo) {
|
||||
const proxy = Harness.LanguageService.makeDefaultProxy(info);
|
||||
proxy.getSemanticDiagnostics = filename => {
|
||||
const prev = info.languageService.getSemanticDiagnostics(filename);
|
||||
const sourceFile: SourceFile = info.project.getSourceFile(toPath(filename, /*basePath*/ undefined, createGetCanonicalFileName(info.serverHost.useCaseSensitiveFileNames)))!;
|
||||
prev.push({
|
||||
category: DiagnosticCategory.Warning,
|
||||
file: sourceFile,
|
||||
code: 9999,
|
||||
length: 3,
|
||||
messageText: `Plugin diagnostic`,
|
||||
start: 0
|
||||
});
|
||||
return prev;
|
||||
};
|
||||
return proxy;
|
||||
}
|
||||
}),
|
||||
error: undefined
|
||||
};
|
||||
};
|
||||
const session = createSession(host, { globalPlugins: ["myplugin"] });
|
||||
|
||||
session.executeCommand(<protocol.OpenExternalProjectsRequest>{
|
||||
seq: 1,
|
||||
type: "request",
|
||||
command: "openExternalProjects",
|
||||
arguments: { projects: [p1] }
|
||||
});
|
||||
|
||||
const projectService = session.getProjectService();
|
||||
checkNumberOfProjects(projectService, { externalProjects: 1 });
|
||||
assert.equal(projectService.externalProjects[0].getProjectName(), p1.projectFileName);
|
||||
|
||||
const handlerResponse = session.executeCommand(<protocol.SemanticDiagnosticsSyncRequest>{
|
||||
seq: 2,
|
||||
type: "request",
|
||||
command: "semanticDiagnosticsSync",
|
||||
arguments: {
|
||||
file: f1.path,
|
||||
projectFileName: p1.projectFileName
|
||||
}
|
||||
});
|
||||
|
||||
assert.isDefined(handlerResponse.response);
|
||||
const response = handlerResponse.response as protocol.Diagnostic[];
|
||||
assert.equal(response.length, 1);
|
||||
assert.equal(response[0].text, "Plugin diagnostic");
|
||||
});
|
||||
|
||||
it("remove not-listed external projects", () => {
|
||||
const f1 = {
|
||||
path: "/a/app.ts",
|
||||
|
||||
@@ -6748,6 +6748,8 @@ declare namespace ts.server.protocol {
|
||||
command: CommandTypes.ConfigurePlugin;
|
||||
arguments: ConfigurePluginRequestArguments;
|
||||
}
|
||||
interface ConfigurePluginResponse extends Response {
|
||||
}
|
||||
/**
|
||||
* Information found in an "open" request.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user