@codemirror/language 6.3.0 → 6.3.2

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.3.2 (2022-12-16)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix a bug that caused `ensureSyntaxTree` to return incomplete trees when using a viewport-aware parser like `StreamLanguage`.
6
+
7
+ ## 6.3.1 (2022-11-14)
8
+
9
+ ### Bug fixes
10
+
11
+ Make syntax-based folding include syntax nodes that start right at the end of a line as potential fold targets.
12
+
13
+ Fix the `indentService` protocol to allow a distinction between declining to handle the indentation and returning null to indicate the line has no definite indentation.
14
+
1
15
  ## 6.3.0 (2022-10-24)
2
16
 
3
17
  ### New features
package/dist/index.cjs CHANGED
@@ -183,7 +183,13 @@ up to that point if the tree isn't already available.
183
183
  function ensureSyntaxTree(state, upto, timeout = 50) {
184
184
  var _a;
185
185
  let parse = (_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context;
186
- return !parse ? null : parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
186
+ if (!parse)
187
+ return null;
188
+ let oldVieport = parse.viewport;
189
+ parse.updateViewport({ from: 0, to: upto });
190
+ let result = parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
191
+ parse.updateViewport(oldVieport);
192
+ return result;
187
193
  }
188
194
  /**
189
195
  Queries whether there is a full syntax tree available up to the
@@ -767,8 +773,10 @@ class LanguageDescription {
767
773
  Facet that defines a way to provide a function that computes the
768
774
  appropriate indentation depth, as a column number (see
769
775
  [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
770
- line, or `null` to indicate no appropriate indentation could be
771
- determined.
776
+ line. A return value of `null` indicates no indentation can be
777
+ determined, and the line should inherit the indentation of the one
778
+ above it. A return value of `undefined` defers to the next indent
779
+ service.
772
780
  */
773
781
  const indentService = state.Facet.define();
774
782
  /**
@@ -826,7 +834,7 @@ function getIndentation(context, pos) {
826
834
  context = new IndentContext(context);
827
835
  for (let service of context.state.facet(indentService)) {
828
836
  let result = service(context, pos);
829
- if (result != null)
837
+ if (result !== undefined)
830
838
  return result;
831
839
  }
832
840
  let tree = syntaxTree(context.state);
@@ -1187,7 +1195,7 @@ function syntaxFolding(state, start, end) {
1187
1195
  let tree = syntaxTree(state);
1188
1196
  if (tree.length < end)
1189
1197
  return null;
1190
- let inner = tree.resolveInner(end);
1198
+ let inner = tree.resolveInner(end, 1);
1191
1199
  let found = null;
1192
1200
  for (let cur = inner; cur; cur = cur.parent) {
1193
1201
  if (cur.to <= end || cur.from > end)
@@ -1680,7 +1688,7 @@ A default highlight style (works well with light themes).
1680
1688
  */
1681
1689
  const defaultHighlightStyle = HighlightStyle.define([
1682
1690
  { tag: highlight.tags.meta,
1683
- color: "#7a757a" },
1691
+ color: "#404740" },
1684
1692
  { tag: highlight.tags.link,
1685
1693
  textDecoration: "underline" },
1686
1694
  { tag: highlight.tags.heading,
package/dist/index.d.ts CHANGED
@@ -363,10 +363,12 @@ declare class LanguageDescription {
363
363
  Facet that defines a way to provide a function that computes the
364
364
  appropriate indentation depth, as a column number (see
365
365
  [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
366
- line, or `null` to indicate no appropriate indentation could be
367
- determined.
366
+ line. A return value of `null` indicates no indentation can be
367
+ determined, and the line should inherit the indentation of the one
368
+ above it. A return value of `undefined` defers to the next indent
369
+ service.
368
370
  */
369
- declare const indentService: Facet<(context: IndentContext, pos: number) => number | null, readonly ((context: IndentContext, pos: number) => number | null)[]>;
371
+ declare const indentService: Facet<(context: IndentContext, pos: number) => number | null | undefined, readonly ((context: IndentContext, pos: number) => number | null | undefined)[]>;
370
372
  /**
371
373
  Facet for overriding the unit by which indentation happens.
372
374
  Should be a string consisting either entirely of spaces or
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { NodeProp, Tree, IterMode, TreeFragment, Parser, NodeType, NodeSet } from '@lezer/common';
1
+ import { NodeProp, IterMode, Tree, TreeFragment, Parser, NodeType, NodeSet } from '@lezer/common';
2
2
  import { StateEffect, StateField, Facet, EditorState, countColumn, combineConfig, RangeSet, RangeSetBuilder, Prec } from '@codemirror/state';
3
3
  import { ViewPlugin, logException, EditorView, Decoration, WidgetType, gutter, GutterMarker } from '@codemirror/view';
4
4
  import { tags, tagHighlighter, highlightTree, styleTags } from '@lezer/highlight';
@@ -179,7 +179,13 @@ up to that point if the tree isn't already available.
179
179
  function ensureSyntaxTree(state, upto, timeout = 50) {
180
180
  var _a;
181
181
  let parse = (_a = state.field(Language.state, false)) === null || _a === void 0 ? void 0 : _a.context;
182
- return !parse ? null : parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
182
+ if (!parse)
183
+ return null;
184
+ let oldVieport = parse.viewport;
185
+ parse.updateViewport({ from: 0, to: upto });
186
+ let result = parse.isDone(upto) || parse.work(timeout, upto) ? parse.tree : null;
187
+ parse.updateViewport(oldVieport);
188
+ return result;
183
189
  }
184
190
  /**
185
191
  Queries whether there is a full syntax tree available up to the
@@ -763,8 +769,10 @@ class LanguageDescription {
763
769
  Facet that defines a way to provide a function that computes the
764
770
  appropriate indentation depth, as a column number (see
765
771
  [`indentString`](https://codemirror.net/6/docs/ref/#language.indentString)), at the start of a given
766
- line, or `null` to indicate no appropriate indentation could be
767
- determined.
772
+ line. A return value of `null` indicates no indentation can be
773
+ determined, and the line should inherit the indentation of the one
774
+ above it. A return value of `undefined` defers to the next indent
775
+ service.
768
776
  */
769
777
  const indentService = /*@__PURE__*/Facet.define();
770
778
  /**
@@ -822,7 +830,7 @@ function getIndentation(context, pos) {
822
830
  context = new IndentContext(context);
823
831
  for (let service of context.state.facet(indentService)) {
824
832
  let result = service(context, pos);
825
- if (result != null)
833
+ if (result !== undefined)
826
834
  return result;
827
835
  }
828
836
  let tree = syntaxTree(context.state);
@@ -1183,7 +1191,7 @@ function syntaxFolding(state, start, end) {
1183
1191
  let tree = syntaxTree(state);
1184
1192
  if (tree.length < end)
1185
1193
  return null;
1186
- let inner = tree.resolveInner(end);
1194
+ let inner = tree.resolveInner(end, 1);
1187
1195
  let found = null;
1188
1196
  for (let cur = inner; cur; cur = cur.parent) {
1189
1197
  if (cur.to <= end || cur.from > end)
@@ -1676,7 +1684,7 @@ A default highlight style (works well with light themes).
1676
1684
  */
1677
1685
  const defaultHighlightStyle = /*@__PURE__*/HighlightStyle.define([
1678
1686
  { tag: tags.meta,
1679
- color: "#7a757a" },
1687
+ color: "#404740" },
1680
1688
  { tag: tags.link,
1681
1689
  textDecoration: "underline" },
1682
1690
  { tag: tags.heading,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/language",
3
- "version": "6.3.0",
3
+ "version": "6.3.2",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",