feat: graphql language improvements
This commit is contained in:
@@ -1,18 +1,26 @@
|
|||||||
import {parser} from "./syntax.grammar"
|
import {parser} from "./syntax.grammar"
|
||||||
import {LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent} from "@codemirror/language"
|
import {LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent} from "@codemirror/language"
|
||||||
import {styleTags, tags as t} from "@codemirror/highlight"
|
import {styleTags, tags as t} from "@codemirror/highlight"
|
||||||
|
|
||||||
export const GQLLanguage = LRLanguage.define({
|
export const GQLLanguage = LRLanguage.define({
|
||||||
parser: parser.configure({
|
parser: parser.configure({
|
||||||
props: [
|
props: [
|
||||||
indentNodeProp.add({
|
indentNodeProp.add({
|
||||||
Application: delimitedIndent({closing: ")", align: false})
|
"SelectionSet FieldsDefinition ObjectValue SchemaDefinition RootTypeDef": delimitedIndent({ closing: "}", align: true }),
|
||||||
}),
|
}),
|
||||||
foldNodeProp.add({
|
foldNodeProp.add({
|
||||||
Application: foldInside
|
Application: foldInside,
|
||||||
|
"SelectionSet FieldsDefinition ObjectValue RootOperationTypeDefinition RootTypeDef": (node) => {
|
||||||
|
return {
|
||||||
|
from: node.from,
|
||||||
|
to: node.to
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
styleTags({
|
styleTags({
|
||||||
Name: t.propertyName,
|
Name: t.definition(t.variableName),
|
||||||
|
"OperationDefinition/Name": t.definition(t.function(t.variableName)),
|
||||||
OperationType: t.keyword,
|
OperationType: t.keyword,
|
||||||
BooleanValue: t.bool,
|
BooleanValue: t.bool,
|
||||||
StringValue: t.string,
|
StringValue: t.string,
|
||||||
|
|||||||
@@ -34,11 +34,15 @@ TypeSystemExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SchemaDefinition {
|
SchemaDefinition {
|
||||||
Description? @specialize<Name, "schema"> Directives? "{" RootOperationTypeDefinition+ "}"
|
Description? @specialize<Name, "schema"> Directives? RootTypeDef
|
||||||
|
}
|
||||||
|
|
||||||
|
RootTypeDef {
|
||||||
|
"{" RootOperationTypeDefinition+ "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
SchemaExtension {
|
SchemaExtension {
|
||||||
@specialize<Name, "extend"> @specialize<Name, "schema"> Directives? "{" RootOperationTypeDefinition "}"
|
@specialize<Name, "extend"> @specialize<Name, "schema"> Directives? RootTypeDef
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeExtension {
|
TypeExtension {
|
||||||
@@ -172,7 +176,7 @@ VariableDefinition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SelectionSet {
|
SelectionSet {
|
||||||
"{" Selection+ "}"
|
"{" Selection* "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
Selection {
|
Selection {
|
||||||
|
|||||||
@@ -48,10 +48,19 @@ const hoppCompleterExt = (completer: Completer): Extension => {
|
|||||||
// Expensive operation! Disable on bigger files ?
|
// Expensive operation! Disable on bigger files ?
|
||||||
const text = context.state.doc.toJSON().join(context.state.lineBreak)
|
const text = context.state.doc.toJSON().join(context.state.lineBreak)
|
||||||
|
|
||||||
const line = context.state.doc.lineAt(context.pos).from
|
const line = context.state.doc.lineAt(context.pos)
|
||||||
const ch = context.pos - line
|
const lineStart = line.from
|
||||||
|
const lineNo = line.number - 1
|
||||||
|
const ch = context.pos - lineStart
|
||||||
|
|
||||||
const result = await completer(text, { line, ch })
|
// Only do trigger on type when typing a word token, else stop (unless explicit)
|
||||||
|
if (!context.matchBefore(/\w+/) && !context.explicit)
|
||||||
|
return {
|
||||||
|
from: context.pos,
|
||||||
|
options: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await completer(text, { line: lineNo, ch })
|
||||||
|
|
||||||
// Use more completion features ?
|
// Use more completion features ?
|
||||||
const completions =
|
const completions =
|
||||||
|
|||||||
Reference in New Issue
Block a user