Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS IntelliCode-related changes #30731

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/harness/client.ts
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/server/editorServices.ts
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/server/project.ts
Expand Up @@ -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,
Expand All @@ -1621,6 +1622,7 @@ namespace ts.server {
compileOnSaveEnabled,
projectService.host,
getDirectoryPath(projectFilePath || normalizeSlashes(externalProjectName)));
this.enableGlobalPlugins(this.getCompilerOptions(), pluginConfigOverrides);
}

updateGraph() {
Expand Down
3 changes: 3 additions & 0 deletions src/server/protocol.ts
Expand Up @@ -1392,6 +1392,9 @@ namespace ts.server.protocol {
arguments: ConfigurePluginRequestArguments;
}

export interface ConfigurePluginResponse extends Response {
}

/**
* Information found in an "open" request.
*/
Expand Down
1 change: 1 addition & 0 deletions src/server/session.ts
Expand Up @@ -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();
}
});
Expand Down
62 changes: 62 additions & 0 deletions src/testRunner/unittests/tsserver/externalProjects.ts
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Expand Up @@ -6748,6 +6748,8 @@ declare namespace ts.server.protocol {
command: CommandTypes.ConfigurePlugin;
arguments: ConfigurePluginRequestArguments;
}
interface ConfigurePluginResponse extends Response {
}
/**
* Information found in an "open" request.
*/
Expand Down