@difizen/libro-codemirror 0.1.0 → 0.1.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.
Files changed (114) hide show
  1. package/es/auto-complete/closebrackets.d.ts +12 -0
  2. package/es/auto-complete/closebrackets.d.ts.map +1 -0
  3. package/es/auto-complete/completion.d.ts +57 -0
  4. package/es/auto-complete/completion.d.ts.map +1 -0
  5. package/es/auto-complete/config.d.ts +22 -0
  6. package/es/auto-complete/config.d.ts.map +1 -0
  7. package/es/auto-complete/filter.d.ts +13 -0
  8. package/es/auto-complete/filter.d.ts.map +1 -0
  9. package/es/auto-complete/filter.js +1 -7
  10. package/es/auto-complete/index.d.ts.map +1 -1
  11. package/es/auto-complete/index.js +5 -9
  12. package/es/auto-complete/snippet.d.ts +14 -0
  13. package/es/auto-complete/snippet.d.ts.map +1 -0
  14. package/es/auto-complete/snippet.js +2 -2
  15. package/es/auto-complete/state.d.ts +63 -0
  16. package/es/auto-complete/state.d.ts.map +1 -0
  17. package/es/auto-complete/state.js +5 -16
  18. package/es/auto-complete/theme.d.ts +6 -0
  19. package/es/auto-complete/theme.d.ts.map +1 -0
  20. package/es/auto-complete/tooltip.d.ts +5 -0
  21. package/es/auto-complete/tooltip.d.ts.map +1 -0
  22. package/es/auto-complete/view.d.ts +43 -0
  23. package/es/auto-complete/view.d.ts.map +1 -0
  24. package/es/auto-complete/view.js +2 -13
  25. package/es/auto-complete/word.d.ts +3 -0
  26. package/es/auto-complete/word.d.ts.map +1 -0
  27. package/es/completion.js +1 -1
  28. package/es/config.d.ts +15 -10
  29. package/es/config.d.ts.map +1 -1
  30. package/es/config.js +15 -6
  31. package/es/editor-contribution.d.ts +8 -0
  32. package/es/editor-contribution.d.ts.map +1 -0
  33. package/es/editor-contribution.js +30 -0
  34. package/es/editor.d.ts +40 -10
  35. package/es/editor.d.ts.map +1 -1
  36. package/es/editor.js +241 -45
  37. package/es/hyperlink.d.ts +15 -0
  38. package/es/hyperlink.d.ts.map +1 -0
  39. package/es/indentation-markers/config.d.ts +17 -0
  40. package/es/indentation-markers/config.d.ts.map +1 -0
  41. package/es/indentation-markers/index.d.ts +3 -0
  42. package/es/indentation-markers/index.d.ts.map +1 -0
  43. package/es/indentation-markers/map.d.ts +77 -0
  44. package/es/indentation-markers/map.d.ts.map +1 -0
  45. package/es/indentation-markers/utils.d.ts +27 -0
  46. package/es/indentation-markers/utils.d.ts.map +1 -0
  47. package/es/index.d.ts +3 -1
  48. package/es/index.d.ts.map +1 -1
  49. package/es/index.js +3 -1
  50. package/es/libro-icon.d.ts +3 -0
  51. package/es/libro-icon.d.ts.map +1 -0
  52. package/es/libro-icon.js +2 -2
  53. package/es/lsp/completion.d.ts +5 -0
  54. package/es/lsp/completion.d.ts.map +1 -0
  55. package/es/lsp/completion.js +245 -0
  56. package/es/lsp/format.d.ts +7 -0
  57. package/es/lsp/format.d.ts.map +1 -0
  58. package/es/lsp/format.js +193 -0
  59. package/es/lsp/index.d.ts +7 -0
  60. package/es/lsp/index.d.ts.map +1 -0
  61. package/es/lsp/index.js +6 -0
  62. package/es/lsp/lint.d.ts +3 -0
  63. package/es/lsp/lint.d.ts.map +1 -0
  64. package/es/lsp/lint.js +114 -0
  65. package/es/lsp/protocol.d.ts +7 -0
  66. package/es/lsp/protocol.d.ts.map +1 -0
  67. package/es/lsp/protocol.js +1 -0
  68. package/es/lsp/tooltip.d.ts +3 -0
  69. package/es/lsp/tooltip.d.ts.map +1 -0
  70. package/es/lsp/tooltip.js +113 -0
  71. package/es/lsp/util.d.ts +15 -0
  72. package/es/lsp/util.d.ts.map +1 -0
  73. package/es/lsp/util.js +58 -0
  74. package/es/mode.d.ts.map +1 -1
  75. package/es/module.d.ts +3 -0
  76. package/es/module.d.ts.map +1 -0
  77. package/es/module.js +4 -0
  78. package/es/monitor.d.ts +32 -0
  79. package/es/monitor.d.ts.map +1 -0
  80. package/es/python-lang.d.ts +3 -0
  81. package/es/python-lang.d.ts.map +1 -0
  82. package/es/theme.d.ts +35 -0
  83. package/es/theme.d.ts.map +1 -0
  84. package/es/theme.js +4 -5
  85. package/es/tooltip.d.ts +1 -1
  86. package/es/tooltip.d.ts.map +1 -1
  87. package/es/tooltip.js +2 -4
  88. package/package.json +7 -5
  89. package/src/auto-complete/filter.ts +5 -7
  90. package/src/auto-complete/index.ts +6 -7
  91. package/src/auto-complete/snippet.ts +8 -2
  92. package/src/auto-complete/state.ts +13 -18
  93. package/src/auto-complete/view.ts +7 -13
  94. package/src/completion.ts +2 -2
  95. package/src/config.ts +40 -28
  96. package/src/editor-contribution.ts +17 -0
  97. package/src/editor.ts +226 -50
  98. package/src/hyperlink.ts +1 -1
  99. package/src/indentation-markers/index.ts +3 -3
  100. package/src/indentation-markers/map.ts +9 -9
  101. package/src/index.ts +4 -1
  102. package/src/libro-icon.tsx +4 -0
  103. package/src/lsp/completion.ts +175 -0
  104. package/src/lsp/format.ts +144 -0
  105. package/src/lsp/index.ts +6 -0
  106. package/src/lsp/lint.ts +125 -0
  107. package/src/lsp/protocol.ts +8 -0
  108. package/src/lsp/tooltip.ts +76 -0
  109. package/src/lsp/util.ts +69 -0
  110. package/src/mode.ts +1 -1
  111. package/src/module.ts +8 -0
  112. package/src/theme.ts +4 -4
  113. package/src/tooltip.ts +2 -4
  114. package/src/libro-icon.ts +0 -4
