@theia/ai-code-completion 1.63.0-next.24 → 1.63.0-next.52
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/lib/browser/ai-code-completion-preference.d.ts +1 -0
- package/lib/browser/ai-code-completion-preference.d.ts.map +1 -1
- package/lib/browser/ai-code-completion-preference.js +10 -1
- package/lib/browser/ai-code-completion-preference.js.map +1 -1
- package/lib/browser/ai-code-frontend-application-contribution.d.ts +1 -0
- package/lib/browser/ai-code-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/ai-code-frontend-application-contribution.js +18 -2
- package/lib/browser/ai-code-frontend-application-contribution.js.map +1 -1
- package/lib/browser/code-completion-cache.d.ts +40 -0
- package/lib/browser/code-completion-cache.d.ts.map +1 -0
- package/lib/browser/code-completion-cache.js +116 -0
- package/lib/browser/code-completion-cache.js.map +1 -0
- package/lib/browser/code-completion-prompt-template.d.ts.map +1 -1
- package/lib/browser/code-completion-prompt-template.js +34 -0
- package/lib/browser/code-completion-prompt-template.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/ai-code-completion-preference.ts +10 -0
- package/src/browser/ai-code-frontend-application-contribution.ts +25 -3
- package/src/browser/code-completion-cache.ts +131 -0
- package/src/browser/code-completion-prompt-template.ts +34 -0
|
@@ -4,5 +4,6 @@ export declare const PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY = "ai-features.cod
|
|
|
4
4
|
export declare const PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = "ai-features.codeCompletion.excludedFileExtensions";
|
|
5
5
|
export declare const PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = "ai-features.codeCompletion.maxContextLines";
|
|
6
6
|
export declare const PREF_AI_INLINE_COMPLETION_STRIP_BACKTICKS = "ai-features.codeCompletion.stripBackticks";
|
|
7
|
+
export declare const PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY = "ai-features.codeCompletion.cacheCapacity";
|
|
7
8
|
export declare const AICodeCompletionPreferencesSchema: PreferenceSchema;
|
|
8
9
|
//# sourceMappingURL=ai-code-completion-preference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-code-completion-preference.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAI/F,eAAO,MAAM,0CAA0C,uDAAuD,CAAC;AAC/G,eAAO,MAAM,wCAAwC,6CAA6C,CAAC;AACnG,eAAO,MAAM,6CAA6C,sDAAsD,CAAC;AACjH,eAAO,MAAM,2CAA2C,+CAA+C,CAAC;AACxG,eAAO,MAAM,yCAAyC,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-code-completion-preference.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAI/F,eAAO,MAAM,0CAA0C,uDAAuD,CAAC;AAC/G,eAAO,MAAM,wCAAwC,6CAA6C,CAAC;AACnG,eAAO,MAAM,6CAA6C,sDAAsD,CAAC;AACjH,eAAO,MAAM,2CAA2C,+CAA+C,CAAC;AACxG,eAAO,MAAM,yCAAyC,8CAA8C,CAAC;AACrG,eAAO,MAAM,wCAAwC,6CAA6C,CAAC;AAEnG,eAAO,MAAM,iCAAiC,EAAE,gBAwD/C,CAAC"}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AICodeCompletionPreferencesSchema = exports.PREF_AI_INLINE_COMPLETION_STRIP_BACKTICKS = exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = exports.PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY = exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = void 0;
|
|
18
|
+
exports.AICodeCompletionPreferencesSchema = exports.PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY = exports.PREF_AI_INLINE_COMPLETION_STRIP_BACKTICKS = exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = exports.PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY = exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = void 0;
|
|
19
19
|
const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
|
|
20
20
|
const core_1 = require("@theia/core");
|
|
21
21
|
exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = 'ai-features.codeCompletion.automaticCodeCompletion';
|
|
@@ -23,6 +23,7 @@ exports.PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY = 'ai-features.codeCompletion.d
|
|
|
23
23
|
exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = 'ai-features.codeCompletion.excludedFileExtensions';
|
|
24
24
|
exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = 'ai-features.codeCompletion.maxContextLines';
|
|
25
25
|
exports.PREF_AI_INLINE_COMPLETION_STRIP_BACKTICKS = 'ai-features.codeCompletion.stripBackticks';
|
|
26
|
+
exports.PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY = 'ai-features.codeCompletion.cacheCapacity';
|
|
26
27
|
exports.AICodeCompletionPreferencesSchema = {
|
|
27
28
|
type: 'object',
|
|
28
29
|
properties: {
|
|
@@ -64,6 +65,14 @@ exports.AICodeCompletionPreferencesSchema = {
|
|
|
64
65
|
description: core_1.nls.localize('theia/ai/completion/stripBackticks/description', 'Remove surrounding backticks from the code returned by some LLMs. If a backtick is detected, all content after the closing\
|
|
65
66
|
backtick is stripped as well. This setting helps ensure plain code is returned when language models use markdown-like formatting.'),
|
|
66
67
|
default: true
|
|
68
|
+
},
|
|
69
|
+
[exports.PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY]: {
|
|
70
|
+
title: core_1.nls.localize('theia/ai/completion/cacheCapacity/title', 'Code Completion Cache Capacity'),
|
|
71
|
+
type: 'number',
|
|
72
|
+
description: core_1.nls.localize('theia/ai/completion/cacheCapacity/description', 'Maximum number of code completions to store in the cache. A higher number can improve performance but will consume more memory.\
|
|
73
|
+
Minimum value is 10, recommended range is between 50-200.'),
|
|
74
|
+
default: 100,
|
|
75
|
+
minimum: 10
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-code-completion-preference.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.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;;;AAGhF,wFAA2F;AAC3F,sCAAkC;AAErB,QAAA,0CAA0C,GAAG,oDAAoD,CAAC;AAClG,QAAA,wCAAwC,GAAG,0CAA0C,CAAC;AACtF,QAAA,6CAA6C,GAAG,mDAAmD,CAAC;AACpG,QAAA,2CAA2C,GAAG,4CAA4C,CAAC;AAC3F,QAAA,yCAAyC,GAAG,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-code-completion-preference.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4E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2C,EAAE,uBAAuB,CAAC;YACzF,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,UAAG,CAAC,QAAQ,CAAC,iDAAiD,EACvE;sHACsG,CAAC;YAC3G,OAAO,EAAE,CAAC,CAAC;YACX,OAAO,EAAE,CAAC,CAAC;SACd;QACD,CAAC,iDAAyC,CAAC,EAAE;YACzC,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,0CAA0C,EAAE,yCAAyC,CAAC;YAC1G,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,UAAG,CAAC,QAAQ,CAAC,gDAAgD,EACtE;+IAC+H,CAAC;YACpI,OAAO,EAAE,IAAI;SAChB;QACD,CAAC,gDAAwC,CAAC,EAAE;YACxC,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,yCAAyC,EAAE,gCAAgC,CAAC;YAChG,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,UAAG,CAAC,QAAQ,CAAC,+CAA+C,EACrE;0EAC0D,CAAC;YAC/D,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,EAAE;SACd;KACJ;CACJ,CAAC"}
|
|
@@ -5,6 +5,7 @@ export declare class AIFrontendApplicationContribution implements FrontendApplic
|
|
|
5
5
|
private inlineCodeCompletionProvider;
|
|
6
6
|
protected readonly preferenceService: PreferenceService;
|
|
7
7
|
protected readonly activationService: AIActivationService;
|
|
8
|
+
private completionCache;
|
|
8
9
|
private debouncer;
|
|
9
10
|
private debounceDelay;
|
|
10
11
|
private toDispose;
|
|
@@ -1 +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,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;
|
|
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,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAazI,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"}
|
|
@@ -26,8 +26,10 @@ const languages_1 = require("@theia/monaco-editor-core/esm/vs/editor/common/lang
|
|
|
26
26
|
const ai_code_completion_preference_1 = require("./ai-code-completion-preference");
|
|
27
27
|
const ai_code_inline_completion_provider_1 = require("./ai-code-inline-completion-provider");
|
|
28
28
|
const code_completion_debouncer_1 = require("./code-completion-debouncer");
|
|
29
|
+
const code_completion_cache_1 = require("./code-completion-cache");
|
|
29
30
|
let AIFrontendApplicationContribution = class AIFrontendApplicationContribution {
|
|
30
31
|
constructor() {
|
|
32
|
+
this.completionCache = new code_completion_cache_1.CodeCompletionCache();
|
|
31
33
|
this.debouncer = new code_completion_debouncer_1.InlineCompletionDebouncer();
|
|
32
34
|
this.toDispose = new Map();
|
|
33
35
|
}
|
|
@@ -40,6 +42,8 @@ let AIFrontendApplicationContribution = class AIFrontendApplicationContribution
|
|
|
40
42
|
const handler = () => this.handleInlineCompletions();
|
|
41
43
|
this.toDispose.set('inlineCompletions', handler());
|
|
42
44
|
this.debounceDelay = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY, 300);
|
|
45
|
+
const cacheCapacity = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY, 100);
|
|
46
|
+
this.completionCache.setMaxSize(cacheCapacity);
|
|
43
47
|
this.preferenceService.onPreferenceChanged(event => {
|
|
44
48
|
var _a;
|
|
45
49
|
if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE
|
|
@@ -50,6 +54,9 @@ let AIFrontendApplicationContribution = class AIFrontendApplicationContribution
|
|
|
50
54
|
if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY) {
|
|
51
55
|
this.debounceDelay = event.newValue;
|
|
52
56
|
}
|
|
57
|
+
if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY) {
|
|
58
|
+
this.completionCache.setMaxSize(event.newValue);
|
|
59
|
+
}
|
|
53
60
|
});
|
|
54
61
|
this.activationService.onDidChangeActiveStatus(change => {
|
|
55
62
|
var _a;
|
|
@@ -79,9 +86,18 @@ let AIFrontendApplicationContribution = class AIFrontendApplicationContribution
|
|
|
79
86
|
if (excludedExtensions.some(ext => fileName.endsWith(ext))) {
|
|
80
87
|
return { items: [] };
|
|
81
88
|
}
|
|
82
|
-
const completionHandler = () => {
|
|
89
|
+
const completionHandler = async () => {
|
|
83
90
|
try {
|
|
84
|
-
|
|
91
|
+
const cacheKey = this.completionCache.generateKey(fileName, model, position);
|
|
92
|
+
const cachedCompletion = this.completionCache.get(cacheKey);
|
|
93
|
+
if (cachedCompletion) {
|
|
94
|
+
return cachedCompletion;
|
|
95
|
+
}
|
|
96
|
+
const completion = await this.inlineCodeCompletionProvider.provideInlineCompletions(model, position, context, token);
|
|
97
|
+
if (completion && completion.items.length > 0) {
|
|
98
|
+
this.completionCache.put(cacheKey, completion);
|
|
99
|
+
}
|
|
100
|
+
return completion;
|
|
85
101
|
}
|
|
86
102
|
catch (error) {
|
|
87
103
|
console.error('Error providing inline completions:', error);
|
|
@@ -1 +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,sCAAyC;AACzC,qDAAyI;AACzI,4DAAkE;AAClE,wFAAuG;AACvG,
|
|
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,sCAAyC;AACzC,qDAAyI;AACzI,4DAAkE;AAClE,wFAAuG;AACvG,mFAKyC;AACzC,6FAAuF;AACvF,2EAAwE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AI,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,2BAAiB,CAAC;;4EAC8B;AAGrC;IADlB,IAAA,kBAAM,EAAC,6BAAmB,CAAC;sCACU,6BAAmB;4EAAC;4CARjD,iCAAiC;IAD7C,IAAA,sBAAU,GAAE;GACA,iCAAiC,CAsH7C"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 based on input parameters
|
|
8
|
+
* @param filePath Path of the current file
|
|
9
|
+
* @param lineNumber Current line number
|
|
10
|
+
* @param lineText Context prefix for completion
|
|
11
|
+
* @returns Unique cache key
|
|
12
|
+
*/
|
|
13
|
+
generateKey(filePath: string, model: monaco.editor.ITextModel, position: monaco.Position): string;
|
|
14
|
+
/**
|
|
15
|
+
* Get a cached completion if available
|
|
16
|
+
* @param key Cache key
|
|
17
|
+
* @returns Cached completion or undefined
|
|
18
|
+
*/
|
|
19
|
+
get(key: string): monaco.languages.InlineCompletions | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Store a completion in the cache
|
|
22
|
+
* @param key Cache key
|
|
23
|
+
* @param value Completion value to cache
|
|
24
|
+
*/
|
|
25
|
+
put(key: string, value: monaco.languages.InlineCompletions | undefined): void;
|
|
26
|
+
/**
|
|
27
|
+
* Clear the entire cache
|
|
28
|
+
*/
|
|
29
|
+
clear(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Remove the least recently used entry from the cache
|
|
32
|
+
*/
|
|
33
|
+
private removeLeastRecentlyUsed;
|
|
34
|
+
/**
|
|
35
|
+
* Set the maximum cache size
|
|
36
|
+
* @param size New maximum cache size
|
|
37
|
+
*/
|
|
38
|
+
setMaxSize(size: number): void;
|
|
39
|
+
}
|
|
40
|
+
//# 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;;;;;;OAMG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,GAAG,MAAM;IAqBjG;;;;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"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2025 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.CodeCompletionCache = void 0;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
+
const monaco = require("@theia/monaco-editor-core");
|
|
22
|
+
let CodeCompletionCache = class CodeCompletionCache {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.maxSize = 100;
|
|
25
|
+
this.cache = new Map();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generate a unique cache key based on input parameters
|
|
29
|
+
* @param filePath Path of the current file
|
|
30
|
+
* @param lineNumber Current line number
|
|
31
|
+
* @param lineText Context prefix for completion
|
|
32
|
+
* @returns Unique cache key
|
|
33
|
+
*/
|
|
34
|
+
generateKey(filePath, model, position) {
|
|
35
|
+
const lineNumber = position.lineNumber;
|
|
36
|
+
const beforeCursorLineRange = new monaco.Range(position.lineNumber, 1, position.lineNumber, position.column);
|
|
37
|
+
const prefix = model.getValueInRange(beforeCursorLineRange);
|
|
38
|
+
const afterCursorLineRange = new monaco.Range(position.lineNumber, position.column, position.lineNumber, model.getLineMaxColumn(position.lineNumber));
|
|
39
|
+
const suffix = model.getValueInRange(afterCursorLineRange);
|
|
40
|
+
const key = JSON.stringify({
|
|
41
|
+
filePath,
|
|
42
|
+
lineNumber,
|
|
43
|
+
prefix,
|
|
44
|
+
suffix
|
|
45
|
+
});
|
|
46
|
+
return key;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get a cached completion if available
|
|
50
|
+
* @param key Cache key
|
|
51
|
+
* @returns Cached completion or undefined
|
|
52
|
+
*/
|
|
53
|
+
get(key) {
|
|
54
|
+
const entry = this.cache.get(key);
|
|
55
|
+
if (entry) {
|
|
56
|
+
// Update the entry's last accessed time
|
|
57
|
+
entry.lastAccessed = Date.now();
|
|
58
|
+
return entry.value;
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Store a completion in the cache
|
|
64
|
+
* @param key Cache key
|
|
65
|
+
* @param value Completion value to cache
|
|
66
|
+
*/
|
|
67
|
+
put(key, value) {
|
|
68
|
+
// If cache is full, remove the least recently used entry
|
|
69
|
+
if (this.cache.size >= this.maxSize) {
|
|
70
|
+
this.removeLeastRecentlyUsed();
|
|
71
|
+
}
|
|
72
|
+
this.cache.set(key, {
|
|
73
|
+
value,
|
|
74
|
+
lastAccessed: Date.now()
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Clear the entire cache
|
|
79
|
+
*/
|
|
80
|
+
clear() {
|
|
81
|
+
this.cache.clear();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Remove the least recently used entry from the cache
|
|
85
|
+
*/
|
|
86
|
+
removeLeastRecentlyUsed() {
|
|
87
|
+
let oldestKey;
|
|
88
|
+
let oldestTime = Infinity;
|
|
89
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
90
|
+
if (entry.lastAccessed < oldestTime) {
|
|
91
|
+
oldestKey = key;
|
|
92
|
+
oldestTime = entry.lastAccessed;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (oldestKey) {
|
|
96
|
+
this.cache.delete(oldestKey);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Set the maximum cache size
|
|
101
|
+
* @param size New maximum cache size
|
|
102
|
+
*/
|
|
103
|
+
setMaxSize(size) {
|
|
104
|
+
this.maxSize = size;
|
|
105
|
+
// Trim cache if it exceeds new size
|
|
106
|
+
while (this.cache.size > this.maxSize) {
|
|
107
|
+
this.removeLeastRecentlyUsed();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
exports.CodeCompletionCache = CodeCompletionCache;
|
|
112
|
+
exports.CodeCompletionCache = CodeCompletionCache = tslib_1.__decorate([
|
|
113
|
+
(0, inversify_1.injectable)(),
|
|
114
|
+
tslib_1.__metadata("design:paramtypes", [])
|
|
115
|
+
], CodeCompletionCache);
|
|
116
|
+
//# sourceMappingURL=code-completion-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-completion-cache.js","sourceRoot":"","sources":["../../src/browser/code-completion-cache.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,4DAA0D;AAC1D,oDAAoD;AAG7C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAI5B;QAFQ,YAAO,GAAG,GAAG,CAAC;QAGlB,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC/C,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,QAAgB,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G,CAAC,GAAG,EAAE;YAChB,KAAK;YACL,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;SAC3B,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,KAAK;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACK,uBAAuB;QAC3B,IAAI,SAA6B,CAAC;QAClC,IAAI,UAAU,GAAG,QAAQ,CAAC;QAE1B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9C,IAAI,KAAK,CAAC,YAAY,GAAG,UAAU,EAAE,CAAC;gBAClC,SAAS,GAAG,GAAG,CAAC;gBAChB,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC;YACpC,CAAC;QACL,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,IAAY;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,oCAAoC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACnC,CAAC;IACL,CAAC;CACJ,CAAA;AAzGY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,GAAE;;GACA,mBAAmB,CAyG/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-completion-prompt-template.d.ts","sourceRoot":"","sources":["../../src/browser/code-completion-prompt-template.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,eAAO,MAAM,qBAAqB,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"code-completion-prompt-template.d.ts","sourceRoot":"","sources":["../../src/browser/code-completion-prompt-template.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,eAAO,MAAM,qBAAqB,EAAE,gBAAgB,EAkEnD,CAAC"}
|
|
@@ -26,6 +26,40 @@ Finish the following code snippet.
|
|
|
26
26
|
{{${code_completion_variables_1.PREFIX.id}}}[[MARKER]]{{${code_completion_variables_1.SUFFIX.id}}}
|
|
27
27
|
|
|
28
28
|
Only return the exact replacement for [[MARKER]] to complete the snippet.`
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'code-completion-prompt-next',
|
|
32
|
+
template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
|
|
33
|
+
Made improvements or adaptations to this prompt template? We'd love for you to share it with the community! Contribute back here:
|
|
34
|
+
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
35
|
+
# System Role
|
|
36
|
+
You are an expert AI code completion assistant focused on generating precise, contextually appropriate code snippets.
|
|
37
|
+
|
|
38
|
+
## Code Context
|
|
39
|
+
\`\`\`
|
|
40
|
+
{{${code_completion_variables_1.PREFIX.id}}}[[MARKER]]{{${code_completion_variables_1.SUFFIX.id}}}
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
## Metadata
|
|
44
|
+
- File: {{${code_completion_variables_1.FILE.id}}}
|
|
45
|
+
- Programming Language: {{${code_completion_variables_1.LANGUAGE.id}}}
|
|
46
|
+
- Project Context: {{prompt:project-info}}
|
|
47
|
+
|
|
48
|
+
# Completion Guidelines
|
|
49
|
+
1. Analyze the surrounding code context carefully.
|
|
50
|
+
2. Generate ONLY the code that should replace [[MARKER]].
|
|
51
|
+
3. Ensure the completion:
|
|
52
|
+
- Maintains the exact syntax of the surrounding code
|
|
53
|
+
- Follows best practices for the specific programming language
|
|
54
|
+
- Completes the code snippet logically and efficiently
|
|
55
|
+
4. Do NOT include any explanatory text, comments, or additional instructions.
|
|
56
|
+
5. Return ONLY the raw code replacement.
|
|
57
|
+
|
|
58
|
+
# Constraints
|
|
59
|
+
- Return strictly the code for [[MARKER]]
|
|
60
|
+
- Match indentation and style of surrounding code
|
|
61
|
+
- Prioritize readability and maintainability
|
|
62
|
+
- Consider language-specific idioms and patterns`
|
|
29
63
|
}],
|
|
30
64
|
defaultVariant: {
|
|
31
65
|
id: 'code-completion-prompt-default',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-completion-prompt-template.js","sourceRoot":"","sources":["../../src/browser/code-completion-prompt-template.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,+CAA+C;AAC/C,mEAAmE;AACnE,sCAAsC;AACtC,EAAE;AACF,+BAA+B;AAC/B,gFAAgF;;;AAGhF,2EAA6E;AAEhE,QAAA,qBAAqB,GAAuB,CAAC;QACtD,EAAE,EAAE,wBAAwB;QAC5B,QAAQ,EAAE,CAAC;gBACP,EAAE,EAAE,iCAAiC;gBACrC,QAAQ,EAAE;;;oFAGkE,gCAAI,CAAC,EAAE;gCAC3D,oCAAQ,CAAC,EAAE;;;IAGvC,kCAAM,CAAC,EAAE,iBAAiB,kCAAM,CAAC,EAAE;;0EAEmC;aACrE,CAAC;QACF,cAAc,EAAE;YACZ,EAAE,EAAE,gCAAgC;YACpC,QAAQ,EAAE;;;;;IAKd,kCAAM,CAAC,EAAE,iBAAiB,kCAAM,CAAC,EAAE;;;;YAI3B,gCAAI,CAAC,EAAE;gBACH,oCAAQ,CAAC,EAAE;;8HAEmG;SACzH;KACJ;CACA,CAAC"}
|
|
1
|
+
{"version":3,"file":"code-completion-prompt-template.js","sourceRoot":"","sources":["../../src/browser/code-completion-prompt-template.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,+CAA+C;AAC/C,mEAAmE;AACnE,sCAAsC;AACtC,EAAE;AACF,+BAA+B;AAC/B,gFAAgF;;;AAGhF,2EAA6E;AAEhE,QAAA,qBAAqB,GAAuB,CAAC;QACtD,EAAE,EAAE,wBAAwB;QAC5B,QAAQ,EAAE,CAAC;gBACP,EAAE,EAAE,iCAAiC;gBACrC,QAAQ,EAAE;;;oFAGkE,gCAAI,CAAC,EAAE;gCAC3D,oCAAQ,CAAC,EAAE;;;IAGvC,kCAAM,CAAC,EAAE,iBAAiB,kCAAM,CAAC,EAAE;;0EAEmC;aACrE;YACD;gBACI,EAAE,EAAE,6BAA6B;gBACjC,QAAQ,EAAE;;;;;;;;IAQd,kCAAM,CAAC,EAAE,iBAAiB,kCAAM,CAAC,EAAE;;;;YAI3B,gCAAI,CAAC,EAAE;4BACS,oCAAQ,CAAC,EAAE;;;;;;;;;;;;;;;;;iDAiBU;aAC5C,CAAC;QACF,cAAc,EAAE;YACZ,EAAE,EAAE,gCAAgC;YACpC,QAAQ,EAAE;;;;;IAKd,kCAAM,CAAC,EAAE,iBAAiB,kCAAM,CAAC,EAAE;;;;YAI3B,gCAAI,CAAC,EAAE;gBACH,oCAAQ,CAAC,EAAE;;8HAEmG;SACzH;KACJ;CACA,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ai-code-completion",
|
|
3
|
-
"version": "1.63.0-next.
|
|
3
|
+
"version": "1.63.0-next.52+176018e53",
|
|
4
4
|
"description": "Theia - AI Core",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/ai-core": "1.63.0-next.
|
|
7
|
-
"@theia/core": "1.63.0-next.
|
|
8
|
-
"@theia/filesystem": "1.63.0-next.
|
|
6
|
+
"@theia/ai-core": "1.63.0-next.52+176018e53",
|
|
7
|
+
"@theia/core": "1.63.0-next.52+176018e53",
|
|
8
|
+
"@theia/filesystem": "1.63.0-next.52+176018e53",
|
|
9
9
|
"@theia/monaco-editor-core": "1.96.302",
|
|
10
|
-
"@theia/output": "1.63.0-next.
|
|
11
|
-
"@theia/workspace": "1.63.0-next.
|
|
10
|
+
"@theia/output": "1.63.0-next.52+176018e53",
|
|
11
|
+
"@theia/workspace": "1.63.0-next.52+176018e53",
|
|
12
12
|
"minimatch": "^5.1.0",
|
|
13
13
|
"tslib": "^2.6.2"
|
|
14
14
|
},
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"nyc": {
|
|
52
52
|
"extends": "../../configs/nyc.json"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "176018e53e62cafec9b25b23ac9f0b4826b6d0f7"
|
|
55
55
|
}
|
|
@@ -23,6 +23,7 @@ export const PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY = 'ai-features.codeComplet
|
|
|
23
23
|
export const PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = 'ai-features.codeCompletion.excludedFileExtensions';
|
|
24
24
|
export const PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = 'ai-features.codeCompletion.maxContextLines';
|
|
25
25
|
export const PREF_AI_INLINE_COMPLETION_STRIP_BACKTICKS = 'ai-features.codeCompletion.stripBackticks';
|
|
26
|
+
export const PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY = 'ai-features.codeCompletion.cacheCapacity';
|
|
26
27
|
|
|
27
28
|
export const AICodeCompletionPreferencesSchema: PreferenceSchema = {
|
|
28
29
|
type: 'object',
|
|
@@ -69,6 +70,15 @@ export const AICodeCompletionPreferencesSchema: PreferenceSchema = {
|
|
|
69
70
|
'Remove surrounding backticks from the code returned by some LLMs. If a backtick is detected, all content after the closing\
|
|
70
71
|
backtick is stripped as well. This setting helps ensure plain code is returned when language models use markdown-like formatting.'),
|
|
71
72
|
default: true
|
|
73
|
+
},
|
|
74
|
+
[PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY]: {
|
|
75
|
+
title: nls.localize('theia/ai/completion/cacheCapacity/title', 'Code Completion Cache Capacity'),
|
|
76
|
+
type: 'number',
|
|
77
|
+
description: nls.localize('theia/ai/completion/cacheCapacity/description',
|
|
78
|
+
'Maximum number of code completions to store in the cache. A higher number can improve performance but will consume more memory.\
|
|
79
|
+
Minimum value is 10, recommended range is between 50-200.'),
|
|
80
|
+
default: 100,
|
|
81
|
+
minimum: 10
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
84
|
};
|
|
@@ -24,10 +24,12 @@ import { InlineCompletionTriggerKind } from '@theia/monaco-editor-core/esm/vs/ed
|
|
|
24
24
|
import {
|
|
25
25
|
PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE,
|
|
26
26
|
PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY,
|
|
27
|
-
PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS
|
|
27
|
+
PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS,
|
|
28
|
+
PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY
|
|
28
29
|
} from './ai-code-completion-preference';
|
|
29
30
|
import { AICodeInlineCompletionsProvider } from './ai-code-inline-completion-provider';
|
|
30
31
|
import { InlineCompletionDebouncer } from './code-completion-debouncer';
|
|
32
|
+
import { CodeCompletionCache } from './code-completion-cache';
|
|
31
33
|
|
|
32
34
|
@injectable()
|
|
33
35
|
export class AIFrontendApplicationContribution implements FrontendApplicationContribution, KeybindingContribution {
|
|
@@ -40,6 +42,7 @@ export class AIFrontendApplicationContribution implements FrontendApplicationCon
|
|
|
40
42
|
@inject(AIActivationService)
|
|
41
43
|
protected readonly activationService: AIActivationService;
|
|
42
44
|
|
|
45
|
+
private completionCache = new CodeCompletionCache();
|
|
43
46
|
private debouncer = new InlineCompletionDebouncer();
|
|
44
47
|
private debounceDelay: number;
|
|
45
48
|
|
|
@@ -58,6 +61,9 @@ export class AIFrontendApplicationContribution implements FrontendApplicationCon
|
|
|
58
61
|
|
|
59
62
|
this.debounceDelay = this.preferenceService.get<number>(PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY, 300);
|
|
60
63
|
|
|
64
|
+
const cacheCapacity = this.preferenceService.get<number>(PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY, 100);
|
|
65
|
+
this.completionCache.setMaxSize(cacheCapacity);
|
|
66
|
+
|
|
61
67
|
this.preferenceService.onPreferenceChanged(event => {
|
|
62
68
|
if (event.preferenceName === PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE
|
|
63
69
|
|| event.preferenceName === PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
|
|
@@ -67,6 +73,9 @@ export class AIFrontendApplicationContribution implements FrontendApplicationCon
|
|
|
67
73
|
if (event.preferenceName === PREF_AI_INLINE_COMPLETION_DEBOUNCE_DELAY) {
|
|
68
74
|
this.debounceDelay = event.newValue;
|
|
69
75
|
}
|
|
76
|
+
if (event.preferenceName === PREF_AI_INLINE_COMPLETION_CACHE_CAPACITY) {
|
|
77
|
+
this.completionCache.setMaxSize(event.newValue);
|
|
78
|
+
}
|
|
70
79
|
});
|
|
71
80
|
|
|
72
81
|
this.activationService.onDidChangeActiveStatus(change => {
|
|
@@ -102,14 +111,27 @@ export class AIFrontendApplicationContribution implements FrontendApplicationCon
|
|
|
102
111
|
return { items: [] };
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
const completionHandler = () => {
|
|
114
|
+
const completionHandler = async () => {
|
|
106
115
|
try {
|
|
107
|
-
|
|
116
|
+
const cacheKey = this.completionCache.generateKey(fileName, model, position);
|
|
117
|
+
const cachedCompletion = this.completionCache.get(cacheKey);
|
|
118
|
+
|
|
119
|
+
if (cachedCompletion) {
|
|
120
|
+
return cachedCompletion;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const completion = await this.inlineCodeCompletionProvider.provideInlineCompletions(
|
|
108
124
|
model,
|
|
109
125
|
position,
|
|
110
126
|
context,
|
|
111
127
|
token
|
|
112
128
|
);
|
|
129
|
+
|
|
130
|
+
if (completion && completion.items.length > 0) {
|
|
131
|
+
this.completionCache.put(cacheKey, completion);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return completion;
|
|
113
135
|
} catch (error) {
|
|
114
136
|
console.error('Error providing inline completions:', error);
|
|
115
137
|
return { items: [] };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2025 EclipseSource GmbH.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
19
|
+
|
|
20
|
+
@injectable()
|
|
21
|
+
export class CodeCompletionCache {
|
|
22
|
+
private cache: Map<string, CacheEntry>;
|
|
23
|
+
private maxSize = 100;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
this.cache = new Map<string, CacheEntry>();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generate a unique cache key based on input parameters
|
|
31
|
+
* @param filePath Path of the current file
|
|
32
|
+
* @param lineNumber Current line number
|
|
33
|
+
* @param lineText Context prefix for completion
|
|
34
|
+
* @returns Unique cache key
|
|
35
|
+
*/
|
|
36
|
+
generateKey(filePath: string, model: monaco.editor.ITextModel, position: monaco.Position): string {
|
|
37
|
+
const lineNumber = position.lineNumber;
|
|
38
|
+
const beforeCursorLineRange = new monaco.Range(
|
|
39
|
+
position.lineNumber, 1,
|
|
40
|
+
position.lineNumber, position.column
|
|
41
|
+
);
|
|
42
|
+
const prefix = model.getValueInRange(beforeCursorLineRange);
|
|
43
|
+
const afterCursorLineRange = new monaco.Range(
|
|
44
|
+
position.lineNumber, position.column,
|
|
45
|
+
position.lineNumber, model.getLineMaxColumn(position.lineNumber)
|
|
46
|
+
);
|
|
47
|
+
const suffix = model.getValueInRange(afterCursorLineRange);
|
|
48
|
+
const key = JSON.stringify({
|
|
49
|
+
filePath,
|
|
50
|
+
lineNumber,
|
|
51
|
+
prefix,
|
|
52
|
+
suffix
|
|
53
|
+
});
|
|
54
|
+
return key;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get a cached completion if available
|
|
59
|
+
* @param key Cache key
|
|
60
|
+
* @returns Cached completion or undefined
|
|
61
|
+
*/
|
|
62
|
+
get(key: string): monaco.languages.InlineCompletions | undefined {
|
|
63
|
+
const entry = this.cache.get(key);
|
|
64
|
+
if (entry) {
|
|
65
|
+
// Update the entry's last accessed time
|
|
66
|
+
entry.lastAccessed = Date.now();
|
|
67
|
+
return entry.value;
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Store a completion in the cache
|
|
74
|
+
* @param key Cache key
|
|
75
|
+
* @param value Completion value to cache
|
|
76
|
+
*/
|
|
77
|
+
put(key: string, value: monaco.languages.InlineCompletions | undefined): void {
|
|
78
|
+
// If cache is full, remove the least recently used entry
|
|
79
|
+
if (this.cache.size >= this.maxSize) {
|
|
80
|
+
this.removeLeastRecentlyUsed();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.cache.set(key, {
|
|
84
|
+
value,
|
|
85
|
+
lastAccessed: Date.now()
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Clear the entire cache
|
|
91
|
+
*/
|
|
92
|
+
clear(): void {
|
|
93
|
+
this.cache.clear();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Remove the least recently used entry from the cache
|
|
98
|
+
*/
|
|
99
|
+
private removeLeastRecentlyUsed(): void {
|
|
100
|
+
let oldestKey: string | undefined;
|
|
101
|
+
let oldestTime = Infinity;
|
|
102
|
+
|
|
103
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
104
|
+
if (entry.lastAccessed < oldestTime) {
|
|
105
|
+
oldestKey = key;
|
|
106
|
+
oldestTime = entry.lastAccessed;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (oldestKey) {
|
|
111
|
+
this.cache.delete(oldestKey);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Set the maximum cache size
|
|
117
|
+
* @param size New maximum cache size
|
|
118
|
+
*/
|
|
119
|
+
setMaxSize(size: number): void {
|
|
120
|
+
this.maxSize = size;
|
|
121
|
+
// Trim cache if it exceeds new size
|
|
122
|
+
while (this.cache.size > this.maxSize) {
|
|
123
|
+
this.removeLeastRecentlyUsed();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
interface CacheEntry {
|
|
129
|
+
value: monaco.languages.InlineCompletions | undefined;
|
|
130
|
+
lastAccessed: number;
|
|
131
|
+
}
|
|
@@ -26,6 +26,40 @@ Finish the following code snippet.
|
|
|
26
26
|
{{${PREFIX.id}}}[[MARKER]]{{${SUFFIX.id}}}
|
|
27
27
|
|
|
28
28
|
Only return the exact replacement for [[MARKER]] to complete the snippet.`
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'code-completion-prompt-next',
|
|
32
|
+
template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
|
|
33
|
+
Made improvements or adaptations to this prompt template? We'd love for you to share it with the community! Contribute back here:
|
|
34
|
+
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
35
|
+
# System Role
|
|
36
|
+
You are an expert AI code completion assistant focused on generating precise, contextually appropriate code snippets.
|
|
37
|
+
|
|
38
|
+
## Code Context
|
|
39
|
+
\`\`\`
|
|
40
|
+
{{${PREFIX.id}}}[[MARKER]]{{${SUFFIX.id}}}
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
## Metadata
|
|
44
|
+
- File: {{${FILE.id}}}
|
|
45
|
+
- Programming Language: {{${LANGUAGE.id}}}
|
|
46
|
+
- Project Context: {{prompt:project-info}}
|
|
47
|
+
|
|
48
|
+
# Completion Guidelines
|
|
49
|
+
1. Analyze the surrounding code context carefully.
|
|
50
|
+
2. Generate ONLY the code that should replace [[MARKER]].
|
|
51
|
+
3. Ensure the completion:
|
|
52
|
+
- Maintains the exact syntax of the surrounding code
|
|
53
|
+
- Follows best practices for the specific programming language
|
|
54
|
+
- Completes the code snippet logically and efficiently
|
|
55
|
+
4. Do NOT include any explanatory text, comments, or additional instructions.
|
|
56
|
+
5. Return ONLY the raw code replacement.
|
|
57
|
+
|
|
58
|
+
# Constraints
|
|
59
|
+
- Return strictly the code for [[MARKER]]
|
|
60
|
+
- Match indentation and style of surrounding code
|
|
61
|
+
- Prioritize readability and maintainability
|
|
62
|
+
- Consider language-specific idioms and patterns`
|
|
29
63
|
}],
|
|
30
64
|
defaultVariant: {
|
|
31
65
|
id: 'code-completion-prompt-default',
|