From d22c3b0c257f5daf5b401988a35ab9ce981a2341 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Fri, 12 Aug 2022 19:54:46 +0200 Subject: refactor(frontend): move from Webpack to Vite Also overhaulds the building and linting for frontend assets. --- subprojects/frontend/src/language/folding.ts | 9 ++++++--- subprojects/frontend/src/language/indentation.ts | 19 ++++++++++--------- subprojects/frontend/src/language/problem.grammar | 2 +- .../frontend/src/language/problemLanguageSupport.ts | 11 ++++------- subprojects/frontend/src/language/props.ts | 2 ++ 5 files changed, 23 insertions(+), 20 deletions(-) (limited to 'subprojects/frontend/src/language') diff --git a/subprojects/frontend/src/language/folding.ts b/subprojects/frontend/src/language/folding.ts index 2560c183..9d1c04a3 100644 --- a/subprojects/frontend/src/language/folding.ts +++ b/subprojects/frontend/src/language/folding.ts @@ -1,7 +1,7 @@ -import { EditorState } from '@codemirror/state'; +import type { EditorState } from '@codemirror/state'; import type { SyntaxNode } from '@lezer/common'; -export type FoldRange = { from: number, to: number }; +export type FoldRange = { from: number; to: number }; /** * Folds a block comment between its delimiters. @@ -47,7 +47,10 @@ export function foldBlockComment(node: SyntaxNode): FoldRange { * @param state the editor state * @returns the folding range or `null` is there is nothing to fold */ -export function foldDeclaration(node: SyntaxNode, state: EditorState): FoldRange | null { +export function foldDeclaration( + node: SyntaxNode, + state: EditorState, +): FoldRange | null { const { firstChild: open, lastChild: close } = node; if (open === null || close === null) { return null; diff --git a/subprojects/frontend/src/language/indentation.ts b/subprojects/frontend/src/language/indentation.ts index 1c38637f..0bd2423c 100644 --- a/subprojects/frontend/src/language/indentation.ts +++ b/subprojects/frontend/src/language/indentation.ts @@ -1,4 +1,4 @@ -import { TreeIndentContext } from '@codemirror/language'; +import type { TreeIndentContext } from '@codemirror/language'; /** * Finds the `from` of first non-skipped token, if any, @@ -11,18 +11,16 @@ import { TreeIndentContext } from '@codemirror/language'; * @returns the alignment or `null` if there is no token after the opening keyword */ function findAlignmentAfterOpening(context: TreeIndentContext): number | null { - const { - node: tree, - simulatedBreak, - } = context; + const { node: tree, simulatedBreak } = context; const openingToken = tree.childAfter(tree.from); if (openingToken === null) { return null; } const openingLine = context.state.doc.lineAt(openingToken.from); - const lineEnd = simulatedBreak == null || simulatedBreak <= openingLine.from - ? openingLine.to - : Math.min(openingLine.to, simulatedBreak); + const lineEnd = + simulatedBreak == null || simulatedBreak <= openingLine.from + ? openingLine.to + : Math.min(openingLine.to, simulatedBreak); const cursor = openingToken.cursor(); while (cursor.next() && cursor.from < lineEnd) { if (!cursor.type.isSkipped) { @@ -58,7 +56,10 @@ function findAlignmentAfterOpening(context: TreeIndentContext): number | null { * @param units the number of units to indent * @returns the desired indentation level */ -function indentDeclarationStrategy(context: TreeIndentContext, units: number): number { +function indentDeclarationStrategy( + context: TreeIndentContext, + units: number, +): number { const alignment = findAlignmentAfterOpening(context); if (alignment !== null) { return context.column(alignment); diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar index ac0b0ea3..313df05d 100644 --- a/subprojects/frontend/src/language/problem.grammar +++ b/subprojects/frontend/src/language/problem.grammar @@ -1,6 +1,6 @@ @detectDelim -@external prop implicitCompletion from '../../../../src/language/props.ts' +@external prop implicitCompletion from './props' @top Problem { statement* } diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts index 65fb50dc..246135d8 100644 --- a/subprojects/frontend/src/language/problemLanguageSupport.ts +++ b/subprojects/frontend/src/language/problemLanguageSupport.ts @@ -7,9 +7,7 @@ import { LRLanguage, } from '@codemirror/language'; import { styleTags, tags as t } from '@lezer/highlight'; -import { LRParser } from '@lezer/lr'; -import { parser } from '../../build/generated/sources/lezer/problem'; import { foldBlockComment, foldConjunction, @@ -21,8 +19,9 @@ import { indentDeclaration, indentPredicateOrRule, } from './indentation'; +import { parser } from './problem.grammar'; -const parserWithMetadata = (parser as LRParser).configure({ +const parserWithMetadata = parser.configure({ props: [ styleTags({ LineComment: t.lineComment, @@ -86,8 +85,6 @@ const problemLanguage = LRLanguage.define({ }, }); -export function problemLanguageSupport(): LanguageSupport { - return new LanguageSupport(problemLanguage, [ - indentUnit.of(' '), - ]); +export default function problemLanguageSupport(): LanguageSupport { + return new LanguageSupport(problemLanguage, [indentUnit.of(' ')]); } diff --git a/subprojects/frontend/src/language/props.ts b/subprojects/frontend/src/language/props.ts index 8e488bf5..65392e75 100644 --- a/subprojects/frontend/src/language/props.ts +++ b/subprojects/frontend/src/language/props.ts @@ -1,3 +1,5 @@ +/* eslint-disable import/prefer-default-export -- Lezer needs non-default exports */ + import { NodeProp } from '@lezer/common'; export const implicitCompletion = new NodeProp({ -- cgit v1.2.3-70-g09d2