@theia/ai-code-completion 1.63.0-next.24 → 1.63.0

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.
@@ -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;AAErG,eAAO,MAAM,iCAAiC,EAAE,gBA+C/C,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,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C;YAC1G,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,UAAG,CAAC,QAAQ,CAAC,gDAAgD,EACtE;+IAC+H,CAAC;YACpI,OAAO,EAAE,IAAI;SAChB;KACJ;CACJ,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,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;AACxF,QAAA,wCAAwC,GAAG,0CAA0C,CAAC;AAEtF,QAAA,iCAAiC,GAAqB;IAC/D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,kDAA0C,CAAC,EAAE;YAC1C,KAAK,EAAE,+CAAyB;YAChC,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,UAAG,CAAC,QAAQ,CAAC,iDAAiD,EACvE;;mJAEmI,CAAC;YACxI,OAAO,EAAE,KAAK;SACjB;QACD,CAAC,gDAAwC,CAAC,EAAE;YACxC,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,yCAAyC,EAAE,gBAAgB,CAAC;YAChF,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,UAAG,CAAC,QAAQ,CAAC,+CAA+C,EACrE;2GAC2F,CAAC;YAChG,OAAO,EAAE,GAAG;SACf;QACD,CAAC,qDAA6C,CAAC,EAAE;YAC7C,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,4CAA4C,EAAE,0BAA0B,CAAC;YAC7F,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,UAAG,CAAC,QAAQ,CAAC,kDAAkD,EAAE,oFAAoF,CAAC;YACnK,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;aACjB;YACD,OAAO,EAAE,EAAE;SACd;QACD,CAAC,mDAA2C,CAAC,EAAE;YAC3C,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,2CAA2C,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;AAWzI,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,SAAS,CAAmC;IACpD,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,SAAS,CAAiC;IAElD,qBAAqB,IAAI,IAAI;IAM7B,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAwBnC,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI;IAQ1D,SAAS,CAAC,uBAAuB,IAAI,UAAU;CA6ClD"}
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
- return this.inlineCodeCompletionProvider.provideInlineCompletions(model, position, context, token);
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,mFAIyC;AACzC,6FAA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,EAAE;oBAC3B,IAAI,CAAC;wBACD,OAAO,IAAI,CAAC,4BAA4B,CAAC,wBAAwB,CAC7D,KAAK,EACL,QAAQ,EACR,OAAO,EACP,KAAK,CACR,CAAC;oBACN,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;AAlGY,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,CAkG7C"}
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,2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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,2BAAiB,CAAC;;4EAC8B;AAGrC;IADlB,IAAA,kBAAM,EAAC,6BAAmB,CAAC;sCACU,6BAAmB;4EAAC;4CARjD,iCAAiC;IAD7C,IAAA,sBAAU,GAAE;GACA,iCAAiC,CAsH7C"}
@@ -61,7 +61,7 @@ let CodeCompletionAgentImpl = class CodeCompletionAgentImpl {
61
61
  return undefined;
62
62
  }
63
63
  const prompt = await this.promptService
64
- .getResolvedPromptFragment('code-completion-prompt', undefined, variableContext)
64
+ .getResolvedPromptFragment('code-completion-system', undefined, variableContext)
65
65
  .then(p => p === null || p === void 0 ? void 0 : p.text);
