Skip to content

Commit

Permalink
tweak word, test
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Aug 21, 2024
1 parent eec3b2b commit fd22d6a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/language-server/src/plugins/typescript/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, join, resolve } from 'path';
import { dirname, join, resolve, basename } from 'path';
import ts from 'typescript';
import {
PublishDiagnosticsParams,
Expand Down Expand Up @@ -777,7 +777,10 @@ async function createLanguageService(
file: undefined,
start: undefined,
length: undefined,
messageText: `No svelte input files were found in config file '${tsconfigPath}'. Specified 'include' paths were '${inputText}' and 'exclude' paths were '${excludeText}'`,
messageText:
`No svelte input files were found in config file '${tsconfigPath}'. ` +
`Did you forget to add svelte files to the "include" in your ${basename(tsconfigPath)}? ` +
`Specified 'include' paths were '${inputText}' and 'exclude' paths were '${excludeText}'`,
source: 'svelte'
}
];
Expand Down
85 changes: 85 additions & 0 deletions packages/language-server/test/plugins/typescript/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,91 @@ describe('service', () => {
});
});

it('errors if tsconfig matches no svelte files', async () => {
const dirPath = getRandomVirtualDirPath(testDir);
const { virtualSystem, lsDocumentContext, rootUris } = setup();

virtualSystem.readDirectory = () => [path.join(dirPath, 'random.ts')];

virtualSystem.writeFile(
path.join(dirPath, 'tsconfig.json'),
JSON.stringify({
include: ['**/*.ts']
})
);

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

let called = false;
await getService(path.join(dirPath, 'random.svelte'), rootUris, {
...lsDocumentContext,
reportConfigError: (message) => {
called = true;
assert.equal(message.uri, pathToUrl(path.join(dirPath, 'tsconfig.json')));
}
});
assert.ok(called);
});

it('do not errors if referenced tsconfig matches no svelte files', async () => {
const dirPath = getRandomVirtualDirPath(testDir);
const { virtualSystem, lsDocumentContext, rootUris } = setup();

const tsPattern = '**/*.ts';
const sveltePattern = '**/*.svelte';
virtualSystem.readDirectory = (_path, _extensions, _excludes, include) => {
return include?.[0] === tsPattern
? [path.join(dirPath, 'random.ts')]
: include?.[0] === sveltePattern
? [path.join(dirPath, 'random.svelte')]
: [];
};

virtualSystem.writeFile(
path.join(dirPath, 'tsconfig.json'),
JSON.stringify({
include: [],
references: [{ path: './tsconfig_node.json' }, { path: './tsconfig_web.json' }]
})
);

virtualSystem.writeFile(
path.join(dirPath, 'tsconfig_node.json'),
JSON.stringify({
include: [tsPattern]
})
);

virtualSystem.writeFile(
path.join(dirPath, 'tsconfig_web.json'),
JSON.stringify({
include: [sveltePattern]
})
);

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

let called = false;
const lsContainer = await getService(path.join(dirPath, 'random.svelte'), rootUris, {
...lsDocumentContext,
reportConfigError: () => {
called = true;
}
});

assert.equal(
normalizePath(path.join(dirPath, 'tsconfig_web.json')),
lsContainer.tsconfigPath
);
assert.equal(called, false, 'expected not to call reportConfigError');
});

it('can loads default tsconfig', async () => {
const dirPath = getRandomVirtualDirPath(testDir);
const { lsDocumentContext, rootUris } = setup();
Expand Down

0 comments on commit fd22d6a

Please sign in to comment.