Skip to content

Commit

Permalink
fix: make no Svelte files found a warning (#2507)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dummdidumm authored Sep 19, 2024
1 parent 94a7352 commit e132b56
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/language-server/src/plugins/typescript/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { dirname, join, resolve, basename } from 'path';
import ts from 'typescript';
import {
DiagnosticSeverity,
PublishDiagnosticsParams,
RelativePattern,
TextDocumentContentChangeEvent
Expand Down Expand Up @@ -803,7 +804,7 @@ async function createLanguageService(
const excludeText = JSON.stringify(exclude);
const svelteConfigDiagnostics: ts.Diagnostic[] = [
{
category: ts.DiagnosticCategory.Error,
category: ts.DiagnosticCategory.Warning,
code: TsconfigSvelteDiagnostics.NO_SVELTE_INPUT,
file: undefined,
start: undefined,
Expand Down Expand Up @@ -977,13 +978,14 @@ async function createLanguageService(
diagnostics: svelteConfigDiagnostics.map((d) => ({
message: d.messageText as string,
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } },
severity: ts.DiagnosticCategory.Error,
severity: DiagnosticSeverity.Warning,
source: 'svelte'
}))
});
projectConfig.errors = projectConfig.errors
const new_errors = projectConfig.errors
.filter((e) => !codes.includes(e.code))
.concat(svelteConfigDiagnostics);
projectConfig.errors.splice(0, projectConfig.errors.length, ...new_errors);
}

// https://github.com/microsoft/TypeScript/blob/23faef92703556567ddbcb9afb893f4ba638fc20/src/server/project.ts#L1624
Expand Down
16 changes: 13 additions & 3 deletions packages/language-server/src/svelte-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,23 @@ export class SvelteCheck {
};
};

if (lsContainer.configErrors.length > 0) {
if (
lsContainer.configErrors.some((error) => error.category === ts.DiagnosticCategory.Error)
) {
return reportConfigError();
}

const lang = lsContainer.getService();
if (lsContainer.configErrors.length > 0) {
if (
lsContainer.configErrors.some((error) => error.category === ts.DiagnosticCategory.Error)
) {
return reportConfigError();
}

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

return await Promise.all(
const diagnostics = await Promise.all(
files.map((file) => {
const uri = pathToUrl(file.fileName);
const doc = this.docManager.get(uri);
Expand Down Expand Up @@ -314,6 +318,12 @@ export class SvelteCheck {
})
);

if (lsContainer.configErrors.length) {
diagnostics.push(...reportConfigError());
}

return diagnostics;

function reportConfigError() {
const grouped = groupBy(
lsContainer.configErrors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export function processInstanceScriptContent(
const tsAst = ts.createSourceFile(
'component.ts.svelte',
scriptContent,
ts.ScriptTarget.Latest,
ts.JSDocParsingMode
? {
languageVersion: ts.ScriptTarget.Latest,
// Exists since TS 5.3
jsDocParsingMode: ts.JSDocParsingMode.ParseNone
}
: ts.ScriptTarget.Latest,
true,
ts.ScriptKind.TS
);
Expand Down

0 comments on commit e132b56

Please sign in to comment.