@@ -0,0 +1,32 @@
1
+ import { Emitter } from '@difizen/mana-app';
2
+ interface DocStatus {
3
+ source: string[];
4
+ cursor: number;
5
+ changes?: string;
6
+ }
7
+ interface CompletionChange {
8
+ start?: DocStatus;
9
+ accept?: DocStatus;
10
+ close?: DocStatus;
11
+ selectIndex?: number;
12
+ }
13
+ export declare class CompletionMonitor {
14
+ protected static instance: CompletionMonitor;
15
+ static getInstance(): CompletionMonitor;
16
+ protected completionChangeEmitter: Emitter<CompletionChange>;
17
+ get compeltionChange(): import("@difizen/mana-app").Event<CompletionChange>;
18
+ protected tooltipChangeEmitter: Emitter<boolean>;
19
+ get onTooltipChange(): import("@difizen/mana-app").Event<boolean>;
20
+ protected currentChange: CompletionChange | undefined;
21
+ start(doc: DocStatus): void;
22
+ accept(doc: DocStatus): void;
23
+ close(doc: DocStatus): void;
24
+ updateIndex(index: number): void;
25
+ emitChange(change: CompletionChange): void;
26
+ }
27
+ export interface MonitorPluginOptions {
28
+ onTooltipChange?: (visible: boolean) => void;
29
+ }
30
+ export declare const monitorPlugin: (options: MonitorPluginOptions) => import("@codemirror/state").Extension;
31
+ export {};
32
+ //# sourceMappingURL=monitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monitor.d.ts","sourceRoot":"","sources":["../src/monitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAQ5C,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,gBAAgB;IACxB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,iBAAiB;IAC5B,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IAE7C,MAAM,CAAC,WAAW;IAOlB,SAAS,CAAC,uBAAuB,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAiB;IAE7E,IAAI,gBAAgB,wDAEnB;IAED,SAAS,CAAC,oBAAoB,EAAE,OAAO,CAAC,OAAO,CAAC,CAAiB;IAEjE,IAAI,eAAe,+CAElB;IAED,SAAS,CAAC,aAAa,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAEtD,KAAK,CAAC,GAAG,EAAE,SAAS;IAIpB,MAAM,CAAC,GAAG,EAAE,SAAS;IAKrB,KAAK,CAAC,GAAG,EAAE,SAAS;IAKpB,WAAW,CAAC,KAAK,EAAE,MAAM;IAIzB,UAAU,CAAC,MAAM,EAAE,gBAAgB;CAGpC;AAED,MAAM,WAAW,oBAAoB;IACnC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C;AAED,eAAO,MAAM,aAAa,YAAa,oBAAoB,0CA+BvD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { LanguageSupport } from '@codemirror/language';
2
+ export declare function python(): LanguageSupport;
3
+ //# sourceMappingURL=python-lang.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"python-lang.d.ts","sourceRoot":"","sources":["../src/python-lang.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,wBAAgB,MAAM,oBAErB"}
package/es/theme.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { HighlightStyle } from '@codemirror/language';
2
+ import type { Extension } from '@codemirror/state';
3
+ export declare const jupyterEditorTheme: Extension;
4
+ export declare const jupyterHighlightStyle: HighlightStyle;
5
+ /**
6
+ * JupyterLab CodeMirror 6 theme
7
+ */
8
+ export declare const jupyterTheme: Extension;
9
+ /**
10
+ * Get the default CodeMirror 6 theme for JupyterLab
11
+ *
12
+ * @alpha
13
+ * @returns Default theme
14
+ */
15
+ export declare function defaultTheme(): Extension;
16
+ /**
17
+ * Register a new theme.
18
+ *
19
+ * @alpha
20
+ * @param name Theme name
21
+ * @param theme Codemirror 6 theme extension
22
+ */
23
+ export declare function registerTheme(name: string, theme: Extension): void;
24
+ /**
25
+ * Get a theme.
26
+ *
27
+ * #### Notes
28
+ * It falls back to the default theme
29
+ *
30
+ * @alpha
31
+ * @param name Theme name
32
+ * @returns Theme extension
33
+ */
34
+ export declare function getTheme(name: string): Extension;
35
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,eAAO,MAAM,kBAAkB,WA0G7B,CAAC;AAEH,eAAO,MAAM,qBAAqB,gBAuDhC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,SAG1B,CAAC;AAeF;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,QAE3D;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAIhD"}
package/es/theme.js CHANGED
@@ -8,7 +8,7 @@ export var jupyterEditorTheme = EditorView.theme({
8
8
  * these things differently.
9
9
  */
10
10
  '&': {
11
- background: 'var(--jp-layout-color0)',
11
+ background: 'var(--mana-libro-input-background)',
12
12
  color: 'var(--mana-libro-text-default-color)'
13
13
  },
14
14
  /* In the notebook, we want this styling to be handled by its container */
@@ -68,10 +68,9 @@ export var jupyterEditorTheme = EditorView.theme({
68
68
  letterSpacing: '0',
69
69
  lineHeight: '20px'
70
70
  },
71
- // '.cm-editor': {
72
- // paddingTop: '24px',
73
- // },
74
-
71
+ '.cm-editor': {
72
+ background: 'var(--mana-libro-input-background)'
73
+ },
75
74
  '.cm-searchMatch': {
76
75
  backgroundColor: 'var(--jp-search-unselected-match-background-color)',
77
76
  color: 'var(--jp-search-unselected-match-color)'
package/es/tooltip.d.ts CHANGED
@@ -6,5 +6,5 @@ export declare const closeTooltipEffect: import("@codemirror/state").StateEffect
6
6
  export declare const startTooltip: Command;
7
7
  export declare const closeTooltip: Command;
8
8
  export declare const tooltipKeymap: readonly KeyBinding[];
9
- export declare function tabTooltip(tooltipProvider: TooltipProvider | undefined): (StateField<Tooltip | null> | import("@codemirror/state").Extension)[];
9
+ export declare function tabTooltip(tooltipProvider: TooltipProvider | undefined): (import("@codemirror/state").Extension | StateField<Tooltip | null>)[];
10
10
  //# sourceMappingURL=tooltip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../src/tooltip.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EAEV,OAAO,EAER,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAIlE,eAAO,MAAM,kBAAkB,sDAAgC,CAAC;AAChE,eAAO,MAAM,kBAAkB,mDAA6B,CAAC;AAsD7D,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAG9C,CAAC;AAyDF,wBAAgB,UAAU,CAAC,eAAe,EAAE,eAAe,GAAG,SAAS,0EAEtE"}
1
+ {"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../src/tooltip.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EAEV,OAAO,EAER,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAIlE,eAAO,MAAM,kBAAkB,sDAAgC,CAAC;AAChE,eAAO,MAAM,kBAAkB,mDAA6B,CAAC;AAsD7D,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,OAG1B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAG9C,CAAC;AAuDF,wBAAgB,UAAU,CAAC,eAAe,EAAE,eAAe,GAAG,SAAS,0EAEtE"}
package/es/tooltip.js CHANGED
@@ -41,7 +41,7 @@ var tooltipField = StateField.define({
41
41
  create: function create() {
42
42
  return null;
43
43
  },
44
- update: function update(_tooltips, tr) {
44
+ update: function update(tooltips, tr) {
45
45
  var effects = tr.effects;
46
46
  var _iterator = _createForOfIteratorHelper(effects),
47
47
  _step;
@@ -134,9 +134,7 @@ var TooltipPlugin = /*#__PURE__*/function () {
134
134
  })
135
135
  });
136
136
  return undefined;
137
- }).catch(function () {
138
- //
139
- });
137
+ }).catch(console.error);
140
138
  }
