diff --git a/lib/server/src/diagnostics.ts b/lib/server/src/diagnostics.ts index 78e2357..b8597b7 100644 --- a/lib/server/src/diagnostics.ts +++ b/lib/server/src/diagnostics.ts @@ -14,10 +14,24 @@ const DISABLE_FLAGS = { DISABLE_IMPORT_CHECK: "cels-disable-import-check" } +const DEFAULT_DISABLE_IMPORT_CHECKS_FILETYPES = ["md", "html", "php"]; + export async function runDiagnostics(uri: string, textDoc: TextDocument) { handleDiagnostics(uri, textDoc); } +function shouldIgnoreImportDiagnostics(fileName: string) { + const fileExtension = fileName.split(".").at(-1) ?? "__CELS_NO_ENDING"; + if (DEFAULT_DISABLE_IMPORT_CHECKS_FILETYPES.includes(fileExtension)) { + return true; + } + if (!fileName.endsWith(fileExtension)) { + return true; + } + + return false; +} + function handleDiagnostics(uri: string, textDoc: TextDocument) { const fileName = url.fileURLToPath(uri); const usableData = textDocumentToUsableData(textDoc); @@ -25,7 +39,6 @@ function handleDiagnostics(uri: string, textDoc: TextDocument) { const text = textDoc.getText(); const disableDiagnostics = text.includes(DISABLE_FLAGS.DISABLE_ALL); - if (disableDiagnostics) { connection.sendDiagnostics({ uri: textDoc.uri, diagnostics: [] }); return; @@ -42,7 +55,7 @@ function handleDiagnostics(uri: string, textDoc: TextDocument) { if (!text.includes(DISABLE_FLAGS.DISABLE_MISSING_CLOSED)) { diagnostics = [...diagnostics, ...getMissingCloseTagDiagnostics(request)]; } - if (!text.includes(DISABLE_FLAGS.DISABLE_IMPORT_CHECK)) { + if (!text.includes(DISABLE_FLAGS.DISABLE_IMPORT_CHECK) && !shouldIgnoreImportDiagnostics(fileName)) { diagnostics = [...diagnostics, ...getImportDiagnostics(request)]; } diff --git a/usage-testing-project/src/card.astro b/usage-testing-project/src/card.astro index ff0045e..3ebca4d 100644 --- a/usage-testing-project/src/card.astro +++ b/usage-testing-project/src/card.astro @@ -1,5 +1,4 @@ --- -import "./example-project.js"; interface Props { title: string; body: string; diff --git a/usage-testing-project/src/index.php b/usage-testing-project/src/index.php index 8f62a22..916e5d5 100644 --- a/usage-testing-project/src/index.php +++ b/usage-testing-project/src/index.php @@ -3,6 +3,6 @@ ?>