Skip to content

Commit

Permalink
Set flags to disable parts of diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Matsuuu committed Nov 7, 2023
1 parent 17dd51e commit 9f32246
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@ Generating a CEM in watch mode will provide you with the best user experience. I

The current featureset is as follows:

- Support HTML files and html`` -template literals
- Provides Completions for custom elements defined in the local Custom Elements Manifest and ones in node_modules
- Provides type hints for attributes and properties on html tages
- Provides Go To Definition -functionality for Custom Elements defined in the Custom Elements Manifest
- Provides diagnostics on missing imports and unclosed custom element tags
- Support HTML files and html`` -template literals
- Provides Completions for custom elements defined in the local Custom Elements Manifest and ones in node_modules
- Provides type hints for attributes and properties on html tages
- Provides Go To Definition -functionality for Custom Elements defined in the Custom Elements Manifest
- Provides diagnostics on missing imports and unclosed custom element tags

### Disabling diagnostics

Sometimes CELS might catch some diagnostics that might not be useful for your usecase.

Adding a comment anywhere in your code with the given code, will disable diagnostics for said file.

These diagnostics can be disbled with the following flags:

| Command | Action |
| --------------------------- | ------------------------------------------------------ |
| cels-disable-diagnostics | Disable all diagnostics |
| cels-disable-missing-closed | Disable diagnostics for non-closed custom element tags |
| cels-disable-import-check | Disable checks for non-imported custom elements |

## Installing

Expand Down Expand Up @@ -63,5 +77,4 @@ These operations include but are not limited to
- Slot name autocompletions
- Event binding completions


Via installing a plugin to your favorite editor to support LSP actions, you are able to enable all of these Language Service functionalities.
27 changes: 21 additions & 6 deletions lib/server/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { textDocumentToUsableData, tsDiagnosticToDiagnostic } from "./transforme
import { createCustomElementsLanguageServiceRequestFromQueryData } from "./language-services/request";
import { generateLanguageServiceQueryDataForDiagnostics } from "./handlers/handler-helper";

const DISABLE_FLAGS = {
DISABLE_ALL: "cels-disable-diagnostics",
DISABLE_MISSING_CLOSED: "cels-disable-missing-closed",
DISABLE_IMPORT_CHECK: "cels-disable-import-check"
}

export async function runDiagnostics(uri: string, textDoc: TextDocument) {
handleDiagnostics(uri, textDoc);
}
Expand All @@ -16,20 +22,29 @@ function handleDiagnostics(uri: string, textDoc: TextDocument) {
const fileName = url.fileURLToPath(uri);

Check warning on line 22 in lib/server/src/diagnostics.ts

View workflow job for this annotation

GitHub Actions / Qodana for JS

Unused local symbol

Unused constant fileName
const usableData = textDocumentToUsableData(textDoc);
const queryData = generateLanguageServiceQueryDataForDiagnostics(usableData, textDoc.uri);
const text = textDoc.getText();
const disableDiagnostics = text.includes(DISABLE_FLAGS.DISABLE_ALL);


if (disableDiagnostics) {
connection.sendDiagnostics({ uri: textDoc.uri, diagnostics: [] });
return;
}

if (!queryData.isValid) {
return;
}

const request = createCustomElementsLanguageServiceRequestFromQueryData(queryData);

// TODO: We need to make importdiagnostics disableable since all file format's can't and won't set this.
// Maybe a flag? if file.includes("cels-disable-import-check")
const importDiagnostics = getImportDiagnostics(request);
const nonClosedTagDiagnostics = getMissingCloseTagDiagnostics(0, request);
let diagnostics: ts.Diagnostic[] = [];

// TODO: Filter diagnostics calls by filetype. No need for imports for md etc.? Or is there?
const diagnostics = [...importDiagnostics, ...nonClosedTagDiagnostics];
if (!text.includes(DISABLE_FLAGS.DISABLE_MISSING_CLOSED)) {
diagnostics = [...getMissingCloseTagDiagnostics(0, request)];
}
if (!text.includes(DISABLE_FLAGS.DISABLE_IMPORT_CHECK)) {
diagnostics = [...getImportDiagnostics(request)];
}

try {
const sendableDiagnostics: Array<Diagnostic> = diagnostics
Expand Down

0 comments on commit 9f32246

Please sign in to comment.