141
139
  }
142
140
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@difizen/libro-codemirror",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "libro",
@@ -32,7 +32,6 @@
32
32
  "src"
33
33
  ],
34
34
  "dependencies": {
35
- "@difizen/mana-app": "latest",
36
35
  "@codemirror/autocomplete": "^6.0.0",
37
36
  "@codemirror/commands": "^6.1.0",
38
37
  "@codemirror/lang-javascript": "^6.0.2",
@@ -45,11 +44,14 @@
45
44
  "@codemirror/search": "^6.0.0",
46
45
  "@codemirror/state": "^6.0.0",
47
46
  "@codemirror/view": "^6.2.2",
48
- "@difizen/libro-code-editor": "^0.1.0",
49
- "@difizen/libro-common": "^0.1.0",
50
- "@difizen/libro-rendermime": "^0.1.0",
47
+ "@difizen/libro-code-editor": "^0.1.2",
48
+ "@difizen/libro-common": "^0.1.2",
49
+ "@difizen/libro-rendermime": "^0.1.2",
50
+ "@difizen/libro-lsp": "^0.1.2",
51
+ "@difizen/mana-app": "latest",
51
52
  "@lezer/common": "^1.1.0",
52
53
  "@lezer/highlight": "^1.1.4",
54
+ "highlight.js": "^11.9.0",
53
55
  "markdown-it": "^13.0.1",
54
56
  "uuid": "^9.0.0",
55
57
  "vscode-languageserver-protocol": "^3.17.0"
@@ -63,13 +63,11 @@ export class FuzzyMatcher {
63
63
  // at the start
64
64
  if (chars.length === 1) {
65
65
  const first = codePointAt(word, 0);
66
- if (first === chars[0]) {
67
- return [0, 0, codePointSize(first)];
68
- }
69
- if (first === folded[0]) {
70
- return [Penalty.CaseFold, 0, codePointSize(first)];
71
- }
72
- return null;
66
+ return first === chars[0]
67
+ ? [0, 0, codePointSize(first)]
68
+ : first === folded[0]
69
+ ? [Penalty.CaseFold, 0, codePointSize(first)]
70
+ : null;
73
71
  }
74
72
  const direct = word.indexOf(this.pattern);
75
73
  if (direct === 0) {
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
1
2
  import type { Extension, EditorState, StateEffect } from '@codemirror/state';
2
3
  import { Prec } from '@codemirror/state';
3
4
  import type { KeyBinding } from '@codemirror/view';
@@ -65,13 +66,11 @@ const completionKeymapExt = Prec.highest(
65
66
  /// returns `null`.
66
67
  export function completionStatus(state: EditorState): null | 'active' | 'pending' {
67
68
  const cState = state.field(completionState, false);
68
- if (cState && cState.active.some((a) => a.state === State.Pending)) {
69
- return 'pending';
70
- }
71
- if (cState && cState.active.some((a) => a.state !== State.Inactive)) {
72
- return 'active';
73
- }
74
- return null;
69
+ return cState && cState.active.some((a) => a.state === State.Pending)
70
+ ? 'pending'
71
+ : cState && cState.active.some((a) => a.state !== State.Inactive)
72
+ ? 'active'
73
+ : null;
75
74
  }
76
75
 
77
76
  const completionArrayCache: WeakMap<readonly Option[], readonly Completion[]> =
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
  /* eslint-disable @typescript-eslint/no-shadow */
3
3
  /* eslint-disable prefer-const */
4
+
4
5
  import { indentUnit } from '@codemirror/language';
5
6
  import type {
6
7
  ChangeDesc,
@@ -93,8 +94,13 @@ class Snippet {
93
94
  name = m[2] || m[3] || '',
94
95
  found = -1;
95
96
  for (let i = 0; i < fields.length; i++) {
96
- const sameName = name ? fields[i].name === name : false;
97
- if (seq !== null ? fields[i].seq === seq : sameName) {
97
+ if (
98
+ seq !== null
99
+ ? fields[i].seq === seq
100
+ : name
101
+ ? fields[i].name === name
102
+ : false
103
+ ) {
98
104
  found = i;
99
105
  }
100
106
  }
@@ -49,7 +49,7 @@ function sortOptions(active: readonly ActiveSource[], state: EditorState) {
49
49
  let match;
50
50
  for (const option of a.result.options) {
51
51
  if ((match = matcher.match(option.label))) {
52
- if (option.boost !== undefined) {
52
+ if (option.boost) {
53
53
  match[0] += option.boost;
54
54
  }
55
55
  options.push(new Option(option, a, match));
@@ -68,9 +68,7 @@ function sortOptions(active: readonly ActiveSource[], state: EditorState) {
68
68
  !prev ||
69
69
  prev.label !== opt.completion.label ||
70
70
  prev.detail !== opt.completion.detail ||
71
- (prev.type !== null &&
72
- opt.completion.type !== null &&
73
- prev.type !== opt.completion.type) ||
71
+ (prev.type && opt.completion.type && prev.type !== opt.completion.type) ||
74
72
  prev.apply !== opt.completion.apply
75
73
  ) {
76
74
  result.push(opt);
@@ -191,16 +189,15 @@ export class CompletionState {
191
189
  ) {
192
190
  active = this.active;
193
191
  }
194
- let open;
195
- if (
192
+
193
+ let open =
196
194
  tr.selection ||
197
195
  active.some((a) => a.hasResult() && tr.changes.touchesRange(a.from, a.to)) ||
198
196
  !sameResults(active, this.active)
199
- ) {
200
- open = CompletionDialog.build(active, state, this.id, this.open, conf);
201
- } else {
202
- open = this.open && tr.docChanged ? this.open.map(tr.changes) : this.open;
203
- }
197
+ ? CompletionDialog.build(active, state, this.id, this.open, conf)
198
+ : this.open && tr.docChanged
199
+ ? this.open.map(tr.changes)
200
+ : this.open;
204
201
  if (
205
202
  !open &&
206
203
  active.every((a) => a.state !== State.Pending) &&
@@ -277,13 +274,11 @@ export const enum State {
277
274
  }
278
275
 
279
276
  export function getUserEvent(tr: Transaction): 'input' | 'delete' | null {
280
- if (tr.isUserEvent('input.type')) {
281
- return 'input';
282
- }
283
- if (tr.isUserEvent('delete.backward')) {
284
- return 'delete';
285
- }
286
- return null;
277
+ return tr.isUserEvent('input.type')
278
+ ? 'input'
279
+ : tr.isUserEvent('delete.backward')
280
+ ? 'delete'
281
+ : null;
287
282
  }
288
283
 
289
284
  export class ActiveSource {
@@ -51,16 +51,12 @@ export function moveCompletionSelection(
51
51
  );
52
52
  }
53
53
  const { length } = cState.open.options;
54
- let selected;
55
- if (cState.open.selected > -1) {
56
- selected = cState.open.selected + step * (forward ? 1 : -1);
57
- } else {
58
- if (forward) {
59
- selected = 0;
60
- } else {
61
- selected = length - 1;
62
- }
63
- }
54
+ let selected =
55
+ cState.open.selected > -1
56
+ ? cState.open.selected + step * (forward ? 1 : -1)
57
+ : forward
58
+ ? 0
59
+ : length - 1;
64
60
  if (selected < 0) {
65
61
  selected = by === 'page' ? 0 : length - 1;
66
62
  } else if (selected >= length) {
@@ -238,9 +234,7 @@ export const completionPlugin = ViewPlugin.fromClass(
238
234
  return undefined;
239
235
  },
240
236
  )
241
- .catch(() => {
242
- //
243
- });
237
+ .catch(console.error);
244
238
  }
245
239
 
246
240
  scheduleAccept() {
package/src/completion.ts CHANGED
@@ -19,7 +19,7 @@ export const kernelCompletions: EditorCompletion =
19
19
  try {
20
20
  result = await Promise.any([
21
21
  provider({ cursorPosition: context.pos }),
22
- new Promise<CompletionReply>((_resolve, reject) => {
22
+ new Promise<CompletionReply>((resolve, reject) => {
23
23
  setTimeout(() => {
24
24
  reject(`request time out in ${timeout}ms`);
25
25
  }, timeout);
@@ -45,7 +45,7 @@ export const kernelCompletions: EditorCompletion =
45
45
  return {
46
46
  label: item['text'] as string,
47
47
  type: item['type'] === '<unknown>' ? undefined : (item['type'] as string),
48
- } as Completion;
48
+ };
49
49
  });
50
50
  } else {
51
51
  items = result.matches.map((item) => {
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { defaultKeymap, historyKeymap, history } from '@codemirror/commands';
1
+ import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
2
2
  import { pythonLanguage } from '@codemirror/lang-python';
3
3
  import {
4
4
  bracketMatching,
@@ -17,23 +17,23 @@ import { Compartment, EditorState, StateEffect } from '@codemirror/state';
17
17
  import type { KeyBinding } from '@codemirror/view';
18
18
  import {
19
19
  crosshairCursor,
20
- rectangularSelection,
21
- dropCursor,
22
20
  drawSelection,
23
- highlightSpecialChars,
24
- highlightActiveLineGutter,
21
+ dropCursor,
25
22
  EditorView,
26
23
  highlightActiveLine,
24
+ highlightActiveLineGutter,
25
+ highlightSpecialChars,
27
26
  keymap,
28
27
  lineNumbers,
29
28
  placeholder,
29
+ rectangularSelection,
30
30
  } from '@codemirror/view';
31
31
  import type { IEditorConfig } from '@difizen/libro-code-editor';
32
32
 
33
33
  import {
34
+ autocompletion,
34
35
  closeBrackets,
35
36
  closeBracketsKeymap,
36
- autocompletion,
37
37
  completionKeymap,
38
38
  } from './auto-complete/index.js';
39
39
  import { kernelCompletions } from './completion.js';
@@ -41,6 +41,9 @@ import type { IOptions } from './editor.js';
41
41
  import { hyperLink } from './hyperlink.js';
42
42
  import { indentationMarkers } from './indentation-markers/index.js';
43
43
  import { FoldIcon, UnFoldIcon } from './libro-icon.js';
44
+ import { lspPythonCompletion } from './lsp/completion.js';
45
+ import { formatKeymap } from './lsp/format.js';
46
+ import { lspLint, lspTooltip } from './lsp/index.js';
44
47
  import { ensure } from './mode.js';
45
48
  import { getTheme, defaultTheme } from './theme.js';
46
49
  import { tabTooltip, tooltipKeymap } from './tooltip.js';
@@ -59,12 +62,6 @@ export interface CodeMirrorConfig extends IEditorConfig {
59
62
  */
60
63
  mimetype?: string;
61
64
 
62
- /**
63
- * The theme to style the editor with. see editortheme.ts for an example
64
- * of how to design a theme for CodeMirror 6.
65
- */
66
- theme?: string;
67
-
68
65
  // FIXME-TRANS: Handle theme localizable names
69
66
  // themeDisplayName?: string
70
67
 
@@ -257,7 +254,7 @@ class FacetWrapper<T, U> extends ExtensionBuilder<T> {
257
254
  return this._facet.of(value);
258
255
  }
259
256
 
260
- private _facet: Facet<T, U>;
257
+ protected _facet: Facet<T, U>;
261
258
  }
262
259
  /**
263
260
  * Extension builder that provides an extension depending
@@ -274,8 +271,8 @@ class ConditionalExtension extends ExtensionBuilder<boolean> {
274
271
  return value ? this._truthy : this._falsy;
275
272
  }
276
273
 
277
- private _truthy: Extension;
278
- private _falsy: Extension;
274
+ protected _truthy: Extension;
275
+ protected _falsy: Extension;
279
276
  }
280
277
 
281
278
  /**
@@ -293,8 +290,8 @@ class GenConditionalExtension<T> extends ExtensionBuilder<T> {
293
290
  return this._builder.of(this._fn(value));
294
291
  }
295
292
 
296
- private _fn: (a: T) => boolean;
297
- private _builder: ConditionalExtension;
293
+ protected _fn: (a: T) => boolean;
294
+ protected _builder: ConditionalExtension;
298
295
  }
299
296
 
300
297
  /**
@@ -325,8 +322,8 @@ class ConfigurableBuilder implements IConfigurableBuilder {
325
322
  );
326
323
  }
327
324
 
328
- private _compartment: Compartment;
329
- private _builder: IExtensionBuilder;
325
+ protected _compartment: Compartment;
326
+ protected _builder: IExtensionBuilder;
330
327
  }
331
328
 
332
329
  /*
@@ -348,7 +345,7 @@ class ThemeBuilder implements IConfigurableBuilder {
348
345
  return this._compartment.reconfigure(getTheme(v));
349
346
  }
350
347
 
351
- private _compartment: Compartment;
348
+ protected _compartment: Compartment;
352
349
  }
353
350
 
354
351
  /*
@@ -370,7 +367,7 @@ class PlaceHolderBuilder implements IConfigurableBuilder {
370
367
  return this._compartment.reconfigure(placeholder(v));
371
368
  }
372
369
 
373
- private _compartment: Compartment;
370
+ protected _compartment: Compartment;
374
371
  }
375
372
 
376
373
  /**
@@ -508,17 +505,31 @@ export class EditorConfiguration {
508
505
  'jupyterKernelCompletion',
509
506
  createConditionalBuilder(
510
507
  pythonLanguage.data.of({
511
- autocomplete: kernelCompletions(options['completionProvider']),
508
+ autocomplete: kernelCompletions(options.completionProvider),
512
509
  }),
513
510
  ),
514
511
  ],
515
512
  [
516
513
  'jupyterKernelTooltip',
517
- createConditionalBuilder(tabTooltip(options['tooltipProvider'])),
514
+ createConditionalBuilder(tabTooltip(options.tooltipProvider)),
518
515
  ],
519
516
  ['indentationMarkers', createConditionalBuilder(indentationMarkers())],
520
517
  ['hyperLink', createConditionalBuilder(hyperLink)],
521
518
  ['placeholder', createPlaceHolderBuilder()],
519
+ [
520
+ 'lspTooltip',
521
+ createConditionalBuilder(lspTooltip({ lspProvider: options.lspProvider })),
522
+ ],
523
+ [
524
+ 'lspLint',
525
+ createConditionalBuilder(lspLint({ lspProvider: options.lspProvider })),
526
+ ],
527
+ [
528
+ 'lspCompletion',
529
+ createConditionalBuilder(
530
+ lspPythonCompletion({ lspProvider: options.lspProvider }),
531
+ ),
532
+ ],
522
533
  ]);
523
534
  this._themeOverloaderSpec = { '&': {}, '.cm-line': {} };
524
535
  this._themeOverloader = new Compartment();
@@ -607,6 +618,7 @@ export class EditorConfiguration {
607
618
  ...completionKeymap,
608
619
  ...lintKeymap,
609
620
  ...tooltipKeymap,
621
+ ...formatKeymap,
610
622
  ];
611
623
 
612
624
  const keymapExt = builder!.of(
@@ -635,7 +647,7 @@ export class EditorConfiguration {
635
647
  return extensions;
636
648
  }
637
649
 
638
- private updateThemeOverload(
650
+ protected updateThemeOverload(
639
651
  config: Partial<CodeMirrorConfig> | Record<string, any>,
640
652
  ): Extension {
641
653
  const { fontFamily, fontSize, lineHeight, lineWrap, wordWrapColumn } = config;
@@ -679,11 +691,11 @@ export class EditorConfiguration {
679
691
  return EditorView.theme(this._themeOverloaderSpec);
680
692
  }
681
693
 
682
- private get(key: string): IConfigurableBuilder | undefined {
694
+ protected get(key: string): IConfigurableBuilder | undefined {
683
695
  return this._configurableBuilderMap.get(key);
684
696
  }
685
697
 
686
- private _configurableBuilderMap: Map<string, IConfigurableBuilder>;
687
- private _themeOverloaderSpec: Record<string, Record<string, string>>;
688
- private _themeOverloader: Compartment;
698
+ protected _configurableBuilderMap: Map<string, IConfigurableBuilder>;
699
+ protected _themeOverloaderSpec: Record<string, Record<string, string>>;
700
+ protected _themeOverloader: Compartment;
689
701
  }
@@ -0,0 +1,17 @@
1
+ import type { CodeEditorFactory } from '@difizen/libro-code-editor';
2
+ import { CodeEditorContribution } from '@difizen/libro-code-editor';
3
+ import { singleton } from '@difizen/mana-app';
4
+
5
+ import { codeMirrorDefaultConfig } from './editor.js';
6
+ import { codeMirrorEditorFactory } from './factory.js';
7
+
8
+ @singleton({ contrib: [CodeEditorContribution] })
9
+ export class CodeMirrorEditorContribution implements CodeEditorContribution {
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ canHandle(mime: string): number {
12
+ // default editor
13
+ return 50;
14
+ }
15
+ factory: CodeEditorFactory = codeMirrorEditorFactory;
16
+ defaultConfig = codeMirrorDefaultConfig;
17
+ }