Skip to content

Commit e132b56

Browse files
authored
fix: make no Svelte files found a warning (#2507)
There were reports that this was too overzealous as some people use this potentially not knowing whether or not this is a Svelte-projects, too. Therefore only issue a warning instead of an error.
1 parent 94a7352 commit e132b56

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { dirname, join, resolve, basename } from 'path';
22
import ts from 'typescript';
33
import {
4+
DiagnosticSeverity,
45
PublishDiagnosticsParams,
56
RelativePattern,
67
TextDocumentContentChangeEvent
@@ -803,7 +804,7 @@ async function createLanguageService(
803804
const excludeText = JSON.stringify(exclude);
804805
const svelteConfigDiagnostics: ts.Diagnostic[] = [
805806
{
806-
category: ts.DiagnosticCategory.Error,
807+
category: ts.DiagnosticCategory.Warning,
807808
code: TsconfigSvelteDiagnostics.NO_SVELTE_INPUT,
808809
file: undefined,
809810
start: undefined,
@@ -977,13 +978,14 @@ async function createLanguageService(
977978
diagnostics: svelteConfigDiagnostics.map((d) => ({
978979
message: d.messageText as string,
979980
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
980-
severity: ts.DiagnosticCategory.Error,
981+
severity: DiagnosticSeverity.Warning,
981982
source: 'svelte'
982983
}))
983984
});
984-
projectConfig.errors = projectConfig.errors
985+
const new_errors = projectConfig.errors
985986
.filter((e) => !codes.includes(e.code))
986987
.concat(svelteConfigDiagnostics);
988+
projectConfig.errors.splice(0, projectConfig.errors.length, ...new_errors);
987989
}
988990

989991
// https://github.com/microsoft/TypeScript/blob/23faef92703556567ddbcb9afb893f4ba638fc20/src/server/project.ts#L1624

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,23 @@ export class SvelteCheck {
208208
};
209209
};
210210

211-
if (lsContainer.configErrors.length > 0) {
211+
if (
212+
lsContainer.configErrors.some((error) => error.category === ts.DiagnosticCategory.Error)
213+
) {
212214
return reportConfigError();
213215
}
214216

215217
const lang = lsContainer.getService();
216-
if (lsContainer.configErrors.length > 0) {
218+
if (
219+
lsContainer.configErrors.some((error) => error.category === ts.DiagnosticCategory.Error)
220+
) {
217221
return reportConfigError();
218222
}
219223

220224
const files = lang.getProgram()?.getSourceFiles() || [];
221225
const options = lang.getProgram()?.getCompilerOptions() || {};
222226

223-
return await Promise.all(
227+
const diagnostics = await Promise.all(
224228
files.map((file) => {
225229
const uri = pathToUrl(file.fileName);
226230
const doc = this.docManager.get(uri);
@@ -314,6 +318,12 @@ export class SvelteCheck {
314318
})
315319
);
316320

321+
if (lsContainer.configErrors.length) {
322+
diagnostics.push(...reportConfigError());
323+
}
324+
325+
return diagnostics;
326+
317327
function reportConfigError() {
318328
const grouped = groupBy(
319329
lsContainer.configErrors,

packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ export function processInstanceScriptContent(
4949
const tsAst = ts.createSourceFile(
5050
'component.ts.svelte',
5151
scriptContent,
52-
ts.ScriptTarget.Latest,
52+
ts.JSDocParsingMode
53+
? {
54+
languageVersion: ts.ScriptTarget.Latest,
55+
// Exists since TS 5.3
56+
jsDocParsingMode: ts.JSDocParsingMode.ParseNone
57+
}
58+
: ts.ScriptTarget.Latest,
5359
true,
5460
ts.ScriptKind.TS
5561
);

0 commit comments

Comments
 (0)