Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typescript errors #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
"@codemirror/language": "^6.3.0",
"@codemirror/state": "^6.0.0",
"@codemirror/view": "^6.0.0",
"@lezer/markdown": "^1.0.0",
"@lezer/common": "^1.0.0"
"@lezer/common": "^1.0.0",
"@lezer/markdown": "^1.0.0"
},
"devDependencies": {
"@codemirror/buildhelper": "^1.0.0"
"@codemirror/buildhelper": "^1.0.0",
"@types/mocha": "^10.0.3",
"ist": "^1.1.7",
"mocha": "^10.2.0"
},
"repository": {
"type": "git",
Expand Down
16 changes: 8 additions & 8 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {StateCommand, Text, EditorState, EditorSelection, ChangeSpec, countColumn} from "@codemirror/state"
import {syntaxTree, indentUnit} from "@codemirror/language"
import {SyntaxNode, Tree} from "@lezer/common"
import {markdownLanguage} from "./markdown"
import { indentUnit, syntaxTree } from "@codemirror/language"
import { ChangeSpec, EditorSelection, EditorState, SelectionRange, StateCommand, Text, countColumn } from "@codemirror/state"
import { SyntaxNode, Tree } from "@lezer/common"
import { markdownLanguage } from "./markdown"

class Context {
constructor(
Expand Down Expand Up @@ -32,12 +32,12 @@ class Context {
}

function getContext(node: SyntaxNode, doc: Text) {
let nodes = []
let nodes: SyntaxNode[] = []
for (let cur: SyntaxNode | null = node; cur && cur.name != "Document"; cur = cur.parent) {
if (cur.name == "ListItem" || cur.name == "Blockquote" || cur.name == "FencedCode")
nodes.push(cur)
}
let context = []
let context: Context[] = []
for (let i = nodes.length - 1; i >= 0; i--) {
let node = nodes[i], match
let line = doc.lineAt(node.from), startPos = node.from - line.from
Expand Down Expand Up @@ -106,7 +106,7 @@ function normalizeIndent(content: string, state: EditorState) {
/// document, HTML and code regions might use a different language).
export const insertNewlineContinueMarkup: StateCommand = ({state, dispatch}) => {
let tree = syntaxTree(state), {doc} = state
let dont = null, changes = state.changeByRange(range => {
let dont: { range: SelectionRange; } | null = null, changes = state.changeByRange(range => {
if (!range.empty || !markdownLanguage.isActiveAt(state, range.from)) return dont = {range}
let pos = range.from, line = doc.lineAt(pos)
let context = getContext(tree.resolveInner(pos, -1), doc)
Expand Down Expand Up @@ -210,7 +210,7 @@ function contextNodeForDelete(tree: Tree, pos: number) {
/// commands, with a higher precedence than the more generic commands.
export const deleteMarkupBackward: StateCommand = ({state, dispatch}) => {
let tree = syntaxTree(state)
let dont = null, changes = state.changeByRange(range => {
let dont: { range: SelectionRange; } | null = null, changes = state.changeByRange(range => {
let pos = range.from, {doc} = state
if (range.empty && markdownLanguage.isActiveAt(state, range.from)) {
let line = doc.lineAt(pos)
Expand Down
18 changes: 13 additions & 5 deletions src/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import {Language, defineLanguageFacet, languageDataProp, foldNodeProp, indentNodeProp, foldService,
syntaxTree, LanguageDescription, ParseContext} from "@codemirror/language"
import {parser as baseParser, MarkdownParser, GFM, Subscript, Superscript, Emoji} from "@lezer/markdown"
import {SyntaxNode, NodeType, NodeProp} from "@lezer/common"
import {
Language,
LanguageDescription, ParseContext,
defineLanguageFacet,
foldNodeProp,
foldService,
indentNodeProp,
languageDataProp,
syntaxTree
} from "@codemirror/language"
import { NodeProp, NodeType, SyntaxNode } from "@lezer/common"
import { Emoji, GFM, MarkdownParser, Subscript, Superscript, parser as baseParser } from "@lezer/markdown"

const data = defineLanguageFacet({commentTokens: {block: {open: "<!--", close: "-->"}}})

Expand Down Expand Up @@ -68,7 +76,7 @@ export function getCodeParser(
) {
return (info: string) => {
if (info && languages) {
let found = null
let found: Language | LanguageDescription | null = null
// Strip anything after whitespace
info = /\S*/.exec(info)![0]
if (typeof languages == "function") found = languages(info)
Expand Down
3 changes: 2 additions & 1 deletion test/test-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {EditorState, EditorSelection, StateCommand, Extension} from "@codemirror
import {markdown, deleteMarkupBackward, insertNewlineContinueMarkup} from "@codemirror/lang-markdown"
import {indentUnit} from "@codemirror/language"
import ist from "ist"
import { SelectionRange } from "@codemirror/state"

function mkState(doc: string, extension?: Extension) {
let cursors = []
let cursors: SelectionRange[] = []
for (let pos = 0;;) {
pos = doc.indexOf("|", pos)
if (pos < 0) break
Expand Down