Skip to content

Commit 930e4c5

Browse files
committed
Add flag to allow local plugin loading
1 parent 47e5569 commit 930e4c5

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/server/editorServices.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ namespace ts.server {
283283
throttleWaitMilliseconds?: number;
284284
globalPlugins?: string[];
285285
pluginProbeLocations?: string[];
286+
allowLocalPluginLoads?: boolean;
286287
}
287288

288289
export class ProjectService {
@@ -342,6 +343,7 @@ namespace ts.server {
342343

343344
public readonly globalPlugins: ReadonlyArray<string>;
344345
public readonly pluginProbeLocations: ReadonlyArray<string>;
346+
public readonly allowLocalPluginLoads: boolean;
345347

346348
constructor(opts: ProjectServiceOptions) {
347349
this.host = opts.host;
@@ -353,6 +355,7 @@ namespace ts.server {
353355
this.eventHandler = opts.eventHandler;
354356
this.globalPlugins = opts.globalPlugins || emptyArray;
355357
this.pluginProbeLocations = opts.pluginProbeLocations || emptyArray;
358+
this.allowLocalPluginLoads = !!opts.allowLocalPluginLoads;
356359

357360
Debug.assert(!!this.host.createHash, "'ServerHost.createHash' is required for ProjectService");
358361

src/server/project.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,12 @@ namespace ts.server {
873873
// ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/
874874
const searchPaths = [combinePaths(host.getExecutingFilePath(), "../../.."), ...this.projectService.pluginProbeLocations];
875875

876+
if (this.projectService.allowLocalPluginLoads) {
877+
const local = getDirectoryPath(this.canonicalConfigFilePath);
878+
this.projectService.logger.info(`Local plugin loading enabled; adding ${local} to search paths`);
879+
searchPaths.unshift(local);
880+
}
881+
876882
// Enable tsconfig-specified plugins
877883
if (options.plugins) {
878884
for (const pluginConfigEntry of options.plugins) {

src/server/server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ts.server {
1616
telemetryEnabled: boolean;
1717
globalPlugins: string[];
1818
pluginProbeLocations: string[];
19+
allowLocalPluginLoads: boolean;
1920
}
2021

2122
const net: {
@@ -403,7 +404,8 @@ namespace ts.server {
403404
logger,
404405
canUseEvents,
405406
globalPlugins: options.globalPlugins,
406-
pluginProbeLocations: options.pluginProbeLocations});
407+
pluginProbeLocations: options.pluginProbeLocations,
408+
allowLocalPluginLoads: options.allowLocalPluginLoads });
407409

408410
if (telemetryEnabled && typingsInstaller) {
409411
typingsInstaller.setTelemetrySender(this);
@@ -744,6 +746,7 @@ namespace ts.server {
744746

745747
const globalPlugins = (findArgument("--globalPlugins") || "").split(",");
746748
const pluginProbeLocations = (findArgument("--pluginProbeLocations") || "").split(",");
749+
const allowLocalPluginLoads = hasArgument("--allowLocalPluginLoads");
747750

748751
const useSingleInferredProject = hasArgument("--useSingleInferredProject");
749752
const disableAutomaticTypingAcquisition = hasArgument("--disableAutomaticTypingAcquisition");
@@ -761,7 +764,8 @@ namespace ts.server {
761764
telemetryEnabled,
762765
logger,
763766
globalPlugins,
764-
pluginProbeLocations
767+
pluginProbeLocations,
768+
allowLocalPluginLoads
765769
};
766770

767771
const ioSession = new IOSession(options);

src/server/session.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ namespace ts.server {
348348

349349
globalPlugins?: string[];
350350
pluginProbeLocations?: string[];
351+
allowLocalPluginLoads?: boolean;
351352
}
352353

353354
export class Session implements EventSender {
@@ -401,7 +402,8 @@ namespace ts.server {
401402
throttleWaitMilliseconds,
402403
eventHandler: this.eventHandler,
403404
globalPlugins: opts.globalPlugins,
404-
pluginProbeLocations: opts.pluginProbeLocations
405+
pluginProbeLocations: opts.pluginProbeLocations,
406+
allowLocalPluginLoads: opts.allowLocalPluginLoads
405407
};
406408
this.projectService = new ProjectService(settings);
407409
this.gcTimer = new GcTimer(this.host, /*delay*/ 7000, this.logger);

0 commit comments

Comments
 (0)