Skip to content

Commit

Permalink
breaking: put non-project files to default service
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Aug 16, 2024
1 parent 006e807 commit 6f87833
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
12 changes: 8 additions & 4 deletions packages/language-server/src/plugins/typescript/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export async function getService(
);
};

const tsconfigPath =
let tsconfigPath =
configFileForOpenFiles.get(path) ??
findTsConfigPath(path, workspaceUris, fileExistsWithCache, getCanonicalFileName);

Expand All @@ -171,9 +171,13 @@ export async function getService(
return service;
}

service = (await findDefaultServiceForFile(service, triedTsConfig)) ?? service;
configFileForOpenFiles.set(path, service.tsconfigPath);
return service;
const defaultService = await findDefaultServiceForFile(service, triedTsConfig);
if (defaultService) {
configFileForOpenFiles.set(path, defaultService.tsconfigPath);
return defaultService;
}

tsconfigPath = '';
}

// Find closer boundary: workspace uri or node_modules
Expand Down
39 changes: 23 additions & 16 deletions packages/language-server/test/plugins/typescript/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ describe('service', () => {
})
);

virtualSystem.writeFile(
path.join(dirPath, 'random.svelte'),
'<script>const a: number = null;</script>'
);

const ls = await getService(
path.join(dirPath, 'random.svelte'),
rootUris,
Expand Down Expand Up @@ -89,6 +94,11 @@ describe('service', () => {
})
);

virtualSystem.writeFile(
path.join(dirPath, 'random.svelte'),
'<script>const a: number = null;</script>'
);

const ls = await getService(
path.join(dirPath, 'random.svelte'),
rootUris,
Expand Down Expand Up @@ -160,6 +170,11 @@ describe('service', () => {
})
);

virtualSystem.writeFile(
path.join(dirPath, 'random.svelte'),
'<script>const a: number = null;</script>'
);

const { reloadPromise, docContextWithReload } = createReloadTester(
{ ...lsDocumentContext, watchTsConfig: true },
testAfterReload
Expand Down Expand Up @@ -207,6 +222,11 @@ describe('service', () => {
})
);

virtualSystem.writeFile(
path.join(dirPath, 'random.svelte'),
'<script>const a: number = null;</script>'
);

const { reloadPromise, docContextWithReload } = createReloadTester(
{ ...lsDocumentContext, watchTsConfig: true },
testAfterReload
Expand Down Expand Up @@ -304,18 +324,9 @@ describe('service', () => {

it('can open client file that do not exist in fs', async () => {
const dirPath = getRandomVirtualDirPath(testDir);
const { virtualSystem, lsDocumentContext, rootUris } = setup();

virtualSystem.writeFile(
path.join(dirPath, 'tsconfig.json'),
JSON.stringify({
compilerOptions: <ts.CompilerOptions>{
checkJs: true,
strict: true
}
})
);
const { lsDocumentContext, rootUris } = setup();

// don't need tsconfig because files doesn't exist in fs goes to a service with default config
const ls = await getService(
path.join(dirPath, 'random.svelte'),
rootUris,
Expand Down Expand Up @@ -380,11 +391,7 @@ describe('service', () => {
return fileExists(realPath);
};

const ls = await getService(
path.join(package1, 'DoNotMatter.svelte'),
rootUris,
lsDocumentContext
);
const ls = await getService(importing, rootUris, lsDocumentContext);

assert.deepStrictEqual(getSemanticDiagnosticsMessages(ls, importing), []);
});
Expand Down

0 comments on commit 6f87833

Please sign in to comment.