@theia/ai-code-completion 1.67.0-next.56 → 1.67.0-next.86

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 (65) hide show
  1. package/lib/browser/ai-code-completion-frontend-module.d.ts +4 -0
  2. package/lib/browser/ai-code-completion-frontend-module.d.ts.map +1 -0
  3. package/lib/browser/ai-code-completion-frontend-module.js +40 -0
  4. package/lib/browser/ai-code-completion-frontend-module.js.map +1 -0
  5. package/lib/browser/ai-code-frontend-application-contribution.d.ts +17 -0
  6. package/lib/browser/ai-code-frontend-application-contribution.d.ts.map +1 -0
  7. package/lib/browser/ai-code-frontend-application-contribution.js +135 -0
  8. package/lib/browser/ai-code-frontend-application-contribution.js.map +1 -0
  9. package/lib/browser/ai-code-inline-completion-provider.d.ts +9 -0
  10. package/lib/browser/ai-code-inline-completion-provider.d.ts.map +1 -0
  11. package/lib/browser/ai-code-inline-completion-provider.js +46 -0
  12. package/lib/browser/ai-code-inline-completion-provider.js.map +1 -0
  13. package/lib/browser/code-completion-agent.d.ts +27 -0
  14. package/lib/browser/code-completion-agent.d.ts.map +1 -0
  15. package/lib/browser/code-completion-agent.js +148 -0
  16. package/lib/browser/code-completion-agent.js.map +1 -0
  17. package/lib/browser/code-completion-cache.d.ts +49 -0
  18. package/lib/browser/code-completion-cache.d.ts.map +1 -0
  19. package/lib/browser/code-completion-cache.js +135 -0
  20. package/lib/browser/code-completion-cache.js.map +1 -0
  21. package/lib/browser/code-completion-debouncer.d.ts +5 -0
  22. package/lib/browser/code-completion-debouncer.d.ts.map +1 -0
  23. package/lib/browser/code-completion-debouncer.js +35 -0
  24. package/lib/browser/code-completion-debouncer.js.map +1 -0
  25. package/lib/browser/code-completion-postprocessor.d.ts +11 -0
  26. package/lib/browser/code-completion-postprocessor.d.ts.map +1 -0
  27. package/lib/browser/code-completion-postprocessor.js +49 -0
  28. package/lib/browser/code-completion-postprocessor.js.map +1 -0
  29. package/lib/browser/code-completion-postprocessor.spec.d.ts +2 -0
  30. package/lib/browser/code-completion-postprocessor.spec.d.ts.map +1 -0
  31. package/lib/browser/code-completion-postprocessor.spec.js +73 -0
  32. package/lib/browser/code-completion-postprocessor.spec.js.map +1 -0
  33. package/lib/browser/code-completion-prompt-template.d.ts +3 -0
  34. package/lib/browser/code-completion-prompt-template.d.ts.map +1 -0
  35. package/lib/browser/code-completion-prompt-template.js +82 -0
  36. package/lib/browser/code-completion-prompt-template.js.map +1 -0
  37. package/lib/browser/code-completion-variable-context.d.ts +11 -0
  38. package/lib/browser/code-completion-variable-context.d.ts.map +1 -0
  39. package/lib/browser/code-completion-variable-context.js +26 -0
  40. package/lib/browser/code-completion-variable-context.js.map +1 -0
  41. package/lib/browser/code-completion-variable-contribution.d.ts +15 -0
  42. package/lib/browser/code-completion-variable-contribution.d.ts.map +1 -0
  43. package/lib/browser/code-completion-variable-contribution.js +127 -0
  44. package/lib/browser/code-completion-variable-contribution.js.map +1 -0
  45. package/lib/browser/code-completion-variable-contribution.spec.d.ts +2 -0
  46. package/lib/browser/code-completion-variable-contribution.spec.d.ts.map +1 -0
  47. package/lib/browser/code-completion-variable-contribution.spec.js +143 -0
  48. package/lib/browser/code-completion-variable-contribution.spec.js.map +1 -0
  49. package/lib/browser/code-completion-variables.d.ts +6 -0
  50. package/lib/browser/code-completion-variables.d.ts.map +1 -0
  51. package/lib/browser/code-completion-variables.js +40 -0
  52. package/lib/browser/code-completion-variables.js.map +1 -0
  53. package/lib/common/ai-code-completion-preference.d.ts +9 -0
  54. package/lib/common/ai-code-completion-preference.d.ts.map +1 -0
  55. package/lib/common/ai-code-completion-preference.js +78 -0
  56. package/lib/common/ai-code-completion-preference.js.map +1 -0
  57. package/lib/node/ai-code-completion-backend-module.d.ts +4 -0
  58. package/lib/node/ai-code-completion-backend-module.d.ts.map +1 -0
  59. package/lib/node/ai-code-completion-backend-module.js +24 -0
  60. package/lib/node/ai-code-completion-backend-module.js.map +1 -0
  61. package/lib/package.spec.d.ts +1 -0
  62. package/lib/package.spec.d.ts.map +1 -0
  63. package/lib/package.spec.js +26 -0
  64. package/lib/package.spec.js.map +1 -0
  65. package/package.json +7 -7
