MCPcopy Index your code
hub / github.com/Exafunction/codeium-chrome / renderCompletion

Method renderCompletion

src/codemirror.ts:189–272  ·  view source on GitHub ↗
(
    doc: CodeMirror.Doc,
    completionItem: CompletionItem,
    additionalUtf8ByteOffset: number,
    apiKey: string,
    createDisposables: () => IDisposable[]
  )

Source from the content-addressed store, hash-verified

187 }
188
189 renderCompletion(
190 doc: CodeMirror.Doc,
191 completionItem: CompletionItem,
192 additionalUtf8ByteOffset: number,
193 apiKey: string,
194 createDisposables: () => IDisposable[]
195 ): void {
196 this.clearCompletion('about to render new completions');
197 const startOffsetUtf8Bytes =
198 Number(completionItem.range?.startOffset ?? 0) - additionalUtf8ByteOffset;
199 const endOffsetUtf8Bytes =
200 Number(completionItem.range?.endOffset ?? 0) - additionalUtf8ByteOffset;
201 const currentCompletion: typeof this.currentCompletion = {
202 completionItem,
203 lineWidgets: [],
204 textMarkers: [],
205 disposables: createDisposables(),
206 doc,
207 start: doc.posFromIndex(numUtf8BytesToNumCodeUnits(doc.getValue(), startOffsetUtf8Bytes)),
208 end: doc.posFromIndex(numUtf8BytesToNumCodeUnits(doc.getValue(), endOffsetUtf8Bytes)),
209 apiKey,
210 docState: doc.getValue(),
211 };
212 const cursor = doc.getCursor();
213 let createdInlineAtCursor = false;
214 completionItem.completionParts.forEach((part) => {
215 if (part.type === CompletionPartType.INLINE) {
216 const bookmarkElement = document.createElement('span');
217 bookmarkElement.classList.add('codeium-ghost');
218 bookmarkElement.innerText = part.text;
219 const partOffsetBytes = Number(part.offset) - additionalUtf8ByteOffset;
220 const partOffset = numUtf8BytesToNumCodeUnits(doc.getValue(), partOffsetBytes);
221 const pos = doc.posFromIndex(partOffset);
222 const bookmarkWidget = doc.setBookmark(pos, {
223 widget: bookmarkElement,
224 insertLeft: true,
225 // We need all widgets to have handleMouseEvents true for the glitches
226 // where the completion doesn't disappear.
227 handleMouseEvents: true,
228 });
229 currentCompletion.textMarkers.push({
230 marker: bookmarkWidget,
231 pos,
232 spanElement: bookmarkElement,
233 });
234 if (pos.line === cursor.line && pos.ch === cursor.ch) {
235 createdInlineAtCursor = true;
236 }
237 } else if (part.type === CompletionPartType.BLOCK) {
238 // We use CodeMirror's LineWidget feature to render the block ghost text element.
239 const lineElement = document.createElement('div');
240 lineElement.classList.add('codeium-ghost');
241 part.text.split('\n').forEach((line) => {
242 const preElement = document.createElement('pre');
243 preElement.classList.add('CodeMirror-line', 'codeium-ghost-line');
244 if (line === '') {
245 line = ' ';
246 }

Callers 1

triggerCompletionMethod · 0.95

Calls 2

clearCompletionMethod · 0.95

Tested by

no test coverage detected