@difizen/libro-cofine-editor 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 (122) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/es/editor-contribution.d.ts +10 -0
  4. package/es/editor-contribution.d.ts.map +1 -0
  5. package/es/editor-contribution.js +31 -0
  6. package/es/index.d.ts +7 -0
  7. package/es/index.d.ts.map +1 -0
  8. package/es/index.js +6 -0
  9. package/es/index.less +32 -0
  10. package/es/language/lsp/completion-provider.d.ts +13 -0
  11. package/es/language/lsp/completion-provider.d.ts.map +1 -0
  12. package/es/language/lsp/completion-provider.js +290 -0
  13. package/es/language/lsp/diagnostic-provider.d.ts +22 -0
  14. package/es/language/lsp/diagnostic-provider.d.ts.map +1 -0
  15. package/es/language/lsp/diagnostic-provider.js +161 -0
  16. package/es/language/lsp/format-provider.d.ts +9 -0
  17. package/es/language/lsp/format-provider.d.ts.map +1 -0
  18. package/es/language/lsp/format-provider.js +139 -0
  19. package/es/language/lsp/hover-provider.d.ts +8 -0
  20. package/es/language/lsp/hover-provider.d.ts.map +1 -0
  21. package/es/language/lsp/hover-provider.js +136 -0
  22. package/es/language/lsp/language-feature-provider.d.ts +17 -0
  23. package/es/language/lsp/language-feature-provider.d.ts.map +1 -0
  24. package/es/language/lsp/language-feature-provider.js +89 -0
  25. package/es/language/lsp/lsp-contribution.d.ts +25 -0
  26. package/es/language/lsp/lsp-contribution.d.ts.map +1 -0
  27. package/es/language/lsp/lsp-contribution.js +213 -0
  28. package/es/language/lsp/module.d.ts +2 -0
  29. package/es/language/lsp/module.d.ts.map +1 -0
  30. package/es/language/lsp/module.js +3 -0
  31. package/es/language/lsp/semantic-highlight-provider.d.ts +9 -0
  32. package/es/language/lsp/semantic-highlight-provider.d.ts.map +1 -0
  33. package/es/language/lsp/semantic-highlight-provider.js +41 -0
  34. package/es/language/lsp/signature-help-provider.d.ts +8 -0
  35. package/es/language/lsp/signature-help-provider.d.ts.map +1 -0
  36. package/es/language/lsp/signature-help-provider.js +108 -0
  37. package/es/language/lsp/type-concerters.d.ts +7 -0
  38. package/es/language/lsp/type-concerters.d.ts.map +1 -0
  39. package/es/language/lsp/type-concerters.js +37 -0
  40. package/es/language/python/data/MagicPython.tmLanguage.json +4213 -0
  41. package/es/language/python/data/MagicRegExp.tmLanguage.json +497 -0
  42. package/es/language/python/data/configurations/python.json +135 -0
  43. package/es/language/python/data/snippets/python.snippets.json +223 -0
  44. package/es/language/python/module.d.ts +2 -0
  45. package/es/language/python/module.d.ts.map +1 -0
  46. package/es/language/python/module.js +3 -0
  47. package/es/language/python/python-builtin.d.ts +86 -0
  48. package/es/language/python/python-builtin.d.ts.map +1 -0
  49. package/es/language/python/python-builtin.js +569 -0
  50. package/es/language/python/python-language-feature.d.ts +26 -0
  51. package/es/language/python/python-language-feature.d.ts.map +1 -0
  52. package/es/language/python/python-language-feature.js +174 -0
  53. package/es/language-specs.d.ts +33 -0
  54. package/es/language-specs.d.ts.map +1 -0
  55. package/es/language-specs.js +115 -0
  56. package/es/libro-e2-editor.d.ts +277 -0
  57. package/es/libro-e2-editor.d.ts.map +1 -0
  58. package/es/libro-e2-editor.js +720 -0
  59. package/es/libro-e2-preload.d.ts +5 -0
  60. package/es/libro-e2-preload.d.ts.map +1 -0
  61. package/es/libro-e2-preload.js +57 -0
  62. package/es/libro-sql-api.d.ts +8 -0
  63. package/es/libro-sql-api.d.ts.map +1 -0
  64. package/es/libro-sql-api.js +26 -0
  65. package/es/module.d.ts +3 -0
  66. package/es/module.d.ts.map +1 -0
  67. package/es/module.js +44 -0
  68. package/es/placeholder.d.ts +31 -0
  69. package/es/placeholder.d.ts.map +1 -0
  70. package/es/placeholder.js +101 -0
  71. package/es/theme/data/jupyter_dark.json +406 -0
  72. package/es/theme/data/jupyter_hc_dark.json +385 -0
  73. package/es/theme/data/jupyter_hc_light.json +386 -0
  74. package/es/theme/data/jupyter_light.json +386 -0
  75. package/es/theme/data/libro_dark.json +186 -0
  76. package/es/theme/data/libro_light.json +170 -0
  77. package/es/theme/libro-python-theme-contribution.d.ts +6 -0
  78. package/es/theme/libro-python-theme-contribution.d.ts.map +1 -0
  79. package/es/theme/libro-python-theme-contribution.js +49 -0
  80. package/es/theme/module.d.ts +2 -0
  81. package/es/theme/module.d.ts.map +1 -0
  82. package/es/theme/module.js +3 -0
  83. package/es/types.d.ts +10 -0
  84. package/es/types.d.ts.map +1 -0
  85. package/es/types.js +3 -0
  86. package/package.json +67 -0
  87. package/src/editor-contribution.ts +30 -0
  88. package/src/index.less +32 -0
  89. package/src/index.spec.ts +8 -0
  90. package/src/index.ts +6 -0
  91. package/src/language/lsp/completion-provider.ts +214 -0
  92. package/src/language/lsp/diagnostic-provider.ts +148 -0
  93. package/src/language/lsp/format-provider.ts +87 -0
  94. package/src/language/lsp/hover-provider.ts +98 -0
  95. package/src/language/lsp/language-feature-provider.ts +69 -0
  96. package/src/language/lsp/lsp-contribution.ts +159 -0
  97. package/src/language/lsp/module.ts +5 -0
  98. package/src/language/lsp/semantic-highlight-provider.ts +26 -0
  99. package/src/language/lsp/signature-help-provider.ts +65 -0
  100. package/src/language/lsp/type-concerters.ts +72 -0
  101. package/src/language/python/data/MagicPython.tmLanguage.json +4213 -0
  102. package/src/language/python/data/MagicRegExp.tmLanguage.json +497 -0
  103. package/src/language/python/data/configurations/python.json +135 -0
  104. package/src/language/python/data/snippets/python.snippets.json +223 -0
  105. package/src/language/python/module.ts +5 -0
  106. package/src/language/python/python-builtin.ts +891 -0
  107. package/src/language/python/python-language-feature.ts +163 -0
  108. package/src/language-specs.ts +99 -0
  109. package/src/libro-e2-editor.ts +922 -0
  110. package/src/libro-e2-preload.ts +23 -0
  111. package/src/libro-sql-api.ts +20 -0
  112. package/src/module.ts +44 -0
  113. package/src/placeholder.ts +100 -0
  114. package/src/theme/data/jupyter_dark.json +406 -0
  115. package/src/theme/data/jupyter_hc_dark.json +385 -0
  116. package/src/theme/data/jupyter_hc_light.json +386 -0
  117. package/src/theme/data/jupyter_light.json +386 -0
  118. package/src/theme/data/libro_dark.json +186 -0
  119. package/src/theme/data/libro_light.json +170 -0
  120. package/src/theme/libro-python-theme-contribution.ts +36 -0
  121. package/src/theme/module.ts +5 -0
  122. package/src/types.ts +11 -0
