@difizen/libro-code-editor 0.2.45 → 0.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/es/code-editor-inline-completions/index.d.ts +4 -0
- package/es/code-editor-inline-completions/index.d.ts.map +1 -0
- package/es/code-editor-inline-completions/index.js +3 -0
- package/es/code-editor-inline-completions/inline-completions-manager.d.ts +13 -0
- package/es/code-editor-inline-completions/inline-completions-manager.d.ts.map +1 -0
- package/es/code-editor-inline-completions/inline-completions-manager.js +42 -0
- package/es/code-editor-inline-completions/inline-completions-protocol.d.ts +140 -0
- package/es/code-editor-inline-completions/inline-completions-protocol.d.ts.map +1 -0
- package/es/code-editor-inline-completions/inline-completions-protocol.js +7 -0
- package/es/code-editor-inline-completions/sequencer.d.ts +6 -0
- package/es/code-editor-inline-completions/sequencer.d.ts.map +1 -0
- package/es/code-editor-inline-completions/sequencer.js +22 -0
- package/es/index.d.ts +1 -0
- package/es/index.d.ts.map +1 -1
- package/es/index.js +1 -0
- package/es/module.d.ts.map +1 -1
- package/es/module.js +2 -1
- package/package.json +5 -5
- package/src/code-editor-inline-completions/index.ts +3 -0
- package/src/code-editor-inline-completions/inline-completions-manager.ts +44 -0
- package/src/code-editor-inline-completions/inline-completions-protocol.ts +173 -0
- package/src/code-editor-inline-completions/sequencer.ts +10 -0
- package/src/index.spec.ts +1 -3
- package/src/index.ts +1 -0
- package/src/module.ts +10 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/code-editor-inline-completions/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { ApplicationContribution } from '@difizen/mana-app';
|
|
3
|
+
import type { InlineCompletionImplement, InlineCompletionRegistry } from './inline-completions-protocol.js';
|
|
4
|
+
import { InlineCompletionContribution } from './inline-completions-protocol.js';
|
|
5
|
+
export declare class InlineCompletionManager implements InlineCompletionRegistry, ApplicationContribution {
|
|
6
|
+
private completionImplements;
|
|
7
|
+
protected readonly completionsProvider: Contribution.Provider<InlineCompletionContribution>;
|
|
8
|
+
constructor(completionsProvider: Contribution.Provider<InlineCompletionContribution>);
|
|
9
|
+
addCompletion(obj: InlineCompletionImplement): void;
|
|
10
|
+
get getCompletionImplements(): InlineCompletionImplement[];
|
|
11
|
+
onStart(): void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=inline-completions-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-completions-manager.d.ts","sourceRoot":"","sources":["../../src/code-editor-inline-completions/inline-completions-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAIL,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACzB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAEhF,qBACa,uBACX,YAAW,wBAAwB,EAAE,uBAAuB;IAE5D,OAAO,CAAC,oBAAoB,CAAmC;IAC/D,SAAS,CAAC,QAAQ,CAAC,mBAAmB,EAAE,YAAY,CAAC,QAAQ,CAAC,4BAA4B,CAAC,CAAC;gBAI1F,mBAAmB,EAAE,YAAY,CAAC,QAAQ,CAAC,4BAA4B,CAAC;IAK1E,aAAa,CAAC,GAAG,EAAE,yBAAyB;IAI5C,IAAI,uBAAuB,gCAE1B;IAED,OAAO;CAOR"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
import { contrib, Priority, singleton, ApplicationContribution } from '@difizen/mana-app';
|
|
9
|
+
import { InlineCompletionContribution } from "./inline-completions-protocol.js";
|
|
10
|
+
export var InlineCompletionManager = (_dec = singleton({
|
|
11
|
+
contrib: [ApplicationContribution]
|
|
12
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
13
|
+
function InlineCompletionManager(completionsProvider) {
|
|
14
|
+
_classCallCheck(this, InlineCompletionManager);
|
|
15
|
+
this.completionImplements = [];
|
|
16
|
+
this.completionsProvider = completionsProvider;
|
|
17
|
+
}
|
|
18
|
+
InlineCompletionManager = contrib(InlineCompletionContribution)(InlineCompletionManager, undefined, 0) || InlineCompletionManager;
|
|
19
|
+
_createClass(InlineCompletionManager, [{
|
|
20
|
+
key: "addCompletion",
|
|
21
|
+
value: function addCompletion(obj) {
|
|
22
|
+
this.completionImplements.push(obj);
|
|
23
|
+
}
|
|
24
|
+
}, {
|
|
25
|
+
key: "getCompletionImplements",
|
|
26
|
+
get: function get() {
|
|
27
|
+
return this.completionImplements;
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "onStart",
|
|
31
|
+
value: function onStart() {
|
|
32
|
+
var _this = this;
|
|
33
|
+
var prioritized = Priority.sortSync(this.completionsProvider.getContributions(), function (contribution) {
|
|
34
|
+
return contribution.canHandle();
|
|
35
|
+
});
|
|
36
|
+
prioritized.map(function (c) {
|
|
37
|
+
return c.value.registerCompletion(_this);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}]);
|
|
41
|
+
return InlineCompletionManager;
|
|
42
|
+
}()) || _class);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Syringe } from '@difizen/mana-app';
|
|
2
|
+
import type { IPosition, IRange } from '../code-editor-protocol.js';
|
|
3
|
+
export interface IRelativePattern {
|
|
4
|
+
/**
|
|
5
|
+
* A base file path to which this pattern will be matched against relatively.
|
|
6
|
+
*/
|
|
7
|
+
readonly base: string;
|
|
8
|
+
/**
|
|
9
|
+
* A file glob pattern like `*.{ts,js}` that will be matched on file paths
|
|
10
|
+
* relative to the base path.
|
|
11
|
+
*
|
|
12
|
+
* Example: Given a base of `/home/work/folder` and a file path of `/home/work/folder/index.js`,
|
|
13
|
+
* the file glob pattern will match on `index.js`.
|
|
14
|
+
*/
|
|
15
|
+
readonly pattern: string;
|
|
16
|
+
}
|
|
17
|
+
export interface LanguageFilter {
|
|
18
|
+
readonly language?: string;
|
|
19
|
+
readonly scheme?: string;
|
|
20
|
+
readonly pattern?: string | IRelativePattern;
|
|
21
|
+
readonly notebookType?: string;
|
|
22
|
+
/**
|
|
23
|
+
* This provider is implemented in the UI thread.
|
|
24
|
+
*/
|
|
25
|
+
readonly hasAccessToAllModels?: boolean;
|
|
26
|
+
readonly exclusive?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* This provider comes from a builtin extension.
|
|
29
|
+
*/
|
|
30
|
+
readonly isBuiltin?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export type LanguageSelector = string | LanguageFilter | ReadonlyArray<string | LanguageFilter>;
|
|
33
|
+
export interface ICompletionContext {
|
|
34
|
+
prefix: string;
|
|
35
|
+
suffix: string;
|
|
36
|
+
fileUrl: string;
|
|
37
|
+
filename: string;
|
|
38
|
+
language: string;
|
|
39
|
+
position?: IPosition;
|
|
40
|
+
extra?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 补全请求对象
|
|
44
|
+
*/
|
|
45
|
+
export interface IAICompletionOption {
|
|
46
|
+
sessionId: string;
|
|
47
|
+
/**
|
|
48
|
+
* 模型输入上文
|
|
49
|
+
*/
|
|
50
|
+
prompt: string;
|
|
51
|
+
/**
|
|
52
|
+
* 代码下文
|
|
53
|
+
*/
|
|
54
|
+
suffix?: string | null;
|
|
55
|
+
workspaceDir?: string;
|
|
56
|
+
/**
|
|
57
|
+
* 文件路径
|
|
58
|
+
*/
|
|
59
|
+
fileUrl: string;
|
|
60
|
+
/**
|
|
61
|
+
* 代码语言类型
|
|
62
|
+
*/
|
|
63
|
+
language: string;
|
|
64
|
+
}
|
|
65
|
+
export interface InlineCompletion {
|
|
66
|
+
/**
|
|
67
|
+
* The text to insert.
|
|
68
|
+
* If the text contains a line break, the range must end at the end of a line.
|
|
69
|
+
* If existing text should be replaced, the existing text must be a prefix of the text to insert.
|
|
70
|
+
*
|
|
71
|
+
* The text can also be a snippet. In that case, a preview with default parameters is shown.
|
|
72
|
+
* When accepting the suggestion, the full snippet is inserted.
|
|
73
|
+
*/
|
|
74
|
+
readonly insertText: string | {
|
|
75
|
+
snippet: string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* A text that is used to decide if this inline completion should be shown.
|
|
79
|
+
* An inline completion is shown if the text to replace is a subword of the filter text.
|
|
80
|
+
*/
|
|
81
|
+
readonly filterText?: string;
|
|
82
|
+
/**
|
|
83
|
+
* An optional array of additional text edits that are applied when
|
|
84
|
+
* selecting this completion. Edits must not overlap with the main edit
|
|
85
|
+
* nor with themselves.
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* The range to replace.
|
|
89
|
+
* Must begin and end on the same line.
|
|
90
|
+
*/
|
|
91
|
+
readonly range?: IRange;
|
|
92
|
+
/**
|
|
93
|
+
* If set to `true`, unopened closing brackets are removed and unclosed opening brackets are closed.
|
|
94
|
+
* Defaults to `false`.
|
|
95
|
+
*/
|
|
96
|
+
readonly completeBracketPairs?: boolean;
|
|
97
|
+
}
|
|
98
|
+
export interface IIntelligentCompletionsResult<T = any> {
|
|
99
|
+
readonly items: InlineCompletion[];
|
|
100
|
+
/**
|
|
101
|
+
* 定义的额外信息
|
|
102
|
+
*/
|
|
103
|
+
extra?: T;
|
|
104
|
+
}
|
|
105
|
+
export declare const InlineCompletionContribution: Syringe.DefinedToken;
|
|
106
|
+
export interface InlineCompletionRegistry {
|
|
107
|
+
addCompletion: (obj: InlineCompletionImplement) => void;
|
|
108
|
+
}
|
|
109
|
+
export interface InlineCompletionContribution {
|
|
110
|
+
canHandle: () => number;
|
|
111
|
+
registerCompletion: (register: InlineCompletionRegistry) => void;
|
|
112
|
+
}
|
|
113
|
+
export interface InlineCompletionProvider {
|
|
114
|
+
provideInlineCompletionItems: ProvideInlineCompletionsFunction;
|
|
115
|
+
}
|
|
116
|
+
export interface CancellationToken {
|
|
117
|
+
/**
|
|
118
|
+
* A flag signalling is cancellation has been requested.
|
|
119
|
+
*/
|
|
120
|
+
readonly isCancellationRequested: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* An event which fires when cancellation is requested. This event
|
|
123
|
+
* only ever fires `once` as cancellation can only happen once. Listeners
|
|
124
|
+
* that are registered after cancellation will be called (next event loop run),
|
|
125
|
+
* but also only once.
|
|
126
|
+
*
|
|
127
|
+
* @event
|
|
128
|
+
*/
|
|
129
|
+
readonly onCancellationRequested: (listener: (e: any) => any, thisArgs?: any, disposables?: IDisposable[]) => IDisposable;
|
|
130
|
+
}
|
|
131
|
+
export interface IDisposable {
|
|
132
|
+
dispose(): void;
|
|
133
|
+
}
|
|
134
|
+
export interface InlineCompletionImplement {
|
|
135
|
+
selector: LanguageSelector;
|
|
136
|
+
getInlineCompletions: ProvideInlineCompletionsFunction;
|
|
137
|
+
freeInlineCompletions: any;
|
|
138
|
+
}
|
|
139
|
+
export type ProvideInlineCompletionsFunction = (context: ICompletionContext, token: CancellationToken) => Promise<IIntelligentCompletionsResult | undefined>;
|
|
140
|
+
//# sourceMappingURL=inline-completions-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-completions-protocol.d.ts","sourceRoot":"","sources":["../../src/code-editor-inline-completions/inline-completions-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpE,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IACxC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,QAAQ,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,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAGrD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
+
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); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
// 请求队列,严格保证请求的先后顺序
|
|
8
|
+
export var Sequencer = /*#__PURE__*/function () {
|
|
9
|
+
function Sequencer() {
|
|
10
|
+
_classCallCheck(this, Sequencer);
|
|
11
|
+
this.current = Promise.resolve(null);
|
|
12
|
+
}
|
|
13
|
+
_createClass(Sequencer, [{
|
|
14
|
+
key: "queue",
|
|
15
|
+
value: function queue(promiseTask) {
|
|
16
|
+
return this.current = this.current.then(function () {
|
|
17
|
+
return promiseTask();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}]);
|
|
21
|
+
return Sequencer;
|
|
22
|
+
}();
|
package/es/index.d.ts
CHANGED
package/es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
|
package/es/index.js
CHANGED
package/es/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAe/C,eAAO,MAAM,gBAAgB,YAe1B,CAAC"}
|
package/es/module.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ManaModule } from '@difizen/mana-app';
|
|
2
2
|
import { CodeEditorInfoManager } from "./code-editor-info-manager.js";
|
|
3
|
+
import { InlineCompletionContribution, InlineCompletionManager } from "./code-editor-inline-completions/index.js";
|
|
3
4
|
import { CodeEditorManager } from "./code-editor-manager.js";
|
|
4
5
|
import { Model } from "./code-editor-model.js";
|
|
5
6
|
import { CodeEditorContribution } from "./code-editor-protocol.js";
|
|
@@ -7,4 +8,4 @@ import { CodeEditorSettings } from "./code-editor-settings.js";
|
|
|
7
8
|
import { CodeEditorStateManager } from "./code-editor-state-manager.js";
|
|
8
9
|
import { CodeEditorView } from "./code-editor-view.js";
|
|
9
10
|
import { LanguageSpecContribution, LanguageSpecRegistry } from "./language-specs.js";
|
|
10
|
-
export var CodeEditorModule = ManaModule.create().register(CodeEditorInfoManager, CodeEditorView, CodeEditorManager, Model, CodeEditorSettings, CodeEditorStateManager, LanguageSpecRegistry).contribution(CodeEditorContribution, LanguageSpecContribution);
|
|
11
|
+
export var CodeEditorModule = ManaModule.create().register(CodeEditorInfoManager, CodeEditorView, CodeEditorManager, Model, CodeEditorSettings, CodeEditorStateManager, LanguageSpecRegistry, InlineCompletionManager).contribution(CodeEditorContribution, LanguageSpecContribution, InlineCompletionContribution);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-code-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@difizen/libro-common": "^0.3.1",
|
|
35
36
|
"@difizen/mana-app": "latest",
|
|
36
37
|
"@difizen/mana-l10n": "latest",
|
|
37
|
-
"
|
|
38
|
-
"uuid": "^9.0.0"
|
|
38
|
+
"uuid": "^9.0.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/react": "^18.
|
|
45
|
-
"@types/uuid": "^9.0.
|
|
44
|
+
"@types/react": "^18.3.12",
|
|
45
|
+
"@types/uuid": "^9.0.8"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"setup": "father build",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import {
|
|
3
|
+
contrib,
|
|
4
|
+
Priority,
|
|
5
|
+
singleton,
|
|
6
|
+
ApplicationContribution,
|
|
7
|
+
} from '@difizen/mana-app';
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
InlineCompletionImplement,
|
|
11
|
+
InlineCompletionRegistry,
|
|
12
|
+
} from './inline-completions-protocol.js';
|
|
13
|
+
import { InlineCompletionContribution } from './inline-completions-protocol.js';
|
|
14
|
+
|
|
15
|
+
@singleton({ contrib: [ApplicationContribution] })
|
|
16
|
+
export class InlineCompletionManager
|
|
17
|
+
implements InlineCompletionRegistry, ApplicationContribution
|
|
18
|
+
{
|
|
19
|
+
private completionImplements: InlineCompletionImplement[] = [];
|
|
20
|
+
protected readonly completionsProvider: Contribution.Provider<InlineCompletionContribution>;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
@contrib(InlineCompletionContribution)
|
|
24
|
+
completionsProvider: Contribution.Provider<InlineCompletionContribution>,
|
|
25
|
+
) {
|
|
26
|
+
this.completionsProvider = completionsProvider;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addCompletion(obj: InlineCompletionImplement) {
|
|
30
|
+
this.completionImplements.push(obj);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get getCompletionImplements() {
|
|
34
|
+
return this.completionImplements;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
onStart() {
|
|
38
|
+
const prioritized = Priority.sortSync(
|
|
39
|
+
this.completionsProvider.getContributions(),
|
|
40
|
+
(contribution) => contribution.canHandle(),
|
|
41
|
+
);
|
|
42
|
+
prioritized.map((c) => c.value.registerCompletion(this));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Syringe } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { IPosition, IRange } from '../code-editor-protocol.js';
|
|
4
|
+
|
|
5
|
+
export interface IRelativePattern {
|
|
6
|
+
/**
|
|
7
|
+
* A base file path to which this pattern will be matched against relatively.
|
|
8
|
+
*/
|
|
9
|
+
readonly base: string;
|
|
10
|
+
/**
|
|
11
|
+
* A file glob pattern like `*.{ts,js}` that will be matched on file paths
|
|
12
|
+
* relative to the base path.
|
|
13
|
+
*
|
|
14
|
+
* Example: Given a base of `/home/work/folder` and a file path of `/home/work/folder/index.js`,
|
|
15
|
+
* the file glob pattern will match on `index.js`.
|
|
16
|
+
*/
|
|
17
|
+
readonly pattern: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface LanguageFilter {
|
|
21
|
+
readonly language?: string;
|
|
22
|
+
readonly scheme?: string;
|
|
23
|
+
readonly pattern?: string | IRelativePattern;
|
|
24
|
+
readonly notebookType?: string;
|
|
25
|
+
/**
|
|
26
|
+
* This provider is implemented in the UI thread.
|
|
27
|
+
*/
|
|
28
|
+
readonly hasAccessToAllModels?: boolean;
|
|
29
|
+
readonly exclusive?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* This provider comes from a builtin extension.
|
|
32
|
+
*/
|
|
33
|
+
readonly isBuiltin?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type LanguageSelector =
|
|
37
|
+
| string
|
|
38
|
+
| LanguageFilter
|
|
39
|
+
| ReadonlyArray<string | LanguageFilter>;
|
|
40
|
+
|
|
41
|
+
export interface ICompletionContext {
|
|
42
|
+
prefix: string;
|
|
43
|
+
suffix: string;
|
|
44
|
+
fileUrl: string;
|
|
45
|
+
filename: string;
|
|
46
|
+
// workspaceDir: string;
|
|
47
|
+
language: string;
|
|
48
|
+
position?: IPosition;
|
|
49
|
+
extra?: Record<string, any>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 补全请求对象
|
|
54
|
+
*/
|
|
55
|
+
export interface IAICompletionOption {
|
|
56
|
+
sessionId: string;
|
|
57
|
+
/**
|
|
58
|
+
* 模型输入上文
|
|
59
|
+
*/
|
|
60
|
+
prompt: string;
|
|
61
|
+
/**
|
|
62
|
+
* 代码下文
|
|
63
|
+
*/
|
|
64
|
+
suffix?: string | null;
|
|
65
|
+
|
|
66
|
+
workspaceDir?: string;
|
|
67
|
+
/**
|
|
68
|
+
* 文件路径
|
|
69
|
+
*/
|
|
70
|
+
fileUrl: string;
|
|
71
|
+
/**
|
|
72
|
+
* 代码语言类型
|
|
73
|
+
*/
|
|
74
|
+
language: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface InlineCompletion {
|
|
78
|
+
/**
|
|
79
|
+
* The text to insert.
|
|
80
|
+
* If the text contains a line break, the range must end at the end of a line.
|
|
81
|
+
* If existing text should be replaced, the existing text must be a prefix of the text to insert.
|
|
82
|
+
*
|
|
83
|
+
* The text can also be a snippet. In that case, a preview with default parameters is shown.
|
|
84
|
+
* When accepting the suggestion, the full snippet is inserted.
|
|
85
|
+
*/
|
|
86
|
+
readonly insertText:
|
|
87
|
+
| string
|
|
88
|
+
| {
|
|
89
|
+
snippet: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* A text that is used to decide if this inline completion should be shown.
|
|
93
|
+
* An inline completion is shown if the text to replace is a subword of the filter text.
|
|
94
|
+
*/
|
|
95
|
+
readonly filterText?: string;
|
|
96
|
+
/**
|
|
97
|
+
* An optional array of additional text edits that are applied when
|
|
98
|
+
* selecting this completion. Edits must not overlap with the main edit
|
|
99
|
+
* nor with themselves.
|
|
100
|
+
*/
|
|
101
|
+
// readonly additionalTextEdits?: editor.ISingleEditOperation[];
|
|
102
|
+
/**
|
|
103
|
+
* The range to replace.
|
|
104
|
+
* Must begin and end on the same line.
|
|
105
|
+
*/
|
|
106
|
+
readonly range?: IRange;
|
|
107
|
+
// readonly command?: Command;
|
|
108
|
+
/**
|
|
109
|
+
* If set to `true`, unopened closing brackets are removed and unclosed opening brackets are closed.
|
|
110
|
+
* Defaults to `false`.
|
|
111
|
+
*/
|
|
112
|
+
readonly completeBracketPairs?: boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface IIntelligentCompletionsResult<T = any> {
|
|
116
|
+
readonly items: InlineCompletion[];
|
|
117
|
+
/**
|
|
118
|
+
* 定义的额外信息
|
|
119
|
+
*/
|
|
120
|
+
extra?: T;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export const InlineCompletionContribution = Syringe.defineToken(
|
|
124
|
+
'InlineCompletionContribution',
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
export interface InlineCompletionRegistry {
|
|
128
|
+
addCompletion: (obj: InlineCompletionImplement) => void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface InlineCompletionContribution {
|
|
132
|
+
canHandle: () => number;
|
|
133
|
+
registerCompletion: (register: InlineCompletionRegistry) => void;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface InlineCompletionProvider {
|
|
137
|
+
provideInlineCompletionItems: ProvideInlineCompletionsFunction;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface CancellationToken {
|
|
141
|
+
/**
|
|
142
|
+
* A flag signalling is cancellation has been requested.
|
|
143
|
+
*/
|
|
144
|
+
readonly isCancellationRequested: boolean;
|
|
145
|
+
/**
|
|
146
|
+
* An event which fires when cancellation is requested. This event
|
|
147
|
+
* only ever fires `once` as cancellation can only happen once. Listeners
|
|
148
|
+
* that are registered after cancellation will be called (next event loop run),
|
|
149
|
+
* but also only once.
|
|
150
|
+
*
|
|
151
|
+
* @event
|
|
152
|
+
*/
|
|
153
|
+
readonly onCancellationRequested: (
|
|
154
|
+
listener: (e: any) => any,
|
|
155
|
+
thisArgs?: any,
|
|
156
|
+
disposables?: IDisposable[],
|
|
157
|
+
) => IDisposable;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface IDisposable {
|
|
161
|
+
dispose(): void;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface InlineCompletionImplement {
|
|
165
|
+
selector: LanguageSelector;
|
|
166
|
+
getInlineCompletions: ProvideInlineCompletionsFunction;
|
|
167
|
+
freeInlineCompletions: any;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type ProvideInlineCompletionsFunction = (
|
|
171
|
+
context: ICompletionContext,
|
|
172
|
+
token: CancellationToken,
|
|
173
|
+
) => Promise<IIntelligentCompletionsResult | undefined>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ITask<T> = () => T;
|
|
2
|
+
|
|
3
|
+
// 请求队列,严格保证请求的先后顺序
|
|
4
|
+
export class Sequencer {
|
|
5
|
+
private current: Promise<any> = Promise.resolve(null);
|
|
6
|
+
|
|
7
|
+
queue<T>(promiseTask: ITask<Promise<T>>): Promise<T> {
|
|
8
|
+
return (this.current = this.current.then(() => promiseTask()));
|
|
9
|
+
}
|
|
10
|
+
}
|
package/src/index.spec.ts
CHANGED
package/src/index.ts
CHANGED
package/src/module.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ManaModule } from '@difizen/mana-app';
|
|
2
2
|
|
|
3
3
|
import { CodeEditorInfoManager } from './code-editor-info-manager.js';
|
|
4
|
+
import {
|
|
5
|
+
InlineCompletionContribution,
|
|
6
|
+
InlineCompletionManager,
|
|
7
|
+
} from './code-editor-inline-completions/index.js';
|
|
4
8
|
import { CodeEditorManager } from './code-editor-manager.js';
|
|
5
9
|
import { Model } from './code-editor-model.js';
|
|
6
10
|
import { CodeEditorContribution } from './code-editor-protocol.js';
|
|
@@ -18,5 +22,10 @@ export const CodeEditorModule = ManaModule.create()
|
|
|
18
22
|
CodeEditorSettings,
|
|
19
23
|
CodeEditorStateManager,
|
|
20
24
|
LanguageSpecRegistry,
|
|
25
|
+
InlineCompletionManager,
|
|
21
26
|
)
|
|
22
|
-
.contribution(
|
|
27
|
+
.contribution(
|
|
28
|
+
CodeEditorContribution,
|
|
29
|
+
LanguageSpecContribution,
|
|
30
|
+
InlineCompletionContribution,
|
|
31
|
+
);
|