-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* relint when schema changes * Create blue-rice-arrive.md
- Loading branch information
Showing
5 changed files
with
99 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"cm6-graphql": patch | ||
--- | ||
|
||
relint when schema changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,60 @@ | ||
import { Diagnostic, linter } from '@codemirror/lint'; | ||
import { getDiagnostics } from 'graphql-language-service'; | ||
import { Position, posToOffset } from './helpers'; | ||
import { getSchema } from './state'; | ||
import { getSchema, optionsStateField, schemaStateField } from './state'; | ||
import { Extension } from '@codemirror/state'; | ||
|
||
const SEVERITY = ['error', 'warning', 'info'] as const; | ||
|
||
export const lint = linter(view => { | ||
const schema = getSchema(view.state); | ||
if (!schema) { | ||
return []; | ||
} | ||
const results = getDiagnostics(view.state.doc.toString(), schema); | ||
export const lint: Extension = linter( | ||
view => { | ||
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 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(_)); | ||
}, | ||
{ | ||
needsRefresh(vu) { | ||
return ( | ||
vu.startState.field(schemaStateField) !== | ||
vu.state.field(schemaStateField) || | ||
vu.startState.field(optionsStateField) !== | ||
vu.state.field(optionsStateField) | ||
); | ||
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(_)); | ||
}); | ||
}, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters