Skip to content

Commit b5f37a1

Browse files
Merge pull request #15060 from RyanCavanaugh/fixPluginLoading
Only load plugins from correct folders
2 parents 28c0eed + 92eaf5d commit b5f37a1

File tree

9 files changed

+273
-108
lines changed

9 files changed

+273
-108
lines changed

src/harness/harnessLanguageService.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,17 @@ namespace Harness.LanguageService {
818818
// This host is just a proxy for the clientHost, it uses the client
819819
// host to answer server queries about files on disk
820820
const serverHost = new SessionServerHost(clientHost);
821-
const server = new ts.server.Session(serverHost,
822-
ts.server.nullCancellationToken,
823-
/*useOneInferredProject*/ false,
824-
/*typingsInstaller*/ undefined,
825-
Utils.byteLength,
826-
process.hrtime, serverHost,
827-
/*canUseEvents*/ true);
821+
const opts: ts.server.SessionOptions = {
822+
host: serverHost,
823+
cancellationToken: ts.server.nullCancellationToken,
824+
useSingleInferredProject: false,
825+
typingsInstaller: undefined,
826+
byteLength: Utils.byteLength,
827+
hrtime: process.hrtime,
828+
logger: serverHost,
829+
canUseEvents: true
830+
};
831+
const server = new ts.server.Session(opts);
828832

829833
// Fake the connection between the client and the server
830834
serverHost.writeMessage = client.onMessage.bind(client);

src/harness/unittests/cachingInServerLSHost.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@ namespace ts {
6464
getLogFileName: (): string => undefined
6565
};
6666

67-
const projectService = new server.ProjectService(serverHost, logger, { isCancellationRequested: () => false }, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined);
68-
const rootScriptInfo = projectService.getOrCreateScriptInfo(rootFile, /*openedByClient*/ true, /*containingProject*/ undefined);
67+
const svcOpts: server.ProjectServiceOptions = {
68+
host: serverHost,
69+
logger,
70+
cancellationToken: { isCancellationRequested: () => false },
71+
useSingleInferredProject: false,
72+
typingsInstaller: undefined
73+
};
74+
const projectService = new server.ProjectService(svcOpts);
75+
const rootScriptInfo = projectService.getOrCreateScriptInfo(rootFile, /* openedByClient */ true, /*containingProject*/ undefined);
76+
6977
const project = projectService.createInferredProjectWithRootFileIfNecessary(rootScriptInfo);
7078
project.setCompilerOptions({ module: ts.ModuleKind.AMD } );
7179
return {

src/harness/unittests/compileOnSave.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ namespace ts.projectSystem {
3131
}
3232
}
3333

34+
function createSession(host: server.ServerHost, typingsInstaller?: server.ITypingsInstaller): server.Session {
35+
const opts: server.SessionOptions = {
36+
host,
37+
cancellationToken: nullCancellationToken,
38+
useSingleInferredProject: false,
39+
typingsInstaller: typingsInstaller || server.nullTypingsInstaller,
40+
byteLength: Utils.byteLength,
41+
hrtime: process.hrtime,
42+
logger: nullLogger,
43+
canUseEvents: false
44+
};
45+
return new server.Session(opts);
46+
}
47+
3448
describe("for configured projects", () => {
3549
let moduleFile1: FileOrFolder;
3650
let file1Consumer1: FileOrFolder;
@@ -113,7 +127,7 @@ namespace ts.projectSystem {
113127
it("should contains only itself if a module file's shape didn't change, and all files referencing it if its shape changed", () => {
114128
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
115129
const typingsInstaller = createTestTypingsInstaller(host);
116-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
130+
const session = createSession(host, typingsInstaller);
117131

118132
openFilesForSession([moduleFile1, file1Consumer1], session);
119133

@@ -138,7 +152,7 @@ namespace ts.projectSystem {
138152
it("should be up-to-date with the reference map changes", () => {
139153
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
140154
const typingsInstaller = createTestTypingsInstaller(host);
141-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
155+
const session = createSession(host, typingsInstaller);
142156

143157
openFilesForSession([moduleFile1, file1Consumer1], session);
144158

@@ -185,7 +199,7 @@ namespace ts.projectSystem {
185199
it("should be up-to-date with changes made in non-open files", () => {
186200
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
187201
const typingsInstaller = createTestTypingsInstaller(host);
188-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
202+
const session = createSession(host, typingsInstaller);
189203

190204
openFilesForSession([moduleFile1], session);
191205

@@ -203,7 +217,7 @@ namespace ts.projectSystem {
203217
it("should be up-to-date with deleted files", () => {
204218
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
205219
const typingsInstaller = createTestTypingsInstaller(host);
206-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
220+
const session = createSession(host, typingsInstaller);
207221

208222
openFilesForSession([moduleFile1], session);
209223
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2] }]);
@@ -218,7 +232,7 @@ namespace ts.projectSystem {
218232
it("should be up-to-date with newly created files", () => {
219233
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
220234
const typingsInstaller = createTestTypingsInstaller(host);
221-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
235+
const session = createSession(host, typingsInstaller);
222236

223237
openFilesForSession([moduleFile1], session);
224238
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer2] }]);
@@ -255,7 +269,7 @@ namespace ts.projectSystem {
255269

256270
const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
257271
const typingsInstaller = createTestTypingsInstaller(host);
258-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
272+
const session = createSession(host, typingsInstaller);
259273

260274
openFilesForSession([moduleFile1, file1Consumer1], session);
261275
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1] }]);
@@ -272,7 +286,7 @@ namespace ts.projectSystem {
272286
it("should return all files if a global file changed shape", () => {
273287
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, globalFile3, moduleFile2, configFile, libFile]);
274288
const typingsInstaller = createTestTypingsInstaller(host);
275-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
289+
const session = createSession(host, typingsInstaller);
276290

277291
openFilesForSession([globalFile3], session);
278292
const changeGlobalFile3ShapeRequest = makeSessionRequest<server.protocol.ChangeRequestArgs>(CommandNames.Change, {
@@ -298,7 +312,7 @@ namespace ts.projectSystem {
298312

299313
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer2, configFile, libFile]);
300314
const typingsInstaller = createTestTypingsInstaller(host);
301-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
315+
const session = createSession(host, typingsInstaller);
302316
openFilesForSession([moduleFile1], session);
303317
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, []);
304318
});
@@ -316,7 +330,7 @@ namespace ts.projectSystem {
316330

317331
const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
318332
const typingsInstaller = createTestTypingsInstaller(host);
319-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
333+
const session = createSession(host, typingsInstaller);
320334
openFilesForSession([moduleFile1], session);
321335

322336
const file1ChangeShapeRequest = makeSessionRequest<server.protocol.ChangeRequestArgs>(CommandNames.Change, {
@@ -345,7 +359,7 @@ namespace ts.projectSystem {
345359

346360
const host = createServerHost([moduleFile1, file1Consumer1, configFile, libFile]);
347361
const typingsInstaller = createTestTypingsInstaller(host);
348-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
362+
const session = createSession(host, typingsInstaller);
349363
openFilesForSession([moduleFile1], session);
350364

351365
const file1ChangeShapeRequest = makeSessionRequest<server.protocol.ChangeRequestArgs>(CommandNames.Change, {
@@ -367,7 +381,7 @@ namespace ts.projectSystem {
367381
};
368382
const host = createServerHost([moduleFile1, file1Consumer1, file1Consumer1Consumer1, globalFile3, configFile, libFile]);
369383
const typingsInstaller = createTestTypingsInstaller(host);
370-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
384+
const session = createSession(host, typingsInstaller);
371385

372386
openFilesForSession([moduleFile1, file1Consumer1], session);
373387
sendAffectedFileRequestAndCheckResult(session, moduleFile1FileListRequest, [{ projectFileName: configFile.path, files: [moduleFile1, file1Consumer1, file1Consumer1Consumer1] }]);
@@ -400,7 +414,7 @@ namespace ts.projectSystem {
400414
};
401415
const host = createServerHost([file1, file2, configFile]);
402416
const typingsInstaller = createTestTypingsInstaller(host);
403-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
417+
const session = createSession(host, typingsInstaller);
404418

405419
openFilesForSession([file1, file2], session);
406420
const file1AffectedListRequest = makeSessionRequest<server.protocol.FileRequestArgs>(CommandNames.CompileOnSaveAffectedFileList, { file: file1.path });
@@ -513,7 +527,7 @@ namespace ts.projectSystem {
513527
};
514528
const host = createServerHost([file1, file2, configFile, libFile], { newLine: "\r\n" });
515529
const typingsInstaller = createTestTypingsInstaller(host);
516-
const session = new server.Session(host, nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ false);
530+
const session = createSession(host, typingsInstaller);
517531

518532
openFilesForSession([file1, file2], session);
519533
const compileFileRequest = makeSessionRequest<server.protocol.CompileOnSaveEmitFileRequestArgs>(CommandNames.CompileOnSaveEmitFile, { file: file1.path, projectFileName: configFile.path });

src/harness/unittests/session.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,22 @@ namespace ts.server {
5050
let session: TestSession;
5151
let lastSent: protocol.Message;
5252

53+
function createSession(): TestSession {
54+
const opts: server.SessionOptions = {
55+
host: mockHost,
56+
cancellationToken: nullCancellationToken,
57+
useSingleInferredProject: false,
58+
typingsInstaller: undefined,
59+
byteLength: Utils.byteLength,
60+
hrtime: process.hrtime,
61+
logger: mockLogger,
62+
canUseEvents: true
63+
};
64+
return new TestSession(opts);
65+
}
66+
5367
beforeEach(() => {
54-
session = new TestSession(mockHost, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined, Utils.byteLength, process.hrtime, mockLogger, /*canUseEvents*/ true);
68+
session = createSession();
5569
session.send = (msg: protocol.Message) => {
5670
lastSent = msg;
5771
};
@@ -318,7 +332,16 @@ namespace ts.server {
318332
lastSent: protocol.Message;
319333
customHandler = "testhandler";
320334
constructor() {
321-
super(mockHost, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined, Utils.byteLength, process.hrtime, mockLogger, /*canUseEvents*/ true);
335+
super({
336+
host: mockHost,
337+
cancellationToken: nullCancellationToken,
338+
useSingleInferredProject: false,
339+
typingsInstaller: undefined,
340+
byteLength: Utils.byteLength,
341+
hrtime: process.hrtime,
342+
logger: mockLogger,
343+
canUseEvents: true
344+
});
322345
this.addProtocolHandler(this.customHandler, () => {
323346
return { response: undefined, responseRequired: true };
324347
});
@@ -376,7 +399,16 @@ namespace ts.server {
376399
class InProcSession extends Session {
377400
private queue: protocol.Request[] = [];
378401
constructor(private client: InProcClient) {
379-
super(mockHost, nullCancellationToken, /*useOneInferredProject*/ false, /*typingsInstaller*/ undefined, Utils.byteLength, process.hrtime, mockLogger, /*canUseEvents*/ true);
402+
super({
403+
host: mockHost,
404+
cancellationToken: nullCancellationToken,
405+
useSingleInferredProject: false,
406+
typingsInstaller: undefined,
407+
byteLength: Utils.byteLength,
408+
hrtime: process.hrtime,
409+
logger: mockLogger,
410+
canUseEvents: true
411+
});
380412
this.addProtocolHandler("echo", (req: protocol.Request) => ({
381413
response: req.arguments,
382414
responseRequired: true

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,19 @@ namespace ts.projectSystem {
190190
if (typingsInstaller === undefined) {
191191
typingsInstaller = new TestTypingsInstaller("/a/data/", /*throttleLimit*/5, host);
192192
}
193-
return new TestSession(host, cancellationToken || server.nullCancellationToken, /*useSingleInferredProject*/ false, typingsInstaller, Utils.byteLength, process.hrtime, nullLogger, /*canUseEvents*/ projectServiceEventHandler !== undefined, projectServiceEventHandler, throttleWaitMilliseconds);
193+
const opts: server.SessionOptions = {
194+
host,
195+
cancellationToken: cancellationToken || server.nullCancellationToken,
196+
useSingleInferredProject: false,
197+
typingsInstaller,
198+
byteLength: Utils.byteLength,
199+
hrtime: process.hrtime,
200+
logger: nullLogger,
201+
canUseEvents: projectServiceEventHandler !== undefined,
202+
eventHandler: projectServiceEventHandler,
203+
throttleWaitMilliseconds
204+
};
205+
return new TestSession(opts);
194206
}
195207

196208
export interface CreateProjectServiceParameters {
@@ -205,7 +217,9 @@ namespace ts.projectSystem {
205217
export class TestProjectService extends server.ProjectService {
206218
constructor(host: server.ServerHost, logger: server.Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean,
207219
typingsInstaller: server.ITypingsInstaller, eventHandler: server.ProjectServiceEventHandler) {
208-
super(host, logger, cancellationToken, useSingleInferredProject, typingsInstaller, eventHandler);
220+
super({
221+
host, logger, cancellationToken, useSingleInferredProject, typingsInstaller, eventHandler
222+
});
209223
}
210224

211225
checkNumberOfProjects(count: { inferredProjects?: number, configuredProjects?: number, externalProjects?: number }) {

0 commit comments

Comments
 (0)