Skip to content

Commit

Permalink
Wrap cm6-graphql lint logic in try..catch (#3461)
Browse files Browse the repository at this point in the history
* Wrap cm6-graphql lint logic in try..catch

* Create silver-lions-build.md
  • Loading branch information
imolorhe committed Nov 17, 2023
1 parent e1ee54e commit 129666a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-lions-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cm6-graphql": patch
---

Wrap cm6-graphql lint logic in try..catch
76 changes: 40 additions & 36 deletions packages/cm6-graphql/src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,48 @@ const SEVERITY = ['error', 'warning', 'info'] as const;

export const lint: Extension = linter(
view => {
const schema = getSchema(view.state);
if (!schema) {
return [];
}
const results = getDiagnostics(view.state.doc.toString(), schema);
try {
const schema = getSchema(view.state);
if (!schema) {
return [];
}
const results = getDiagnostics(view.state.doc.toString(), schema);

return results
.map((item): Diagnostic | null => {
if (!item.severity || !item.source) {
return null;
}
return results
.map((item): Diagnostic | null => {
if (!item.severity || !item.source) {
return null;
}

const calculatedFrom = posToOffset(
view.state.doc,
new Position(item.range.start.line, item.range.start.character),
);
const from = Math.max(
0,
Math.min(calculatedFrom, view.state.doc.length),
);
const calculatedRo = posToOffset(
view.state.doc,
new Position(item.range.end.line, item.range.end.character - 1),
);
const to = Math.min(
Math.max(from + 1, calculatedRo),
view.state.doc.length,
);
return {
from,
to: from === to ? to + 1 : to,
severity: SEVERITY[item.severity - 1],
// source: item.source, // TODO:
message: item.message,
actions: [], // TODO:
};
})
.filter((_): _ is Diagnostic => Boolean(_));
const calculatedFrom = posToOffset(
view.state.doc,
new Position(item.range.start.line, item.range.start.character),
);
const from = Math.max(
0,
Math.min(calculatedFrom, view.state.doc.length),
);
const calculatedRo = posToOffset(
view.state.doc,
new Position(item.range.end.line, item.range.end.character - 1),
);
const to = Math.min(
Math.max(from + 1, calculatedRo),
view.state.doc.length,
);
return {
from,
to: from === to ? to + 1 : to,
severity: SEVERITY[item.severity - 1],
// source: item.source, // TODO:
message: item.message,
actions: [], // TODO:
};
})
.filter((_): _ is Diagnostic => Boolean(_));
} catch {
return [];
}
},
{
needsRefresh(vu) {
Expand Down

0 comments on commit 129666a

Please sign in to comment.