@codemirror/language
Advanced tools
Comparing version 0.17.5 to 0.18.0
@@ -0,1 +1,13 @@ | ||
## 0.18.0 (2021-03-03) | ||
### Breaking changes | ||
The `Language` constructor takes an additional argument that provides the top node type. | ||
### New features | ||
`Language` instances now have a `topNode` property giving their top node type. | ||
`TreeIndentContext` now has a `continue` method that allows an indenter to defer to the indentation of the parent nodes. | ||
## 0.17.5 (2021-02-19) | ||
@@ -2,0 +14,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { NodeProp, Input, ParseContext, PartialParse, Tree, TreeFragment, SyntaxNode } from 'lezer-tree'; | ||
import { NodeProp, NodeType, Input, ParseContext, PartialParse, Tree, TreeFragment, SyntaxNode } from 'lezer-tree'; | ||
import { Parser, ParserConfig } from 'lezer'; | ||
@@ -22,2 +22,3 @@ import { Facet, Extension, EditorState } from '@codemirror/state'; | ||
}>; | ||
readonly topNode: NodeType; | ||
readonly extension: Extension; | ||
@@ -31,3 +32,3 @@ parser: { | ||
startParse(input: Input, pos: number, context: EditorParseContext): PartialParse; | ||
}, extraExtensions?: Extension[]); | ||
}, topNode: NodeType, extraExtensions?: Extension[]); | ||
isActiveAt(state: EditorState, pos: number): boolean; | ||
@@ -118,2 +119,3 @@ findRegions(state: EditorState): { | ||
declare class TreeIndentContext extends IndentContext { | ||
private base; | ||
readonly pos: number; | ||
@@ -123,2 +125,3 @@ readonly node: SyntaxNode; | ||
get baseIndent(): number; | ||
continue(): number | null; | ||
} | ||
@@ -125,0 +128,0 @@ declare function delimitedIndent({ closing, align, units }: { |
@@ -35,4 +35,7 @@ import { NodeProp, Tree, TreeFragment, NodeType } from 'lezer-tree'; | ||
/// facet used for this language. | ||
data, parser, extraExtensions = []) { | ||
data, parser, | ||
/// The node type of the top node of trees produced by this parser. | ||
topNode, extraExtensions = []) { | ||
this.data = data; | ||
this.topNode = topNode; | ||
// Kludge to define EditorState.tree as a debugging helper, | ||
@@ -109,3 +112,3 @@ // without the EditorState package actually knowing about | ||
constructor(data, parser) { | ||
super(data, parser); | ||
super(data, parser, parser.topNode); | ||
this.parser = parser; | ||
@@ -660,8 +663,3 @@ } | ||
} | ||
for (; tree; tree = tree.parent) { | ||
let strategy = indentStrategy(tree); | ||
if (strategy) | ||
return strategy(new TreeIndentContext(cx, pos, tree)); | ||
} | ||
return null; | ||
return indentFrom(tree, pos, cx); | ||
} | ||
@@ -683,2 +681,10 @@ function ignoreClosed(cx) { | ||
} | ||
function indentFrom(node, pos, base) { | ||
for (; node; node = node.parent) { | ||
let strategy = indentStrategy(node); | ||
if (strategy) | ||
return strategy(new TreeIndentContext(base, pos, node)); | ||
} | ||
return null; | ||
} | ||
function topIndent() { return 0; } | ||
@@ -696,2 +702,3 @@ /// Objects of this type provide context information and helper | ||
super(base.state, base.options); | ||
this.base = base; | ||
this.pos = pos; | ||
@@ -723,2 +730,8 @@ this.node = node; | ||
} | ||
/// Continue looking for indentations in the node's parent nodes, | ||
/// and return the result of that. | ||
continue() { | ||
let parent = this.node.parent; | ||
return parent ? indentFrom(parent, this.pos, this.base) : 0; | ||
} | ||
} | ||
@@ -725,0 +738,0 @@ function isParent(parent, of) { |
{ | ||
"name": "@codemirror/language", | ||
"version": "0.17.5", | ||
"version": "0.18.0", | ||
"description": "Language support infrastructure for the CodeMirror code editor", | ||
@@ -29,6 +29,6 @@ "scripts": { | ||
"dependencies": { | ||
"@codemirror/state": "^0.17.0", | ||
"@codemirror/text": "^0.17.0", | ||
"@codemirror/view": "^0.17.0", | ||
"lezer": "^0.13.0", | ||
"@codemirror/state": "^0.18.0", | ||
"@codemirror/text": "^0.18.0", | ||
"@codemirror/view": "^0.18.0", | ||
"lezer": "^0.13.4", | ||
"lezer-tree": "^0.13.0" | ||
@@ -35,0 +35,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157003
1970
+ Added@codemirror/rangeset@0.18.5(transitive)
+ Added@codemirror/state@0.18.7(transitive)
+ Added@codemirror/text@0.18.1(transitive)
+ Added@codemirror/view@0.18.19(transitive)
+ Addedstyle-mod@4.1.2(transitive)
- Removed@codemirror/rangeset@0.17.1(transitive)
- Removed@codemirror/state@0.17.2(transitive)
- Removed@codemirror/text@0.17.2(transitive)
- Removed@codemirror/view@0.17.13(transitive)
- Removedstyle-mod@3.2.2(transitive)
Updated@codemirror/state@^0.18.0
Updated@codemirror/text@^0.18.0
Updated@codemirror/view@^0.18.0
Updatedlezer@^0.13.4