66
66
  if (!prompt) {
67
67
  this.logger.error('No prompt found for code-completion-agent');
@@ -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"}
@@ -0,0 +1,135 @@
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
+ var CodeCompletionCache_1;
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.CodeCompletionCache = void 0;
20
+ const tslib_1 = require("tslib");
21
+ const inversify_1 = require("@theia/core/shared/inversify");
22
+ const monaco = require("@theia/monaco-editor-core");
23
+ let CodeCompletionCache = CodeCompletionCache_1 = class CodeCompletionCache {
24
+ constructor() {
25
+ this.maxSize = 100;
26
+ this.cache = new Map();
27
+ }
28
+ /**
29
+ * Generate a unique cache key for code completion based on the file path, cursor position, and the hashed context (prefix and suffix).
30
+ * The prefix and suffix are hashed to avoid storing large or sensitive content directly in the cache key.
31
+ *
32
+ * @param filePath Path of the current file
33
+ * @param model Monaco text model of the file
34
+ * @param position Current cursor position in the editor
35
+ * @returns Unique cache key as a string
36
+ */
37
+ generateKey(filePath, model, position) {
38
+ const lineNumber = position.lineNumber;
39
+ const prefixRange = new monaco.Range(1, 1, position.lineNumber, position.column);
40
+ const prefix = model.getValueInRange(prefixRange);
41
+ const lastLine = model.getLineCount();
42
+ const lastColumn = model.getLineMaxColumn(lastLine);
43
+ const suffixRange = new monaco.Range(position.lineNumber, position.column, lastLine, lastColumn);
44
+ const suffix = model.getValueInRange(suffixRange);
45
+ const key = JSON.stringify({
46
+ filePath,
47
+ lineNumber,
48
+ prefixHash: CodeCompletionCache_1.hashString(prefix),
49
+ suffixHash: CodeCompletionCache_1.hashString(suffix)
50
+ });
51
+ return key;
52
+ }
53
+ /**
54
+ * Hash a string using a simple hash algorithm (FNV-1a 32-bit).
55
+ * This is not cryptographically secure but is sufficient for cache key uniqueness.
56
+ * @param str The string to hash
57
+ * @returns The hash as a hex string
58
+ */
59
+ static hashString(str) {
60
+ let hash = 0x811c9dc5;
61
+ for (let i = 0; i < str.length; i++) {
62
+ hash ^= str.charCodeAt(i);
63
+ hash = (hash * 0x01000193) >>> 0;
64
+ }
65
+ return hash.toString(16);
66
+ }
67
+ /**
68
+ * Get a cached completion if available
69
+ * @param key Cache key
70
+ * @returns Cached completion or undefined
71
+ */
72
+ get(key) {
73
+ const entry = this.cache.get(key);
74
+ if (entry) {
75
+ // Update the entry's last accessed time
76
+ entry.lastAccessed = Date.now();
77
+ return entry.value;
78
+ }
79
+ return undefined;
80
+ }
81
+ /**
82
+ * Store a completion in the cache
83
+ * @param key Cache key
84
+ * @param value Completion value to cache
85
+ */
86
+ put(key, value) {
87
+ // If cache is full, remove the least recently used entry
88
+ if (this.cache.size >= this.maxSize) {
89
+ this.removeLeastRecentlyUsed();
90
+ }
91
+ this.cache.set(key, {
92
+ value,
93
+ lastAccessed: Date.now()
94
+ });
95
+ }
96
+ /**
97
+ * Clear the entire cache
98
+ */
99
+ clear() {
100
+ this.cache.clear();
101
+ }
102
+ /**
103
+ * Remove the least recently used entry from the cache
104
+ */
105
+ removeLeastRecentlyUsed() {
106
+ let oldestKey;
107
+ let oldestTime = Infinity;
108
+ for (const [key, entry] of this.cache.entries()) {
109
+ if (entry.lastAccessed < oldestTime) {
110
+ oldestKey = key;
111
+ oldestTime = entry.lastAccessed;
112
+ }
113
+ }
114
+ if (oldestKey) {
115
+ this.cache.delete(oldestKey);
116
+ }
117
+ }
118
+ /**
119
+ * Set the maximum cache size
120
+ * @param size New maximum cache size
121
+ */
122
+ setMaxSize(size) {
123
+ this.maxSize = size;
124
+ // Trim cache if it exceeds new size
125
+ while (this.cache.size > this.maxSize) {
126
+ this.removeLeastRecentlyUsed();
127
+ }
128
+ }
129
+ };
130
+ exports.CodeCompletionCache = CodeCompletionCache;
131
+ exports.CodeCompletionCache = CodeCompletionCache = CodeCompletionCache_1 = tslib_1.__decorate([
132
+ (0, inversify_1.injectable)(),
133
+ tslib_1.__metadata("design:paramtypes", [])
134
+ ], CodeCompletionCache);
135
+ //# 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,2BAAzB,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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;AAtHY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,GAAE;;GACA,mBAAmB,CAsH/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,EAgCnD,CAAC"}
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"}
@@ -13,9 +13,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.codeCompletionPrompts = void 0;
14
14
  const code_completion_variables_1 = require("./code-completion-variables");
15
15
  exports.codeCompletionPrompts = [{
16
- id: 'code-completion-prompt',
16
+ id: 'code-completion-system',
17
17
  variants: [{
18
- id: 'code-completion-prompt-previous',
18
+ id: 'code-completion-system-previous',
19
19
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
20
20
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
21
21
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
@@ -26,9 +26,43 @@ 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-system-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
- id: 'code-completion-prompt-default',
65
+ id: 'code-completion-system-default',
32
66
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
33
67
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
34
68
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
@@ -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.24+83b50cc66",
3
+ "version": "1.63.0",
4
4
  "description": "Theia - AI Core",
5
5
  "dependencies": {
6
- "@theia/ai-core": "1.63.0-next.24+83b50cc66",
7
- "@theia/core": "1.63.0-next.24+83b50cc66",
8
- "@theia/filesystem": "1.63.0-next.24+83b50cc66",
6
+ "@theia/ai-core": "1.63.0",
7
+ "@theia/core": "1.63.0",
8
+ "@theia/filesystem": "1.63.0",
9
9
  "@theia/monaco-editor-core": "1.96.302",
10
- "@theia/output": "1.63.0-next.24+83b50cc66",
11
- "@theia/workspace": "1.63.0-next.24+83b50cc66",
10
+ "@theia/output": "1.63.0",
11
+ "@theia/workspace": "1.63.0",
12
12
  "minimatch": "^5.1.0",
13
13
  "tslib": "^2.6.2"
14
14
  },
@@ -46,10 +46,10 @@
46
46
  "watch": "theiaext watch"
47
47
  },
48
48
  "devDependencies": {
49
- "@theia/ext-scripts": "1.62.0"
49
+ "@theia/ext-scripts": "1.63.0"
50
50
  },
51
51
  "nyc": {
52
52
  "extends": "../../configs/nyc.json"
53
53
  },
54
- "gitHead": "83b50cc66b001a5b9100ccd944dcace04cd4ae2e"
54
+ "gitHead": "facf442522991134333495a0b90cf56a56990280"
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
- return this.inlineCodeCompletionProvider.provideInlineCompletions(
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: [] };
@@ -71,7 +71,7 @@ export class CodeCompletionAgentImpl implements CodeCompletionAgent {
71
71
  return undefined;
72
72
  }
73
73
  const prompt = await this.promptService
74
- .getResolvedPromptFragment('code-completion-prompt', undefined, variableContext)
74
+ .getResolvedPromptFragment('code-completion-system', undefined, variableContext)
75
75
  .then(p => p?.text);
76
76
  if (!prompt) {
77
77
  this.logger.error('No prompt found for code-completion-agent');
@@ -0,0 +1,144 @@
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 for code completion based on the file path, cursor position, and the hashed context (prefix and suffix).
31
+ * The prefix and suffix are hashed to avoid storing large or sensitive content directly in the cache key.
32
+ *
33
+ * @param filePath Path of the current file
34
+ * @param model Monaco text model of the file
35
+ * @param position Current cursor position in the editor
36
+ * @returns Unique cache key as a string
37
+ */
38
+ generateKey(filePath: string, model: monaco.editor.ITextModel, position: monaco.Position): string {
39
+ const lineNumber = position.lineNumber;
40
+ const prefixRange = new monaco.Range(1, 1, position.lineNumber, position.column);
41
+ const prefix = model.getValueInRange(prefixRange);
42
+ const lastLine = model.getLineCount();
43
+ const lastColumn = model.getLineMaxColumn(lastLine);
44
+ const suffixRange = new monaco.Range(position.lineNumber, position.column, lastLine, lastColumn);
45
+ const suffix = model.getValueInRange(suffixRange);
46
+ const key = JSON.stringify({
47
+ filePath,
48
+ lineNumber,
49
+ prefixHash: CodeCompletionCache.hashString(prefix),
50
+ suffixHash: CodeCompletionCache.hashString(suffix)
51
+ });
52
+ return key;
53
+ }
54
+
55
+ /**
56
+ * Hash a string using a simple hash algorithm (FNV-1a 32-bit).
57
+ * This is not cryptographically secure but is sufficient for cache key uniqueness.
58
+ * @param str The string to hash
59
+ * @returns The hash as a hex string
60
+ */
61
+ private static hashString(str: string): string {
62
+ let hash = 0x811c9dc5;
63
+ for (let i = 0; i < str.length; i++) {
64
+ hash ^= str.charCodeAt(i);
65
+ hash = (hash * 0x01000193) >>> 0;
66
+ }
67
+ return hash.toString(16);
68
+ }
69
+
70
+ /**
71
+ * Get a cached completion if available
72
+ * @param key Cache key
73
+ * @returns Cached completion or undefined
74
+ */
75
+ get(key: string): monaco.languages.InlineCompletions | undefined {
76
+ const entry = this.cache.get(key);
77
+ if (entry) {
78
+ // Update the entry's last accessed time
79
+ entry.lastAccessed = Date.now();
80
+ return entry.value;
81
+ }
82
+ return undefined;
83
+ }
84
+
85
+ /**
86
+ * Store a completion in the cache
87
+ * @param key Cache key
88
+ * @param value Completion value to cache
89
+ */
90
+ put(key: string, value: monaco.languages.InlineCompletions | undefined): void {
91
+ // If cache is full, remove the least recently used entry
92
+ if (this.cache.size >= this.maxSize) {
93
+ this.removeLeastRecentlyUsed();
94
+ }
95
+
96
+ this.cache.set(key, {
97
+ value,
98
+ lastAccessed: Date.now()
99
+ });
100
+ }
101
+
102
+ /**
103
+ * Clear the entire cache
104
+ */
105
+ clear(): void {
106
+ this.cache.clear();
107
+ }
108
+
109
+ /**
110
+ * Remove the least recently used entry from the cache
111
+ */
112
+ private removeLeastRecentlyUsed(): void {
113
+ let oldestKey: string | undefined;
114
+ let oldestTime = Infinity;
115
+
116
+ for (const [key, entry] of this.cache.entries()) {
117
+ if (entry.lastAccessed < oldestTime) {
118
+ oldestKey = key;
119
+ oldestTime = entry.lastAccessed;
120
+ }
121
+ }
122
+
123
+ if (oldestKey) {
124
+ this.cache.delete(oldestKey);
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Set the maximum cache size
130
+ * @param size New maximum cache size
131
+ */
132
+ setMaxSize(size: number): void {
133
+ this.maxSize = size;
134
+ // Trim cache if it exceeds new size
135
+ while (this.cache.size > this.maxSize) {
136
+ this.removeLeastRecentlyUsed();
137
+ }
138
+ }
139
+ }
140
+
141
+ interface CacheEntry {
142
+ value: monaco.languages.InlineCompletions | undefined;
143
+ lastAccessed: number;
144
+ }
@@ -13,9 +13,9 @@ import { PromptVariantSet } from '@theia/ai-core/lib/common';
13
13
  import { FILE, LANGUAGE, PREFIX, SUFFIX } from './code-completion-variables';
14
14
 
15
15
  export const codeCompletionPrompts: PromptVariantSet[] = [{
16
- id: 'code-completion-prompt',
16
+ id: 'code-completion-system',
17
17
  variants: [{
18
- id: 'code-completion-prompt-previous',
18
+ id: 'code-completion-system-previous',
19
19
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
20
20
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
21
21
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
@@ -26,9 +26,43 @@ 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-system-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
- id: 'code-completion-prompt-default',
65
+ id: 'code-completion-system-default',
32
66
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
33
67
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
34
68
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}