Skip to content

Commit 6a5ad09

Browse files
authored
more attempt to fix memory issues in sapper workspace (#967)
* more attempt to fix memory issues in sapper workspace * fix filename check
1 parent 9613233 commit 6a5ad09

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

packages/language-server/src/plugins/typescript/SnapshotManager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,5 @@ export class SnapshotManager {
122122
}
123123
}
124124
}
125+
126+
export const ignoredBuildDirectories = ['__sapper__', '.svelte'];

packages/language-server/src/plugins/typescript/TypeScriptPlugin.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import { getDirectiveCommentCompletions } from './features/getDirectiveCommentCo
6464
import { FindReferencesProviderImpl } from './features/FindReferencesProvider';
6565
import { SelectionRangeProviderImpl } from './features/SelectionRangeProvider';
6666
import { SignatureHelpProviderImpl } from './features/SignatureHelpProvider';
67-
import { SnapshotManager } from './SnapshotManager';
67+
import { ignoredBuildDirectories, SnapshotManager } from './SnapshotManager';
6868
import { SemanticTokensProviderImpl } from './features/SemanticTokensProvider';
6969
import { isNoTextSpanInGeneratedCode, SnapshotFragmentMap } from './features/utils';
7070

@@ -367,8 +367,13 @@ export class TypeScriptPlugin
367367
const doneUpdateProjectFiles = new Set<SnapshotManager>();
368368

369369
for (const { fileName, changeType } of onWatchFileChangesParas) {
370-
const scriptKind = getScriptKindFromFileName(fileName);
370+
const pathParts = fileName.split(/\/|\\/);
371+
const dirPathParts = pathParts.slice(0, pathParts.length - 1);
372+
if (ignoredBuildDirectories.some((dir) => dirPathParts.includes(dir))) {
373+
continue;
374+
}
371375

376+
const scriptKind = getScriptKindFromFileName(fileName);
372377
if (scriptKind === ts.ScriptKind.Unknown) {
373378
// We don't deal with svelte files here
374379
continue;
@@ -382,7 +387,10 @@ export class TypeScriptPlugin
382387
}
383388
} else if (changeType === FileChangeType.Deleted) {
384389
snapshotManager.delete(fileName);
385-
} else {
390+
} else if (snapshotManager.has(fileName)) {
391+
// Only allow existing files to be update
392+
// Otherwise, new files would still get loaded
393+
// into snapshot manager after update
386394
snapshotManager.updateTsOrJsFile(fileName);
387395
}
388396
}

packages/language-server/src/plugins/typescript/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Logger } from '../../logger';
55
import { getPackageInfo } from '../../importPackage';
66
import { DocumentSnapshot } from './DocumentSnapshot';
77
import { createSvelteModuleLoader } from './module-loader';
8-
import { SnapshotManager } from './SnapshotManager';
8+
import { ignoredBuildDirectories, SnapshotManager } from './SnapshotManager';
99
import { ensureRealSvelteFilePath, findTsConfigPath } from './utils';
1010
import { configLoader } from '../../lib/documents/configLoader';
1111

@@ -269,6 +269,6 @@ async function createLanguageService(
269269
}
270270

271271
function getDefaultExclude() {
272-
return ['__sapper__', 'node_modules'];
272+
return ['node_modules', ...ignoredBuildDirectories];
273273
}
274274
}

packages/language-server/test/plugins/typescript/TypescriptPlugin.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { LSConfigManager } from '../../../src/ls-config';
88
import { TypeScriptPlugin } from '../../../src/plugins';
99
import { INITIAL_VERSION } from '../../../src/plugins/typescript/DocumentSnapshot';
1010
import { pathToUrl, urlToPath } from '../../../src/utils';
11+
import { ignoredBuildDirectories } from '../../../src/plugins/typescript/SnapshotManager';
1112

1213
describe('TypescriptPlugin', () => {
1314
function getUri(filename: string) {
@@ -454,6 +455,15 @@ describe('TypescriptPlugin', () => {
454455
]);
455456

456457
assert.equal(snapshotManager.has(normalizedAddFilePath), shouldExist);
458+
459+
await plugin.onWatchFileChanges([
460+
{
461+
fileName: normalizedAddFilePath,
462+
changeType: FileChangeType.Changed
463+
}
464+
]);
465+
466+
assert.equal(snapshotManager.has(normalizedAddFilePath), shouldExist);
457467
} finally {
458468
fs.unlinkSync(addFile);
459469
}
@@ -467,6 +477,12 @@ describe('TypescriptPlugin', () => {
467477
await testForOnWatchedFileAdd(path.join('dist', 'index.js'), false);
468478
});
469479

480+
it('should not add snapshot when files added to known build directory', async () => {
481+
for (const dir of ignoredBuildDirectories) {
482+
await testForOnWatchedFileAdd(path.join(dir, 'index.js'), false);
483+
}
484+
});
485+
470486
it('should update ts/js file after document change', async () => {
471487
const {
472488
snapshotManager,

0 commit comments

Comments
 (0)