@codemirror/language 6.10.5 → 6.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 6.10.7 (2024-12-17)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue where indentation for a stream language would fail to work when the parse covered only part of the document, far from the start.
6
+
7
+ Make sure the inner mode gets a chance to indent when indenting right at the end of a nested language section.
8
+
9
+ ## 6.10.6 (2024-11-29)
10
+
11
+ ### Bug fixes
12
+
13
+ Fix a crash in `StreamLanguage` when the input range is entirely before the editor viewport.
14
+
1
15
  ## 6.10.5 (2024-11-27)
2
16
 
3
17
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -995,7 +995,7 @@ const indentNodeProp = new common.NodeProp();
995
995
  // Compute the indentation for a given position from the syntax tree.
996
996
  function syntaxIndentation(cx, ast, pos) {
997
997
  let stack = ast.resolveStack(pos);
998
- let inner = stack.node.enterUnfinishedNodesBefore(pos);
998
+ let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
999
999
  if (inner != stack.node) {
1000
1000
  let add = [];
1001
1001
  for (let cur = inner; cur != stack.node; cur = cur.parent)
@@ -2230,14 +2230,14 @@ class StreamLanguage extends Language {
2230
2230
  if (from != null && from < cx.pos - 1e4)
2231
2231
  from = undefined;
2232
2232
  }
2233
- let start = findState(this, cx.node.tree, 0, cx.node.from, from !== null && from !== void 0 ? from : cx.pos), statePos, state;
2233
+ let start = findState(this, cx.node.tree, cx.node.from, cx.node.from, from !== null && from !== void 0 ? from : cx.pos), statePos, state;
2234
2234
  if (start) {
2235
2235
  state = start.state;
2236
2236
  statePos = start.pos + 1;
2237
2237
  }
2238
2238
  else {
2239
2239
  state = this.streamParser.startState(cx.unit);
2240
- statePos = 0;
2240
+ statePos = cx.node.from;
2241
2241
  }
2242
2242
  if (cx.pos - statePos > 10000 /* C.MaxIndentScanDist */)
2243
2243
  return null;
@@ -2314,14 +2314,15 @@ class Parse {
2314
2314
  this.rangeIndex = 0;
2315
2315
  this.to = ranges[ranges.length - 1].to;
2316
2316
  let context = ParseContext.get(), from = ranges[0].from;
2317
- let { state, tree } = findStartInFragments(lang, fragments, from, ranges[ranges.length - 1].to, context === null || context === void 0 ? void 0 : context.state);
2317
+ let { state, tree } = findStartInFragments(lang, fragments, from, this.to, context === null || context === void 0 ? void 0 : context.state);
2318
2318
  this.state = state;
2319
2319
  this.parsedPos = this.chunkStart = from + tree.length;
2320
2320
  for (let i = 0; i < tree.children.length; i++) {
2321
2321
  this.chunks.push(tree.children[i]);
2322
2322
  this.chunkPos.push(tree.positions[i]);
2323
2323
  }
2324
- if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */) {
2324
+ if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */ &&
2325
+ ranges.some(r => r.from <= context.viewport.from && r.to >= context.viewport.from)) {
2325
2326
  this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
2326
2327
  context.skipUntilInView(this.parsedPos, context.viewport.from);
2327
2328
  this.parsedPos = context.viewport.from;
package/dist/index.js CHANGED
@@ -993,7 +993,7 @@ const indentNodeProp = /*@__PURE__*/new NodeProp();
993
993
  // Compute the indentation for a given position from the syntax tree.
994
994
  function syntaxIndentation(cx, ast, pos) {
995
995
  let stack = ast.resolveStack(pos);
996
- let inner = stack.node.enterUnfinishedNodesBefore(pos);
996
+ let inner = ast.resolveInner(pos, -1).resolve(pos, 0).enterUnfinishedNodesBefore(pos);
997
997
  if (inner != stack.node) {
998
998
  let add = [];
999
999
  for (let cur = inner; cur != stack.node; cur = cur.parent)
@@ -2228,14 +2228,14 @@ class StreamLanguage extends Language {
2228
2228
  if (from != null && from < cx.pos - 1e4)
2229
2229
  from = undefined;
2230
2230
  }
2231
- let start = findState(this, cx.node.tree, 0, cx.node.from, from !== null && from !== void 0 ? from : cx.pos), statePos, state;
2231
+ let start = findState(this, cx.node.tree, cx.node.from, cx.node.from, from !== null && from !== void 0 ? from : cx.pos), statePos, state;
2232
2232
  if (start) {
2233
2233
  state = start.state;
2234
2234
  statePos = start.pos + 1;
2235
2235
  }
2236
2236
  else {
2237
2237
  state = this.streamParser.startState(cx.unit);
2238
- statePos = 0;
2238
+ statePos = cx.node.from;
2239
2239
  }
2240
2240
  if (cx.pos - statePos > 10000 /* C.MaxIndentScanDist */)
2241
2241
  return null;
@@ -2312,14 +2312,15 @@ class Parse {
2312
2312
  this.rangeIndex = 0;
2313
2313
  this.to = ranges[ranges.length - 1].to;
2314
2314
  let context = ParseContext.get(), from = ranges[0].from;
2315
- let { state, tree } = findStartInFragments(lang, fragments, from, ranges[ranges.length - 1].to, context === null || context === void 0 ? void 0 : context.state);
2315
+ let { state, tree } = findStartInFragments(lang, fragments, from, this.to, context === null || context === void 0 ? void 0 : context.state);
2316
2316
  this.state = state;
2317
2317
  this.parsedPos = this.chunkStart = from + tree.length;
2318
2318
  for (let i = 0; i < tree.children.length; i++) {
2319
2319
  this.chunks.push(tree.children[i]);
2320
2320
  this.chunkPos.push(tree.positions[i]);
2321
2321
  }
2322
- if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */) {
2322
+ if (context && this.parsedPos < context.viewport.from - 100000 /* C.MaxDistanceBeforeViewport */ &&
2323
+ ranges.some(r => r.from <= context.viewport.from && r.to >= context.viewport.from)) {
2323
2324
  this.state = this.lang.streamParser.startState(getIndentUnit(context.state));
2324
2325
  context.skipUntilInView(this.parsedPos, context.viewport.from);
2325
2326
  this.parsedPos = context.viewport.from;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/language",
3
- "version": "6.10.5",
3
+ "version": "6.10.7",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",