@codemirror/language 6.3.0 → 6.3.1

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,11 @@
1
+ ## 6.3.1 (2022-11-14)
2
+
3
+ ### Bug fixes
4
+
5
+ Make syntax-based folding include syntax nodes that start right at the end of a line as potential fold targets.
6
+
7
+ 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.
8
+
1
9
  ## 6.3.0 (2022-10-24)
2
10
 
3
11
  ### New features
package/dist/index.cjs CHANGED
@@ -767,8 +767,10 @@ class LanguageDescription {
767
767
  Facet that defines a way to provide a function that computes the
768
768
  appropriate indentation depth, as a column number (see
769
769
  [`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.
770
+ line. A return value of `null` indicates no indentation can be
771
+ determined, and the line should inherit the indentation of the one
772
+ above it. A return value of `undefined` defers to the next indent
773
+ service.
772
774
  */
773
775
  const indentService = state.Facet.define();
774
776
  /**
@@ -826,7 +828,7 @@ function getIndentation(context, pos) {
826
828
  context = new IndentContext(context);
827
829
  for (let service of context.state.facet(indentService)) {
828
830
  let result = service(context, pos);
829
- if (result != null)
831
+ if (result !== undefined)
830
832
  return result;
831
833
  }
832
834
  let tree = syntaxTree(context.state);
@@ -1187,7 +1189,7 @@ function syntaxFolding(state, start, end) {
1187
1189
  let tree = syntaxTree(state);
1188
1190
  if (tree.length < end)
1189
1191
  return null;
1190
- let inner = tree.resolveInner(end);
1192
+ let inner = tree.resolveInner(end, 1);
1191
1193
  let found = null;
1192
1194
  for (let cur = inner; cur; cur = cur.parent) {
1193
1195
  if (cur.to <= end || cur.from > end)
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';
@@ -763,8 +763,10 @@ class LanguageDescription {
763
763
  Facet that defines a way to provide a function that computes the
764
764
  appropriate indentation depth, as a column number (see
765
765
  [`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.
766
+ line. A return value of `null` indicates no indentation can be
767
+ determined, and the line should inherit the indentation of the one
768
+ above it. A return value of `undefined` defers to the next indent
769
+ service.
768
770
  */
769
771
  const indentService = /*@__PURE__*/Facet.define();
770
772
  /**
@@ -822,7 +824,7 @@ function getIndentation(context, pos) {
822
824
  context = new IndentContext(context);
823
825
  for (let service of context.state.facet(indentService)) {
824
826
  let result = service(context, pos);
825
- if (result != null)
827
+ if (result !== undefined)
826
828
  return result;
827
829
  }
828
830
  let tree = syntaxTree(context.state);
@@ -1183,7 +1185,7 @@ function syntaxFolding(state, start, end) {
1183
1185
  let tree = syntaxTree(state);
1184
1186
  if (tree.length < end)
1185
1187
  return null;
1186
- let inner = tree.resolveInner(end);
1188
+ let inner = tree.resolveInner(end, 1);
1187
1189
  let found = null;
1188
1190
  for (let cur = inner; cur; cur = cur.parent) {
1189
1191
  if (cur.to <= end || cur.from > end)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/language",
3
- "version": "6.3.0",
3
+ "version": "6.3.1",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",