Skip to content

Commit d293e72

Browse files
authoredAug 31, 2022
Rename API to importPlugin (#50554)
* Rename API to importPlugin * Make it internal too
1 parent 19defbf commit d293e72

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed
 

‎src/server/editorServices.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4068,7 +4068,7 @@ namespace ts.server {
40684068

40694069
/*@internal*/
40704070
requestEnablePlugin(project: Project, pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map<any> | undefined) {
4071-
if (!this.host.importServicePlugin && !this.host.require) {
4071+
if (!this.host.importPlugin && !this.host.require) {
40724072
this.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded");
40734073
return;
40744074
}
@@ -4080,7 +4080,7 @@ namespace ts.server {
40804080
}
40814081

40824082
// If the host supports dynamic import, begin enabling the plugin asynchronously.
4083-
if (this.host.importServicePlugin) {
4083+
if (this.host.importPlugin) {
40844084
const importPromise = project.beginEnablePluginAsync(pluginConfigEntry, searchPaths, pluginConfigOverrides);
40854085
this.pendingPluginEnablements ??= new Map();
40864086
let promises = this.pendingPluginEnablements.get(project);

‎src/server/project.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ namespace ts.server {
256256

257257
/*@internal*/
258258
public static async importServicePluginAsync(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void, logErrors?: (message: string) => void): Promise<{} | undefined> {
259-
Debug.assertIsDefined(host.importServicePlugin);
259+
Debug.assertIsDefined(host.importPlugin);
260260
const resolvedPath = combinePaths(initialDir, "node_modules");
261261
log(`Dynamically importing ${moduleName} from ${initialDir} (resolved to ${resolvedPath})`);
262262
let result: ModuleImportResult;
263263
try {
264-
result = await host.importServicePlugin(resolvedPath, moduleName);
264+
result = await host.importPlugin(resolvedPath, moduleName);
265265
}
266266
catch (e) {
267267
result = { module: undefined, error: e };
@@ -1607,7 +1607,7 @@ namespace ts.server {
16071607
protected enableGlobalPlugins(options: CompilerOptions, pluginConfigOverrides: Map<any> | undefined): void {
16081608
const host = this.projectService.host;
16091609

1610-
if (!host.require && !host.importServicePlugin) {
1610+
if (!host.require && !host.importPlugin) {
16111611
this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded");
16121612
return;
16131613
}
@@ -1658,7 +1658,7 @@ namespace ts.server {
16581658
*/
16591659
/*@internal*/
16601660
async beginEnablePluginAsync(pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map<any> | undefined): Promise<BeginEnablePluginResult> {
1661-
Debug.assertIsDefined(this.projectService.host.importServicePlugin);
1661+
Debug.assertIsDefined(this.projectService.host.importPlugin);
16621662

16631663
let errorLogs: string[] | undefined;
16641664
const log = (message: string) => this.projectService.logger.info(message);
@@ -2522,8 +2522,7 @@ namespace ts.server {
25222522
/*@internal*/
25232523
enablePluginsWithOptions(options: CompilerOptions, pluginConfigOverrides: ESMap<string, any> | undefined): void {
25242524
const host = this.projectService.host;
2525-
2526-
if (!host.require && !host.importServicePlugin) {
2525+
if (!host.require && !host.importPlugin) {
25272526
this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded");
25282527
return;
25292528
}

‎src/server/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare namespace ts.server {
2020
gc?(): void;
2121
trace?(s: string): void;
2222
require?(initialPath: string, moduleName: string): ModuleImportResult;
23-
importServicePlugin?(root: string, moduleName: string): Promise<ModuleImportResult>;
23+
/*@internal*/
24+
importPlugin?(root: string, moduleName: string): Promise<ModuleImportResult>;
2425
}
2526
}

‎src/testRunner/unittests/tsserver/webServer.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace ts.projectSystem {
2929
}
3030
}
3131

32-
function setup(logLevel: server.LogLevel | undefined, options?: Partial<server.StartSessionOptions>, importServicePlugin?: server.ServerHost["importServicePlugin"]) {
32+
function setup(logLevel: server.LogLevel | undefined, options?: Partial<server.StartSessionOptions>, importPlugin?: server.ServerHost["importPlugin"]) {
3333
const host = createServerHost([libFile], { windowsStyleRoot: "c:/" });
3434
const messages: any[] = [];
3535
const webHost: server.WebHost = {
@@ -38,7 +38,7 @@ namespace ts.projectSystem {
3838
writeMessage: s => messages.push(s),
3939
};
4040
const webSys = server.createWebSystem(webHost, emptyArray, () => host.getExecutingFilePath());
41-
webSys.importServicePlugin = importServicePlugin;
41+
webSys.importPlugin = importPlugin;
4242
const logger = logLevel !== undefined ? new server.MainProcessLogger(logLevel, webHost) : nullLogger();
4343
const session = new TestWorkerSession(webSys, webHost, { serverMode: LanguageServiceMode.PartialSemantic, ...options }, logger);
4444
return { getMessages: () => messages, clearMessages: () => messages.length = 0, session };
@@ -161,7 +161,7 @@ namespace ts.projectSystem {
161161
it("plugins are not loaded immediately", async () => {
162162
let pluginModuleInstantiated = false;
163163
let pluginInvoked = false;
164-
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
164+
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
165165
await Promise.resolve(); // simulate at least a single turn delay
166166
pluginModuleInstantiated = true;
167167
return {
@@ -173,7 +173,7 @@ namespace ts.projectSystem {
173173
};
174174
};
175175

176-
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
176+
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
177177
const projectService = session.getProjectService();
178178

179179
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
@@ -201,7 +201,7 @@ namespace ts.projectSystem {
201201
const pluginADeferred = Utils.defer();
202202
const pluginBDeferred = Utils.defer();
203203
const log: string[] = [];
204-
const importServicePlugin = async (_root: string, moduleName: string): Promise<server.ModuleImportResult> => {
204+
const importPlugin = async (_root: string, moduleName: string): Promise<server.ModuleImportResult> => {
205205
log.push(`request import ${moduleName}`);
206206
const promise = moduleName === "plugin-a" ? pluginADeferred.promise : pluginBDeferred.promise;
207207
await promise;
@@ -215,7 +215,7 @@ namespace ts.projectSystem {
215215
};
216216
};
217217

218-
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a", "plugin-b"] }, importServicePlugin);
218+
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a", "plugin-b"] }, importPlugin);
219219
const projectService = session.getProjectService();
220220

221221
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
@@ -241,15 +241,15 @@ namespace ts.projectSystem {
241241
});
242242

243243
it("sends projectsUpdatedInBackground event", async () => {
244-
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
244+
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
245245
await Promise.resolve(); // simulate at least a single turn delay
246246
return {
247247
module: (() => ({ create: info => info.languageService })) as server.PluginModuleFactory,
248248
error: undefined
249249
};
250250
};
251251

252-
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
252+
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
253253
const projectService = session.getProjectService();
254254

255255
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
@@ -270,7 +270,7 @@ namespace ts.projectSystem {
270270
const pluginAShouldLoad = Utils.defer();
271271
const pluginAExternalFilesRequested = Utils.defer();
272272

273-
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
273+
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
274274
// wait until the initial external files are requested from the project service.
275275
await pluginAShouldLoad.promise;
276276

@@ -287,7 +287,7 @@ namespace ts.projectSystem {
287287
};
288288
};
289289

290-
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
290+
const { session } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
291291
const projectService = session.getProjectService();
292292

293293
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });
@@ -316,7 +316,7 @@ namespace ts.projectSystem {
316316
it("project is closed before plugins are loaded", async () => {
317317
const pluginALoaded = Utils.defer();
318318
const projectClosed = Utils.defer();
319-
const importServicePlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
319+
const importPlugin = async (_root: string, _moduleName: string): Promise<server.ModuleImportResult> => {
320320
// mark that the plugin has started loading
321321
pluginALoaded.resolve();
322322

@@ -328,7 +328,7 @@ namespace ts.projectSystem {
328328
};
329329
};
330330

331-
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importServicePlugin);
331+
const { session, getMessages } = setup(/*logLevel*/ undefined, { globalPlugins: ["plugin-a"] }, importPlugin);
332332
const projectService = session.getProjectService();
333333

334334
session.executeCommand({ seq: 1, type: "request", command: protocol.CommandTypes.Open, arguments: { file: "^memfs:/foo.ts", content: "" } });

‎src/webServer/webServer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ namespace ts.server {
162162
clearImmediate: handle => clearTimeout(handle),
163163
/* eslint-enable no-restricted-globals */
164164

165-
importServicePlugin: async (initialDir: string, moduleName: string): Promise<ModuleImportResult> => {
165+
importPlugin: async (initialDir: string, moduleName: string): Promise<ModuleImportResult> => {
166166
const packageRoot = combinePaths(initialDir, moduleName);
167167

168168
let packageJson: any | undefined;

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

-1
Original file line numberDiff line numberDiff line change
@@ -7044,7 +7044,6 @@ declare namespace ts.server {
70447044
gc?(): void;
70457045
trace?(s: string): void;
70467046
require?(initialPath: string, moduleName: string): ModuleImportResult;
7047-
importServicePlugin?(root: string, moduleName: string): Promise<ModuleImportResult>;
70487047
}
70497048
}
70507049
declare namespace ts.server {

0 commit comments

Comments
 (0)
Please sign in to comment.