@@ -0,0 +1,170 @@
1
+ {
2
+ "$schema": "vscode://schemas/color-theme",
3
+ "name": "libro light",
4
+ "include": "jupyter-light",
5
+ "colors": {
6
+ "activityBar.background": "#ececec",
7
+ "activityBar.activeBorder": "#000000",
8
+ "activityBar.foreground": "#000000"
9
+ },
10
+ "tokenColors": [
11
+ {
12
+ "scope": "storage.type.function",
13
+ "settings": {
14
+ "foreground": "#098658",
15
+ "fontStyle": "bold"
16
+ }
17
+ },
18
+ {
19
+ "scope": "support.function.builtin.python",
20
+ "settings": {
21
+ "foreground": "#098658"
22
+ }
23
+ },
24
+ {
25
+ "scope": "comment.line.number-sign.python",
26
+ "settings": {
27
+ "foreground": "#6A8B93",
28
+ "fontStyle": "italic"
29
+ }
30
+ },
31
+ {
32
+ "scope": "keyword.control",
33
+ "settings": {
34
+ "foreground": "#098658",
35
+ "fontStyle": "bold"
36
+ }
37
+ },
38
+ {
39
+ "scope": "keyword.operator",
40
+ "settings": {
41
+ "foreground": "#c700c7"
42
+ }
43
+ },
44
+ {
45
+ "scope": "meta.member.access",
46
+ "settings": {
47
+ "foreground": "#2060a0"
48
+ }
49
+ },
50
+ {
51
+ "scope": "constant.language",
52
+ "settings": {
53
+ "foreground": "#098658",
54
+ "fontStyle": "bold"
55
+ }
56
+ },
57
+ {
58
+ "scope": "string.quoted",
59
+ "settings": {
60
+ "foreground": "#c03030"
61
+ }
62
+ },
63
+ {
64
+ "scope": "entity.name.function",
65
+ "settings": {
66
+ "foreground": "#003cff"
67
+ }
68
+ },
69
+
70
+ {
71
+ "name": "SQL Scope",
72
+ "scope": ["keywords", "customKeywords"],
73
+ "settings": {
74
+ "foreground": "#236fd9"
75
+ }
76
+ },
77
+ {
78
+ "name": "SQL Scope",
79
+ "scope": ["comment"],
80
+ "settings": {
81
+ "foreground": "#999999"
82
+ }
83
+ },
84
+ {
85
+ "name": "SQL Scope",
86
+ "scope": ["builtinFunctions", "function"],
87
+ "settings": {
88
+ "foreground": "#CB3BC1"
89
+ }
90
+ },
91
+ {
92
+ "name": "SQL Scope",
93
+ "scope": ["operator"],
94
+ "settings": {
95
+ "foreground": "#232226"
96
+ }
97
+ },
98
+ {
99
+ "name": "SQL Scope",
100
+ "scope": ["string"],
101
+ "settings": {
102
+ "foreground": "#D45E00"
103
+ }
104
+ },
105
+ {
106
+ "name": "SQL Scope",
107
+ "scope": ["number"],
108
+ "settings": {
109
+ "foreground": "#2E7F01"
110
+ }
111
+ },
112
+ {
113
+ "name": "SQL Scope",
114
+ "scope": ["variable"],
115
+ "settings": {
116
+ "foreground": "#B8DBA6"
117
+ }
118
+ },
119
+ {
120
+ "name": "Log Scope",
121
+ "scope": ["log-info"],
122
+ "settings": {
123
+ "foreground": "#008800"
124
+ }
125
+ },
126
+ {
127
+ "name": "Log Scope",
128
+ "scope": ["log-alert"],
129
+ "settings": {
130
+ "foreground": "#DE9504"
131
+ }
132
+ },
133
+ {
134
+ "name": "Log Scope",
135
+ "scope": ["log-date"],
136
+ "settings": {
137
+ "foreground": "#171617"
138
+ }
139
+ },
140
+ {
141
+ "name": "Log Scope",
142
+ "scope": ["log-error"],
143
+ "settings": {
144
+ "foreground": "#FF4B61"
145
+ }
146
+ },
147
+ {
148
+ "name": "Log Scope",
149
+ "scope": ["log-links"],
150
+ "settings": {
151
+ "foreground": "#1292FF"
152
+ }
153
+ },
154
+ {
155
+ "name": "Log Scope",
156
+ "scope": ["log-failed"],
157
+ "settings": {
158
+ "foreground": "#FF4B61"
159
+ }
160
+ },
161
+ {
162
+ "name": "Log Scope",
163
+ "scope": ["log-success"],
164
+ "settings": {
165
+ "foreground": "#171617"
166
+ }
167
+ }
168
+ ],
169
+ "semanticHighlighting": true
170
+ }
@@ -0,0 +1,6 @@
1
+ import type { ThemeRegistry } from '@difizen/libro-cofine-editor-core';
2
+ import { ThemeContribution } from '@difizen/libro-cofine-editor-core';
3
+ export declare class LibroPythonThemeContribution implements ThemeContribution {
4
+ registerItem(registry: ThemeRegistry): void;
5
+ }
6
+ //# sourceMappingURL=libro-python-theme-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-python-theme-contribution.d.ts","sourceRoot":"","sources":["../../src/theme/libro-python-theme-contribution.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAUtE,qBACa,4BAA6B,YAAW,iBAAiB;IACpE,YAAY,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;CAqB5C"}
@@ -0,0 +1,49 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _class;
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ /* eslint-disable global-require */
9
+
10
+ import { ThemeContribution } from '@difizen/libro-cofine-editor-core';
11
+ import { singleton } from '@difizen/mana-app';
12
+ import jupyterDark from "./data/jupyter_dark.json";
13
+ import jupyterHCDark from "./data/jupyter_hc_dark.json";
14
+ import jupyterHCLight from "./data/jupyter_hc_light.json";
15
+ import jupyterLight from "./data/jupyter_light.json";
16
+ import libroDark from "./data/libro_dark.json";
17
+ import libroLight from "./data/libro_light.json";
18
+ export var LibroPythonThemeContribution = (_dec = singleton({
19
+ contrib: ThemeContribution
20
+ }), _dec(_class = /*#__PURE__*/function () {
21
+ function LibroPythonThemeContribution() {
22
+ _classCallCheck(this, LibroPythonThemeContribution);
23
+ }
24
+ _createClass(LibroPythonThemeContribution, [{
25
+ key: "registerItem",
26
+ value: function registerItem(registry) {
27
+ if (!registry.mixedThemeEnable) {
28
+ console.warn('cannot register textmate themes');
29
+ return;
30
+ }
31
+
32
+ // theme名称必须满足 ^[a-z0-9\-]+$, 必须提供base theme
33
+ // jupyter theme from https://github.com/sam-the-programmer/vscode-jupyter-theme
34
+ registry.registerMixedTheme(jupyterLight, 'jupyter-light', 'vs');
35
+ registry.registerMixedTheme(jupyterDark, 'jupyter-dark', 'vs-dark');
36
+ registry.registerMixedTheme(jupyterHCLight, 'jupyter-hc-light', 'hc-black');
37
+ registry.registerMixedTheme(jupyterHCDark, 'jupyter-hc-dark', 'hc-black');
38
+
39
+ /**
40
+ * libro theme based on jupyter theme, 支持python;
41
+ * 同时兼容sql和log, 如果有其他语言需要支持,需要在主题中指定对应的token和颜色;
42
+ * monaco不同编辑器实例无法使用不同的主题,所有的编辑器实例共享一个主题,后创建的编辑器会覆盖更新全局的主题,所以libro所有e2编辑器必须使用同一个主题!
43
+ */
44
+ registry.registerMixedTheme(libroLight, 'libro-light', 'vs');
45
+ registry.registerMixedTheme(libroDark, 'libro-dark', 'vs-dark');
46
+ }
47
+ }]);
48
+ return LibroPythonThemeContribution;
49
+ }()) || _class);
@@ -0,0 +1,2 @@
1
+ export declare const LibroE2ThemeModule: import("@difizen/mana-app").SyringeModule<import("@difizen/mana-app").Syringe.Module>;
2
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/theme/module.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,uFAAkD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Module } from '@difizen/mana-app';
2
+ import { LibroPythonThemeContribution } from "./libro-python-theme-contribution.js";
3
+ export var LibroE2ThemeModule = Module().register(LibroPythonThemeContribution);
package/es/types.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { Range, Uri } from '@difizen/monaco-editor-core';
2
+ import type monaco from '@difizen/monaco-editor-core';
3
+ export type MonacoEditorType = monaco.editor.IStandaloneCodeEditor;
4
+ export type MonacoEditorOptions = monaco.editor.IStandaloneEditorConstructionOptions & {
5
+ uri?: monaco.Uri;
6
+ };
7
+ export type MonacoMatch = monaco.editor.FindMatch;
8
+ export declare const MonacoRange: typeof Range;
9
+ export declare const MonacoUri: typeof Uri;
10
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,KAAK,MAAM,MAAM,6BAA6B,CAAC;AAEtD,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC;AACnE,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,oCAAoC,GAAG;IACrF,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;CAClB,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;AAElD,eAAO,MAAM,WAAW,cAAQ,CAAC;AACjC,eAAO,MAAM,SAAS,YAAM,CAAC"}
package/es/types.js ADDED
@@ -0,0 +1,3 @@
1
+ import { Range, Uri } from '@difizen/monaco-editor-core';
2
+ export var MonacoRange = Range;
3
+ export var MonacoUri = Uri;
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@difizen/libro-cofine-editor",
3
+ "version": "0.1.2",
4
+ "description": "",
5
+ "keywords": [
6
+ "libro",
7
+ "notebook"
8
+ ],
9
+ "repository": "git@github.com:difizen/libro.git",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "typings": "./es/index.d.ts",
15
+ "default": "./es/index.js"
16
+ },
17
+ "./mock": {
18
+ "typings": "./es/mock/index.d.ts",
19
+ "default": "./es/mock/index.js"
20
+ },
21
+ "./es/mock": {
22
+ "typings": "./es/mock/index.d.ts",
23
+ "default": "./es/mock/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "es/index.js",
28
+ "module": "es/index.js",
29
+ "typings": "es/index.d.ts",
30
+ "files": [
31
+ "es",
32
+ "src"
33
+ ],
34
+ "dependencies": {
35
+ "@difizen/monaco-editor-core": "latest",
36
+ "@difizen/libro-cofine-editor-core": "^0.1.2",
37
+ "@difizen/libro-cofine-textmate": "^0.1.2",
38
+ "@difizen/libro-lsp": "^0.1.2",
39
+ "@difizen/libro-code-editor": "^0.1.2",
40
+ "@difizen/libro-common": "^0.1.2",
41
+ "@difizen/libro-core": "^0.1.2",
42
+ "@difizen/mana-app": "latest",
43
+ "resize-observer-polyfill": "^1.5.1",
44
+ "vscode-languageserver-protocol": "^3.17.4",
45
+ "uuid": "^9.0.0"
46
+ },
47
+ "peerDependencies": {
48
+ "react": "^18.2.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/react": "^18.2.25",
52
+ "@types/uuid": "^9.0.2"
53
+ },
54
+ "scripts": {
55
+ "setup": "father build",
56
+ "build": "father build",
57
+ "test": ": Note: lint task is delegated to test:* scripts",
58
+ "test:vitest": "vitest run",
59
+ "test:jest": "jest",
60
+ "coverage": ": Note: lint task is delegated to coverage:* scripts",
61
+ "coverage:vitest": "vitest run --coverage",
62
+ "coverage:jest": "jest --coverage",
63
+ "lint": ": Note: lint task is delegated to lint:* scripts",
64
+ "lint:eslint": "eslint src",
65
+ "lint:tsc": "tsc --noEmit"
66
+ }
67
+ }
@@ -0,0 +1,30 @@
1
+ import type { CodeEditorFactory } from '@difizen/libro-code-editor';
2
+ import { CodeEditorContribution } from '@difizen/libro-code-editor';
3
+ import { inject, singleton } from '@difizen/mana-app';
4
+
5
+ import { libroE2DefaultConfig, LibroE2EditorFactory } from './libro-e2-editor.js';
6
+
7
+ @singleton({ contrib: [CodeEditorContribution] })
8
+ export class LibroE2EditorContribution implements CodeEditorContribution {
9
+ factory: CodeEditorFactory;
10
+
11
+ defaultConfig = libroE2DefaultConfig;
12
+
13
+ constructor(
14
+ @inject(LibroE2EditorFactory) libroE2EditorFactory: LibroE2EditorFactory,
15
+ ) {
16
+ this.factory = libroE2EditorFactory;
17
+ }
18
+
19
+ canHandle(mime: string): number {
20
+ const mimes = [
21
+ 'application/vnd.libro.sql+json',
22
+ 'text/x-python',
23
+ 'application/vnd.libro.prompt+json',
24
+ ];
25
+ if (mimes.includes(mime)) {
26
+ return 50 + 1;
27
+ }
28
+ return 0;
29
+ }
30
+ }
package/src/index.less ADDED
@@ -0,0 +1,32 @@
1
+ .libro-e2-editor-container {
2
+ padding: 12px 0 18px;
3
+ background: var(--mana-libro-input-background) !important;
4
+ border-radius: 4px;
5
+ }
6
+
7
+ .libro-e2-editor {
8
+ background: var(--mana-libro-input-background) !important;
9
+
10
+ .monaco-editor-background,
11
+ .margin {
12
+ background: var(--mana-libro-input-background) !important;
13
+ }
14
+
15
+ .current-line-margin,
16
+ .current-line-both {
17
+ background: var(--mana-libro-editor-activeline-color) !important;
18
+ border: unset !important;
19
+ }
20
+
21
+ .line-numbers {
22
+ margin-left: 8px;
23
+ color: var(--mana-libro-editor-gutter-number-color) !important;
24
+ font-weight: 400;
25
+ font-size: 13px;
26
+ // font-family: Menlo-Regular, consolas, 'DejaVu Sans Mono', monospace !important;
27
+ }
28
+
29
+ .cursors-layer .cursor {
30
+ background-color: var(--mana-libro-editor-cursor-color);
31
+ }
32
+ }
@@ -0,0 +1,8 @@
1
+ import 'reflect-metadata';
2
+ import assert from 'assert';
3
+
4
+ describe('libro-cofine-editor', () => {
5
+ it('#import', () => {
6
+ assert(true);
7
+ });
8
+ });
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './editor-contribution.js';
2
+ export * from './language-specs.js';
3
+ export * from './libro-e2-editor.js';
4
+ export * from './libro-e2-preload.js';
5
+ export * from './libro-sql-api.js';
6
+ export * from './module.js';
@@ -0,0 +1,214 @@
1
+ import { CompletionTriggerKind } from '@difizen/libro-lsp';
2
+ import { languages } from '@difizen/monaco-editor-core';
3
+ import type monaco from '@difizen/monaco-editor-core';
4
+ import * as lsp from 'vscode-languageserver-protocol';
5
+ import { InsertReplaceEdit } from 'vscode-languageserver-protocol';
6
+
7
+ import { LangaugeFeatureProvider } from './language-feature-provider.js';
8
+ import { CompletionItemKind } from './type-concerters.js';
9
+
10
+ export class CompletionProvider
11
+ extends LangaugeFeatureProvider
12
+ implements monaco.languages.CompletionItemProvider
13
+ {
14
+ triggerCharacters: ['.', '[', '"', "'"];
15
+
16
+ public provideCompletionItems = async (
17
+ model: monaco.editor.ITextModel,
18
+ position: monaco.Position,
19
+ ): Promise<monaco.languages.CompletionList | undefined> => {
20
+ const result = await this.provideCompletionItemsFromLSPServer(model, position);
21
+ return result;
22
+ };
23
+
24
+ protected provideCompletionItemsFromKernel = async (
25
+ model: monaco.editor.ITextModel,
26
+ position: monaco.Position,
27
+ ): Promise<monaco.languages.CompletionList | undefined> => {
28
+ const editor = this.getEditorByModel(model);
29
+ if (!editor || editor.getOption('lspEnabled') !== true) {
30
+ return;
31
+ }
32
+
33
+ const reply = await editor.completionProvider?.({
34
+ cursorPosition: editor.getOffsetAt({
35
+ column: position.column,
36
+ line: position.lineNumber,
37
+ }),
38
+ });
39
+
40
+ const start = reply?.cursor_start
41
+ ? editor.getPositionAt(reply?.cursor_start)
42
+ : editor.getCursorPosition();
43
+ const end = reply?.cursor_end
44
+ ? editor.getPositionAt(reply?.cursor_end)
45
+ : editor.getCursorPosition();
46
+
47
+ const suggestion: languages.CompletionItem[] = (reply?.matches ?? []).map(
48
+ (match) => {
49
+ return {
50
+ label: match,
51
+ kind: languages.CompletionItemKind.Text,
52
+ insertText: match,
53
+ range: {
54
+ startColumn: start?.column,
55
+ startLineNumber: start?.line,
56
+ endColumn: end?.column,
57
+ endLineNumber: end?.line,
58
+ },
59
+ } as languages.CompletionItem;
60
+ },
61
+ );
62
+
63
+ return {
64
+ suggestions: suggestion as any,
65
+ };
66
+ };
67
+
68
+ protected provideCompletionItemsFromLSPServer = async (
69
+ model: monaco.editor.ITextModel,
70
+ position: monaco.Position,
71
+ ): Promise<monaco.languages.CompletionList | undefined> => {
72
+ const provider = await this.getProvider(model);
73
+ if (!provider) {
74
+ return;
75
+ }
76
+ const editor = this.getEditorByModel(model);
77
+ if (!editor || editor.getOption('lspEnabled') !== true) {
78
+ return;
79
+ }
80
+
81
+ const { lspConnection, editor: docEditor, virtualDocument: doc } = provider;
82
+
83
+ if (!lspConnection.isReady || !lspConnection.provides('completionProvider')) {
84
+ return;
85
+ }
86
+
87
+ const virtualPos = doc.transformEditorToVirtual(docEditor, {
88
+ line: position.lineNumber - 1,
89
+ ch: position.column,
90
+ isEditor: true,
91
+ });
92
+
93
+ if (!virtualPos) {
94
+ return;
95
+ }
96
+
97
+ const result = await lspConnection.clientRequests[
98
+ 'textDocument/completion'
99
+ ].request({
100
+ position: { line: virtualPos.line, character: virtualPos.ch },
101
+ textDocument: {
102
+ uri: doc.documentInfo.uri,
103
+ },
104
+ context: {
105
+ triggerKind: CompletionTriggerKind.Invoked,
106
+ },
107
+ });
108
+
109
+ const items = 'items' in result ? result.items : result;
110
+
111
+ const word = model.getWordUntilPosition(position);
112
+ const range = {
113
+ startLineNumber: position.lineNumber,
114
+ endLineNumber: position.lineNumber,
115
+ startColumn: word.startColumn,
116
+ endColumn: position.column,
117
+ };
118
+
119
+ const suggestions: monaco.languages.CompletionItem[] = items.map(
120
+ (item: lsp.CompletionItem) => {
121
+ return this.transformCompletion(item, range);
122
+ },
123
+ );
124
+
125
+ if (Array.isArray(result)) {
126
+ return { suggestions };
127
+ }
128
+
129
+ return {
130
+ incomplete: result.isIncomplete,
131
+ suggestions,
132
+ };
133
+ };
134
+
135
+ resolveCompletionItem = async (
136
+ item: monaco.languages.CompletionItem,
137
+ token: monaco.CancellationToken,
138
+ ): Promise<monaco.languages.CompletionItem | undefined> => {
139
+ const original = (item as any).__original as lsp.CompletionItem | undefined;
140
+ if (!original) {
141
+ return;
142
+ }
143
+ const itemResult =
144
+ await this.lspConnection.clientRequests['completionItem/resolve'].request(
145
+ original,
146
+ );
147
+ if (token.isCancellationRequested) {
148
+ return;
149
+ }
150
+ const resolve = this.transformCompletion(itemResult, item.range);
151
+ return resolve;
152
+ };
153
+
154
+ transformCompletion(
155
+ item: lsp.CompletionItem,
156
+ range: monaco.IRange | monaco.languages.CompletionItemRanges,
157
+ ): monaco.languages.CompletionItem {
158
+ const converted: monaco.languages.CompletionItem = {
159
+ ...item,
160
+ label: item.label,
161
+ sortText: item.sortText,
162
+ filterText: item.filterText,
163
+ insertText: item.insertText ? item.insertText : item.label,
164
+ kind: CompletionItemKind.from(item.kind ?? lsp.CompletionItemKind.Property),
165
+ detail: item.detail,
166
+ documentation: item.documentation,
167
+ command: item.command
168
+ ? {
169
+ id: item.command.command,
170
+ title: item.command.title,
171
+ arguments: item.command?.arguments,
172
+ }
173
+ : undefined,
174
+ range,
175
+ additionalTextEdits: undefined,
176
+ };
177
+
178
+ // FIXME: text edit 生成的range有可能在其他的editor上,这里似乎无法处理
179
+ if (item.textEdit) {
180
+ converted.insertText = item.textEdit.newText;
181
+ if (InsertReplaceEdit.is(item.textEdit)) {
182
+ converted.range = {
183
+ insert: convertRange(item.textEdit.insert),
184
+ replace: convertRange(item.textEdit.replace),
185
+ };
186
+ } else {
187
+ converted.range = convertRange(item.textEdit.range);
188
+ }
189
+ }
190
+
191
+ if (item.additionalTextEdits) {
192
+ converted.additionalTextEdits = item.additionalTextEdits.map((edit) => {
193
+ return {
194
+ range: convertRange(edit.range),
195
+ text: edit.newText,
196
+ };
197
+ });
198
+ }
199
+
200
+ // Stash a few additional pieces of information.
201
+ (converted as any).__original = item;
202
+
203
+ return converted;
204
+ }
205
+ }
206
+
207
+ function convertRange(range: lsp.Range): monaco.IRange {
208
+ return {
209
+ startLineNumber: range.start.line + 1,
210
+ startColumn: range.start.character + 1,
211
+ endLineNumber: range.end.line + 1,
212
+ endColumn: range.end.character + 1,
213
+ };
214
+ }