Skip to content

Commit a872bc6

Browse files
authored
(feat) svelte-check diagnostic-sources (#542)
#541 Decide which sources to use for diagnostics
1 parent 9009d88 commit a872bc6

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

packages/language-server/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './server';
22
export { offsetAt } from './lib/documents';
3-
export { SvelteCheck, SvelteCheckOptions } from './svelte-check';
3+
export { SvelteCheck, SvelteCheckOptions, SvelteCheckDiagnosticSource } from './svelte-check';

packages/language-server/src/svelte-check.ts

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { Document, DocumentManager } from './lib/documents';
22
import { LSConfigManager } from './ls-config';
3-
import { CSSPlugin, HTMLPlugin, PluginHost, SveltePlugin, TypeScriptPlugin } from './plugins';
3+
import { CSSPlugin, PluginHost, SveltePlugin, TypeScriptPlugin } from './plugins';
44
import { Diagnostic } from 'vscode-languageserver';
55
import { Logger } from './logger';
66
import { urlToPath, pathToUrl } from './utils';
77

8+
export type SvelteCheckDiagnosticSource = 'js' | 'css' | 'svelte';
9+
810
export interface SvelteCheckOptions {
911
compilerWarnings?: Record<string, 'ignore' | 'error'>;
12+
diagnosticSources?: SvelteCheckDiagnosticSource[];
1013
}
1114

1215
/**
@@ -31,12 +34,24 @@ export class SvelteCheck {
3134
compilerWarnings: options.compilerWarnings,
3235
},
3336
});
34-
this.pluginHost.register(new SveltePlugin(this.configManager, {}));
35-
this.pluginHost.register(new HTMLPlugin(this.docManager, this.configManager));
36-
this.pluginHost.register(new CSSPlugin(this.docManager, this.configManager));
37-
this.pluginHost.register(
38-
new TypeScriptPlugin(this.docManager, this.configManager, [pathToUrl(workspacePath)]),
39-
);
37+
// No HTMLPlugin, it does not provide diagnostics
38+
if (shouldRegister('svelte')) {
39+
this.pluginHost.register(new SveltePlugin(this.configManager, {}));
40+
}
41+
if (shouldRegister('css')) {
42+
this.pluginHost.register(new CSSPlugin(this.docManager, this.configManager));
43+
}
44+
if (shouldRegister('js')) {
45+
this.pluginHost.register(
46+
new TypeScriptPlugin(this.docManager, this.configManager, [
47+
pathToUrl(workspacePath),
48+
]),
49+
);
50+
}
51+
52+
function shouldRegister(source: SvelteCheckDiagnosticSource) {
53+
return !options.diagnosticSources || options.diagnosticSources.includes(source);
54+
}
4055
}
4156

4257
/**

packages/svelte-check/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Usage:
6262

6363
`--compiler-warnings <code1:error|ignore,code2:error|ignore>` A list of Svelte compiler warning codes. Each entry defines whether that warning should be ignored or treated as an error. Warnings are comma-separated, between warning code and error level is a colon; all inside quotes. Example: --compiler-warnings "css-unused-selector:ignore,unused-export-let:error"
6464

65+
`--diagnostic-sources <js,svelte,css>` A list of diagnostic sources which should run diagnostics on your code. Possible values are `js` (includes TS), `svelte`, `css`. Comma-separated, inside quotes. By default all are active. Example: --diagnostic-sources "js,svelte"
66+
6567
### More docs, preprocessor setup and troubleshooting
6668

6769
[See here](/docs/README.md).

packages/svelte-check/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ function instantiateWriter(myArgs: argv.ParsedArgs): Writer {
137137
function getOptions(myArgs: argv.ParsedArgs): SvelteCheckOptions {
138138
return {
139139
compilerWarnings: stringToObj(myArgs['compiler-warnings']),
140+
diagnosticSources: <any>(
141+
myArgs['diagnostic-sources']?.split(',')?.map((s: string) => s.trim())
142+
),
140143
};
141144

142145
function stringToObj(str = '') {

0 commit comments

Comments
 (0)