@@ -0,0 +1,4 @@
1
+ import { ContainerModule } from '@theia/core/shared/inversify';
2
+ declare const _default: ContainerModule;
3
+ export default _default;
4
+ //# sourceMappingURL=ai-code-completion-frontend-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-code-completion-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAS/D,wBAWG"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const ai_core_1 = require("@theia/ai-core");
19
+ const browser_1 = require("@theia/core/lib/browser");
20
+ const inversify_1 = require("@theia/core/shared/inversify");
21
+ const ai_code_completion_preference_1 = require("../common/ai-code-completion-preference");
22
+ const ai_code_frontend_application_contribution_1 = require("./ai-code-frontend-application-contribution");
23
+ const ai_code_inline_completion_provider_1 = require("./ai-code-inline-completion-provider");
24
+ const code_completion_agent_1 = require("./code-completion-agent");
25
+ const code_completion_postprocessor_1 = require("./code-completion-postprocessor");
26
+ const code_completion_variable_contribution_1 = require("./code-completion-variable-contribution");
27
+ const core_1 = require("@theia/core");
28
+ exports.default = new inversify_1.ContainerModule(bind => {
29
+ bind(code_completion_agent_1.CodeCompletionAgentImpl).toSelf().inSingletonScope();
30
+ bind(code_completion_agent_1.CodeCompletionAgent).toService(code_completion_agent_1.CodeCompletionAgentImpl);
31
+ bind(ai_core_1.Agent).toService(code_completion_agent_1.CodeCompletionAgentImpl);
32
+ bind(ai_code_inline_completion_provider_1.AICodeInlineCompletionsProvider).toSelf().inSingletonScope();
33
+ bind(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution).toSelf().inSingletonScope();
34
+ bind(browser_1.FrontendApplicationContribution).to(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution);
35
+ bind(browser_1.KeybindingContribution).toService(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution);
36
+ bind(core_1.PreferenceContribution).toConstantValue({ schema: ai_code_completion_preference_1.AICodeCompletionPreferencesSchema });
37
+ bind(code_completion_postprocessor_1.CodeCompletionPostProcessor).to(code_completion_postprocessor_1.DefaultCodeCompletionPostProcessor).inSingletonScope();
38
+ bind(ai_core_1.AIVariableContribution).to(code_completion_variable_contribution_1.CodeCompletionVariableContribution).inSingletonScope();
39
+ });
40
+ //# sourceMappingURL=ai-code-completion-frontend-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-code-completion-frontend-module.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,4CAA+D;AAC/D,qDAAmG;AACnG,4DAA+D;AAC/D,2FAA4F;AAC5F,2GAAgG;AAChG,6FAAuF;AACvF,mEAAuF;AACvF,mFAAkH;AAClH,mGAA6F;AAC7F,sCAAqD;AAErD,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,+CAAuB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC1D,IAAI,CAAC,2CAAmB,CAAC,CAAC,SAAS,CAAC,+CAAuB,CAAC,CAAC;IAC7D,IAAI,CAAC,eAAK,CAAC,CAAC,SAAS,CAAC,+CAAuB,CAAC,CAAC;IAC/C,IAAI,CAAC,oEAA+B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAClE,IAAI,CAAC,6EAAiC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACpE,IAAI,CAAC,yCAA+B,CAAC,CAAC,EAAE,CAAC,6EAAiC,CAAC,CAAC;IAC5E,IAAI,CAAC,gCAAsB,CAAC,CAAC,SAAS,CAAC,6EAAiC,CAAC,CAAC;IAC1E,IAAI,CAAC,6BAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,iEAAiC,EAAE,CAAC,CAAC;IAC5F,IAAI,CAAC,2DAA2B,CAAC,CAAC,EAAE,CAAC,kEAAkC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAC5F,IAAI,CAAC,gCAAsB,CAAC,CAAC,EAAE,CAAC,0EAAkC,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAC3F,CAAC,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { AIActivationService } from '@theia/ai-core/lib/browser';
2
+ import { Disposable, PreferenceService } from '@theia/core';
3
+ import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry } from '@theia/core/lib/browser';
4
+ export declare class AIFrontendApplicationContribution implements FrontendApplicationContribution, KeybindingContribution {
5
+ private inlineCodeCompletionProvider;
6
+ protected readonly preferenceService: PreferenceService;
7
+ protected readonly activationService: AIActivationService;
8
+ private completionCache;
9
+ private debouncer;
10
+ private debounceDelay;
11
+ private toDispose;
12
+ onDidInitializeLayout(): void;
13
+ protected handlePreferences(): void;
14
+ registerKeybindings(keybindings: KeybindingRegistry): void;
15
+ protected handleInlineCompletions(): Disposable;
16
+ }
17
+ //# sourceMappingURL=ai-code-frontend-application-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-code-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAatH,qBACa,iCAAkC,YAAW,+BAA+B,EAAE,sBAAsB;IAE7G,OAAO,CAAC,4BAA4B,CAAkC;IAGtE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IAE1D,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,SAAS,CAAmC;IACpD,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,SAAS,CAAiC;IAElD,qBAAqB,IAAI,IAAI;IAM7B,SAAS,CAAC,iBAAiB,IAAI,IAAI;IA8BnC,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI;IAQ1D,SAAS,CAAC,uBAAuB,IAAI,UAAU;CA0DlD"}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.AIFrontendApplicationContribution = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const monaco = require("@theia/monaco-editor-core");
21
+ const browser_1 = require("@theia/ai-core/lib/browser");
22
+ const core_1 = require("@theia/core");
23
+ const inversify_1 = require("@theia/core/shared/inversify");
24
+ const languages_1 = require("@theia/monaco-editor-core/esm/vs/editor/common/languages");
25
+ const ai_code_completion_preference_1 = require("../common/ai-code-completion-preference");
26
+ const ai_code_inline_completion_provider_1 = require("./ai-code-inline-completion-provider");
27
+ const code_completion_debouncer_1 = require("./code-completion-debouncer");
28
+ const code_completion_cache_1 = require("./code-completion-cache");
29
+ let AIFrontendApplicationContribution = class AIFrontendApplicationContribution {
30
+ constructor() {
31
+ this.completionCache = new code_completion_cache_1.CodeCompletionCache();
32
+ this.debouncer = new code_completion_debouncer_1.InlineCompletionDebouncer();
33
+ this.toDispose = new Map();
34
+ }
35
+ onDidInitializeLayout() {
36
+ this.preferenceService.ready.then(() => {
37
+ this.handlePreferences();
38
+ });
39
+ }
40
+ handlePreferences() {
41
+ const handler = () => this.handleInlineCompletions();
42
+ this.toDispose.set('inlineCompletions', handler());
43
+ this.debounceDelay = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY, 300);
44
+ const cacheCapacity = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY, 100);
45
+ this.completionCache.setMaxSize(cacheCapacity);
46
+ this.preferenceService.onPreferenceChanged(event => {
47
+ var _a;
48
+ if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE
49
+ || event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
50
+ (_a = this.toDispose.get('inlineCompletions')) === null || _a === void 0 ? void 0 : _a.dispose();
51
+ this.toDispose.set('inlineCompletions', handler());
52
+ }
53
+ if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY) {
54
+ this.debounceDelay = event.newValue;
55
+ }
56
+ if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY) {
57
+ this.completionCache.setMaxSize(event.newValue);
58
+ }
59
+ });
60
+ this.activationService.onDidChangeActiveStatus(change => {
61
+ var _a;
62
+ (_a = this.toDispose.get('inlineCompletions')) === null || _a === void 0 ? void 0 : _a.dispose();
63
+ this.toDispose.set('inlineCompletions', handler());
64
+ });
65
+ }
66
+ registerKeybindings(keybindings) {
67
+ keybindings.registerKeybinding({
68
+ command: 'editor.action.inlineSuggest.trigger',
69
+ keybinding: 'Ctrl+Alt+Space',
70
+ when: '!editorReadonly && editorTextFocus'
71
+ });
72
+ }
73
+ handleInlineCompletions() {
74
+ if (!this.activationService.isActive) {
75
+ return core_1.Disposable.NULL;
76
+ }
77
+ const automatic = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE, true);
78
+ const excludedExtensions = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS, []);
79
+ return monaco.languages.registerInlineCompletionsProvider({ scheme: 'file' }, {
80
+ provideInlineCompletions: (model, position, context, token) => {
81
+ if (!automatic && context.triggerKind === languages_1.InlineCompletionTriggerKind.Automatic) {
82
+ return { items: [] };
83
+ }
84
+ const fileName = model.uri.toString();
85
+ if (excludedExtensions.some(ext => fileName.endsWith(ext))) {
86
+ return { items: [] };
87
+ }
88
+ const completionHandler = async () => {
89
+ try {
90
+ const cacheKey = this.completionCache.generateKey(fileName, model, position);
91
+ const cachedCompletion = this.completionCache.get(cacheKey);
92
+ if (cachedCompletion) {
93
+ return cachedCompletion;
94
+ }
95
+ const completion = await this.inlineCodeCompletionProvider.provideInlineCompletions(model, position, context, token);
96
+ if (completion && completion.items.length > 0) {
97
+ this.completionCache.put(cacheKey, completion);
98
+ }
99
+ return completion;
100
+ }
101
+ catch (error) {
102
+ console.error('Error providing inline completions:', error);
103
+ return { items: [] };
104
+ }
105
+ };
106
+ if (context.triggerKind === languages_1.InlineCompletionTriggerKind.Automatic) {
107
+ return this.debouncer.debounce(async () => completionHandler(), this.debounceDelay);
108
+ }
109
+ else if (context.triggerKind === languages_1.InlineCompletionTriggerKind.Explicit) {
110
+ return completionHandler();
111
+ }
112
+ },
113
+ freeInlineCompletions: completions => {
114
+ this.inlineCodeCompletionProvider.freeInlineCompletions(completions);
115
+ }
116
+ });
117
+ }
118
+ };
119
+ exports.AIFrontendApplicationContribution = AIFrontendApplicationContribution;
120
+ tslib_1.__decorate([
121
+ (0, inversify_1.inject)(ai_code_inline_completion_provider_1.AICodeInlineCompletionsProvider),
122
+ tslib_1.__metadata("design:type", ai_code_inline_completion_provider_1.AICodeInlineCompletionsProvider)
123
+ ], AIFrontendApplicationContribution.prototype, "inlineCodeCompletionProvider", void 0);
124
+ tslib_1.__decorate([
125
+ (0, inversify_1.inject)(core_1.PreferenceService),
126
+ tslib_1.__metadata("design:type", Object)
127
+ ], AIFrontendApplicationContribution.prototype, "preferenceService", void 0);
128
+ tslib_1.__decorate([
129
+ (0, inversify_1.inject)(browser_1.AIActivationService),
130
+ tslib_1.__metadata("design:type", Object)
131
+ ], AIFrontendApplicationContribution.prototype, "activationService", void 0);
132
+ exports.AIFrontendApplicationContribution = AIFrontendApplicationContribution = tslib_1.__decorate([
133
+ (0, inversify_1.injectable)()
134
+ ], AIFrontendApplicationContribution);
135
+ //# sourceMappingURL=ai-code-frontend-application-contribution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-code-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,oDAAoD;AAEpD,wDAAiE;AACjE,sCAA4D;AAE5D,4DAAkE;AAClE,wFAAuG;AACvG,2FAKiD;AACjD,6FAAuF;AACvF,2EAAwE;AACxE,mEAA8D;AAGvD,IAAM,iCAAiC,GAAvC,MAAM,iCAAiC;IAAvC;QAUK,oBAAe,GAAG,IAAI,2CAAmB,EAAE,CAAC;QAC5C,cAAS,GAAG,IAAI,qDAAyB,EAAE,CAAC;QAG5C,cAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;IAwGtD,CAAC;IAtGG,qBAAqB;QACjB,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACnC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC;IAES,iBAAiB;QACvB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAErD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,EAAE,CAAC,CAAC;QAEnD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAS,wEAAwC,EAAE,GAAG,CAAC,CAAC;QAEvG,MAAM,aAAa,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAS,wEAAwC,EAAE,GAAG,CAAC,CAAC;QACxG,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,aAA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AI,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;4BAC5C,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;wBACnD,CAAC;wBAED,OAAO,UAAU,CAAC;oBACtB,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACb,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;wBAC5D,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;oBACzB,CAAC;gBACL,CAAC,CAAC;gBAEF,IAAI,OAAO,CAAC,WAAW,KAAK,uCAA2B,CAAC,SAAS,EAAE,CAAC;oBAChE,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,iBAAiB,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;gBACxF,CAAC;qBAAM,IAAI,OAAO,CAAC,WAAW,KAAK,uCAA2B,CAAC,QAAQ,EAAE,CAAC;oBACtE,OAAO,iBAAiB,EAAE,CAAC;gBAC/B,CAAC;YACL,CAAC;YACD,qBAAqB,EAAE,WAAW,CAAC,EAAE;gBACjC,IAAI,CAAC,4BAA4B,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;YACzE,CAAC;SACJ,CACJ,CAAC;IACN,CAAC;CACJ,CAAA;AAtHY,8EAAiC;AAElC;IADP,IAAA,kBAAM,EAAC,oEAA+B,CAAC;sCACF,oEAA+B;uFAAC;AAGnD;IADlB,IAAA,kBAAM,EAAC,wBAAiB,CAAC;;4EAC8B;AAGrC;IADlB,IAAA,kBAAM,EAAC,6BAAmB,CAAC;;4EAC8B;4CARjD,iCAAiC;IAD7C,IAAA,sBAAU,GAAE;GACA,iCAAiC,CAsH7C"}
@@ -0,0 +1,9 @@
1
+ import * as monaco from '@theia/monaco-editor-core';
2
+ import { CodeCompletionAgent } from './code-completion-agent';
3
+ export declare class AICodeInlineCompletionsProvider implements monaco.languages.InlineCompletionsProvider {
4
+ protected readonly agent: CodeCompletionAgent;
5
+ private readonly agentService;
6
+ provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>;
7
+ freeInlineCompletions(completions: monaco.languages.InlineCompletions<monaco.languages.InlineCompletion>): void;
8
+ }
9
+ //# sourceMappingURL=ai-code-inline-completion-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-code-inline-completion-provider.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,qBACa,+BACT,YAAW,MAAM,CAAC,SAAS,CAAC,yBAAyB;IAErD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IAE9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAEtC,wBAAwB,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EACjD,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAY1D,qBAAqB,CACjB,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,GACnF,IAAI;CAGV"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.AICodeInlineCompletionsProvider = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const inversify_1 = require("@theia/core/shared/inversify");
21
+ const code_completion_agent_1 = require("./code-completion-agent");
22
+ const ai_core_1 = require("@theia/ai-core");
23
+ let AICodeInlineCompletionsProvider = class AICodeInlineCompletionsProvider {
24
+ async provideInlineCompletions(model, position, context, token) {
25
+ if (!this.agentService.isEnabled(this.agent.id)) {
26
+ return undefined;
27
+ }
28
+ return this.agent.provideInlineCompletions(model, position, context, token);
29
+ }
30
+ freeInlineCompletions(completions) {
31
+ // nothing to do
32
+ }
33
+ };
34
+ exports.AICodeInlineCompletionsProvider = AICodeInlineCompletionsProvider;
35
+ tslib_1.__decorate([
36
+ (0, inversify_1.inject)(code_completion_agent_1.CodeCompletionAgent),
37
+ tslib_1.__metadata("design:type", Object)
38
+ ], AICodeInlineCompletionsProvider.prototype, "agent", void 0);
39
+ tslib_1.__decorate([
40
+ (0, inversify_1.inject)(ai_core_1.AgentService),
41
+ tslib_1.__metadata("design:type", Object)
42
+ ], AICodeInlineCompletionsProvider.prototype, "agentService", void 0);
43
+ exports.AICodeInlineCompletionsProvider = AICodeInlineCompletionsProvider = tslib_1.__decorate([
44
+ (0, inversify_1.injectable)()
45
+ ], AICodeInlineCompletionsProvider);
46
+ //# sourceMappingURL=ai-code-inline-completion-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-code-inline-completion-provider.js","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAIhF,4DAAkE;AAClE,mEAA8D;AAC9D,4CAA8C;AAGvC,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAOxC,KAAK,CAAC,wBAAwB,CAC1B,KAA+B,EAC/B,QAAyB,EACzB,OAAiD,EACjD,KAA+B;QAE/B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CACtC,KAAK,EACL,QAAQ,EACR,OAAO,EACP,KAAK,CACR,CAAC;IACN,CAAC;IAED,qBAAqB,CACjB,WAAkF;QAElF,gBAAgB;IACpB,CAAC;CACJ,CAAA;AA7BY,0EAA+B;AAGrB;IADlB,IAAA,kBAAM,EAAC,2CAAmB,CAAC;;8DACkB;AAE7B;IADhB,IAAA,kBAAM,EAAC,sBAAY,CAAC;;qEACuB;0CALnC,+BAA+B;IAD3C,IAAA,sBAAU,GAAE;GACA,+BAA+B,CA6B3C"}
@@ -0,0 +1,27 @@
1
+ import { LanguageModelService } from '@theia/ai-core/lib/browser';
2
+ import { Agent, AgentSpecificVariables, LanguageModelRegistry, LanguageModelRequirement, PromptService, PromptVariantSet } from '@theia/ai-core/lib/common';
3
+ import { ILogger, ProgressService } from '@theia/core';
4
+ import * as monaco from '@theia/monaco-editor-core';
5
+ import { CodeCompletionPostProcessor } from './code-completion-postprocessor';
6
+ export declare const CodeCompletionAgent: unique symbol;
7
+ export interface CodeCompletionAgent extends Agent {
8
+ provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>;
9
+ }
10
+ export declare class CodeCompletionAgentImpl implements CodeCompletionAgent {
11
+ protected languageModelService: LanguageModelService;
12
+ provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>;
13
+ protected logger: ILogger;
14
+ protected languageModelRegistry: LanguageModelRegistry;
15
+ protected promptService: PromptService;
16
+ protected progressService: ProgressService;
17
+ protected postProcessor: CodeCompletionPostProcessor;
18
+ id: string;
19
+ name: string;
20
+ description: string;
21
+ prompts: PromptVariantSet[];
22
+ languageModelRequirements: LanguageModelRequirement[];
23
+ readonly variables: string[];
24
+ readonly functions: string[];
25
+ readonly agentSpecificVariables: AgentSpecificVariables[];
26
+ }
27
+ //# sourceMappingURL=code-completion-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-completion-agent.d.ts","sourceRoot":"","sources":["../../src/browser/code-completion-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACH,KAAK,EAAE,sBAAsB,EAC7B,qBAAqB,EAAE,wBAAwB,EAAE,aAAa,EAC9D,gBAAgB,EAEnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAgB,OAAO,EAAO,eAAe,EAAE,MAAM,aAAa,CAAC;AAE1E,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAI9E,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AACjE,MAAM,WAAW,mBAAoB,SAAQ,KAAK;IAC9C,wBAAwB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAC/E,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAA;CACnJ;AAED,qBACa,uBAAwB,YAAW,mBAAmB;IAE/D,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;IAE/C,wBAAwB,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EACjD,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC;IA+E1D,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAG1B,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGvD,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IAGvC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAG3C,SAAS,CAAC,aAAa,EAAE,2BAA2B,CAAC;IAErD,EAAE,SAAqB;IACvB,IAAI,SAAqB;IACzB,WAAW,SACkI;IAC7I,OAAO,EAAE,gBAAgB,EAAE,CAAyB;IACpD,yBAAyB,EAAE,wBAAwB,EAAE,CAKnD;IACF,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,CAKvD;CACL"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ // *****************************************************************************
3
+ // Copyright (C) 2024 EclipseSource GmbH.
4
+ //
5
+ // This program and the accompanying materials are made available under the
6
+ // terms of the Eclipse Public License v. 2.0 which is available at
7
+ // http://www.eclipse.org/legal/epl-2.0.
8
+ //
9
+ // This Source Code may also be made available under the following Secondary
10
+ // Licenses when the conditions for such availability set forth in the Eclipse
11
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ // with the GNU Classpath Exception which is available at
13
+ // https://www.gnu.org/software/classpath/license.html.
14
+ //
15
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
+ // *****************************************************************************
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CodeCompletionAgentImpl = exports.CodeCompletionAgent = void 0;
19
+ const tslib_1 = require("tslib");
20
+ const browser_1 = require("@theia/ai-core/lib/browser");
21
+ const common_1 = require("@theia/ai-core/lib/common");
22
+ const core_1 = require("@theia/core");
23
+ const inversify_1 = require("@theia/core/shared/inversify");
24
+ const monaco = require("@theia/monaco-editor-core");
25
+ const code_completion_prompt_template_1 = require("./code-completion-prompt-template");
26
+ const code_completion_postprocessor_1 = require("./code-completion-postprocessor");
27
+ const code_completion_variables_1 = require("./code-completion-variables");
28
+ exports.CodeCompletionAgent = Symbol('CodeCompletionAgent');
29
+ let CodeCompletionAgentImpl = class CodeCompletionAgentImpl {
30
+ constructor() {
31
+ this.id = 'Code Completion';
32
+ this.name = 'Code Completion';
33
+ this.description = core_1.nls.localize('theia/ai/completion/agent/description', 'This agent provides inline code completion in the code editor in the Theia IDE.');
34
+ this.prompts = code_completion_prompt_template_1.codeCompletionPrompts;
35
+ this.languageModelRequirements = [
36
+ {
37
+ purpose: 'code-completion',
38
+ identifier: 'default/code-completion',
39
+ },
40
+ ];
41
+ this.variables = [];
42
+ this.functions = [];
43
+ this.agentSpecificVariables = [
44
+ { name: code_completion_variables_1.FILE.id, description: core_1.nls.localize('theia/ai/completion/agent/vars/file/description', 'The URI of the file being edited'), usedInPrompt: true },
45
+ { name: code_completion_variables_1.PREFIX.id, description: core_1.nls.localize('theia/ai/completion/agent/vars/prefix/description', 'The code before the current cursor position'), usedInPrompt: true },
46
+ { name: code_completion_variables_1.SUFFIX.id, description: core_1.nls.localize('theia/ai/completion/agent/vars/suffix/description', 'The code after the current cursor position'), usedInPrompt: true },
47
+ { name: code_completion_variables_1.LANGUAGE.id, description: core_1.nls.localize('theia/ai/completion/agent/vars/language/description', 'The languageId of the file being edited'), usedInPrompt: true }
48
+ ];
49
+ }
50
+ async provideInlineCompletions(model, position, context, token) {
51
+ const progress = await this.progressService.showProgress({ text: core_1.nls.localize('theia/ai/code-completion/progressText', 'Calculating AI code completion...'), options: { location: 'window' } });
52
+ try {
53
+ const languageModel = await this.languageModelRegistry.selectLanguageModel({
54
+ agent: this.id,
55
+ ...this.languageModelRequirements[0],
56
+ });
57
+ if (!languageModel) {
58
+ this.logger.error('No language model found for code-completion-agent');
59
+ return undefined;
60
+ }
61
+ const variableContext = {
62
+ model,
63
+ position,
64
+ context
65
+ };
66
+ if (token.isCancellationRequested) {
67
+ return undefined;
68
+ }
69
+ const prompt = await this.promptService
70
+ .getResolvedPromptFragment('code-completion-system', undefined, variableContext)
71
+ .then(p => p === null || p === void 0 ? void 0 : p.text);
72
+ if (!prompt) {
73
+ this.logger.error('No prompt found for code-completion-agent');
74
+ return undefined;
75
+ }
76
+ // since we do not actually hold complete conversions, the request/response pair is considered a session
77
+ const sessionId = (0, core_1.generateUuid)();
78
+ const requestId = (0, core_1.generateUuid)();
79
+ const request = {
80
+ messages: [{ type: 'text', actor: 'user', text: prompt }],
81
+ settings: {
82
+ stream: false
83
+ },
84
+ agentId: this.id,
85
+ sessionId,
86
+ requestId,
87
+ cancellationToken: token
88
+ };
89
+ if (token.isCancellationRequested) {
90
+ return undefined;
91
+ }
92
+ const response = await this.languageModelService.sendRequest(languageModel, request);
93
+ if (token.isCancellationRequested) {
94
+ return undefined;
95
+ }
96
+ const completionText = await (0, common_1.getTextOfResponse)(response);
97
+ if (token.isCancellationRequested) {
98
+ return undefined;
99
+ }
100
+ const postProcessedCompletionText = this.postProcessor.postProcess(completionText);
101
+ return {
102
+ items: [{
103
+ insertText: postProcessedCompletionText,
104
+ range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column)
105
+ }],
106
+ enableForwardStability: true
107
+ };
108
+ }
109
+ catch (e) {
110
+ if (!token.isCancellationRequested) {
111
+ console.error(e.message, e);
112
+ }
113
+ }
114
+ finally {
115
+ progress.cancel();
116
+ }
117
+ }
118
+ };
119
+ exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl;
120
+ tslib_1.__decorate([
121
+ (0, inversify_1.inject)(browser_1.LanguageModelService),
122
+ tslib_1.__metadata("design:type", Object)
123
+ ], CodeCompletionAgentImpl.prototype, "languageModelService", void 0);
124
+ tslib_1.__decorate([
125
+ (0, inversify_1.inject)(core_1.ILogger),
126
+ (0, inversify_1.named)('code-completion-agent'),
127
+ tslib_1.__metadata("design:type", Object)
128
+ ], CodeCompletionAgentImpl.prototype, "logger", void 0);
129
+ tslib_1.__decorate([
130
+ (0, inversify_1.inject)(common_1.LanguageModelRegistry),
131
+ tslib_1.__metadata("design:type", Object)
132
+ ], CodeCompletionAgentImpl.prototype, "languageModelRegistry", void 0);
133
+ tslib_1.__decorate([
134
+ (0, inversify_1.inject)(common_1.PromptService),
135
+ tslib_1.__metadata("design:type", Object)
136
+ ], CodeCompletionAgentImpl.prototype, "promptService", void 0);
137
+ tslib_1.__decorate([
138
+ (0, inversify_1.inject)(core_1.ProgressService),
139
+ tslib_1.__metadata("design:type", core_1.ProgressService)
140
+ ], CodeCompletionAgentImpl.prototype, "progressService", void 0);
141
+ tslib_1.__decorate([
142
+ (0, inversify_1.inject)(code_completion_postprocessor_1.CodeCompletionPostProcessor),
143
+ tslib_1.__metadata("design:type", Object)
144
+ ], CodeCompletionAgentImpl.prototype, "postProcessor", void 0);
145
+ exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl = tslib_1.__decorate([
146
+ (0, inversify_1.injectable)()
147
+ ], CodeCompletionAgentImpl);
148
+ //# sourceMappingURL=code-completion-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-completion-agent.js","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AAC;gBACF,sBAAsB,EAAE,IAAI;aAC/B,CAAC;QACN,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,IAAI,CAAC,KAAK,CAAC,uBAAuB,EAAE,CAAC;gBACjC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAChC,CAAC;QACL,CAAC;gBACO,CAAC;YACL,QAAQ,CAAC,MAAM,EAAE,CAAC;QACtB,CAAC;IACL,CAAC;CAqCJ,CAAA;AAzHY,0DAAuB;AAEtB;IADT,IAAA,kBAAM,EAAC,8BAAoB,CAAC;;qEACwB;AAsF3C;IAFT,IAAA,kBAAM,EAAC,cAAO,CAAC;IACf,IAAA,iBAAK,EAAC,uBAAuB,CAAC;;uDACL;AAGhB;IADT,IAAA,kBAAM,EAAC,8BAAqB,CAAC;;sEACyB;AAG7C;IADT,IAAA,kBAAM,EAAC,sBAAa,CAAC;;8DACiB;AAG7B;IADT,IAAA,kBAAM,EAAC,sBAAe,CAAC;sCACG,sBAAe;gEAAC;AAGjC;IADT,IAAA,kBAAM,EAAC,2DAA2B,CAAC;;8DACiB;kCApG5C,uBAAuB;IADnC,IAAA,sBAAU,GAAE;GACA,uBAAuB,CAyHnC"}
@@ -0,0 +1,49 @@
1
+ import * as monaco from '@theia/monaco-editor-core';
2
+ export declare class CodeCompletionCache {
3
+ private cache;
4
+ private maxSize;
5
+ constructor();
6
+ /**
7
+ * Generate a unique cache key for code completion based on the file path, cursor position, and the hashed context (prefix and suffix).
8
+ * The prefix and suffix are hashed to avoid storing large or sensitive content directly in the cache key.
9
+ *
10
+ * @param filePath Path of the current file
11
+ * @param model Monaco text model of the file
12
+ * @param position Current cursor position in the editor
13
+ * @returns Unique cache key as a string
14
+ */
15
+ generateKey(filePath: string, model: monaco.editor.ITextModel, position: monaco.Position): string;
16
+ /**
17
+ * Hash a string using a simple hash algorithm (FNV-1a 32-bit).
18
+ * This is not cryptographically secure but is sufficient for cache key uniqueness.
19
+ * @param str The string to hash
20
+ * @returns The hash as a hex string
21
+ */
22
+ private static hashString;
23
+ /**
24
+ * Get a cached completion if available
25
+ * @param key Cache key
26
+ * @returns Cached completion or undefined
27
+ */
28
+ get(key: string): monaco.languages.InlineCompletions | undefined;
29
+ /**
30
+ * Store a completion in the cache
31
+ * @param key Cache key
32
+ * @param value Completion value to cache
33
+ */
34
+ put(key: string, value: monaco.languages.InlineCompletions | undefined): void;
35
+ /**
36
+ * Clear the entire cache
37
+ */
38
+ clear(): void;
39
+ /**
40
+ * Remove the least recently used entry from the cache
41
+ */
42
+ private removeLeastRecentlyUsed;
43
+ /**
44
+ * Set the maximum cache size
45
+ * @param size New maximum cache size
46
+ */
47
+ setMaxSize(size: number): void;
48
+ }
49
+ //# sourceMappingURL=code-completion-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-completion-cache.d.ts","sourceRoot":"","sources":["../../src/browser/code-completion-cache.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAEpD,qBACa,mBAAmB;IAC5B,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,OAAO,CAAO;;IAMtB;;;;;;;;OAQG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,GAAG,MAAM;IAiBjG;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IASzB;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS;IAUhE;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,GAAG,IAAI;IAY7E;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAgB/B;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAOjC"}