From 360aa7915ffe7ad3b64fffa147d1e989c1ffd1f6 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 11 Apr 2024 11:27:12 -0400 Subject: [PATCH] breaking change: specify otherDocuments as a function instead of an array --- README.md | 2 +- demo/index.ts | 2 +- src/completionRequester.ts | 6 +++--- src/config.ts | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ab03b08..472c021 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # codemirror-codeium - [![npm](https://img.shields.io/npm/v/@valtown/codemirror-codeium)](https://www.npmjs.com/package/@valtown/codemirror-codeium) +[![npm](https://img.shields.io/npm/v/@valtown/codemirror-codeium)](https://www.npmjs.com/package/@valtown/codemirror-codeium) ```mermaid flowchart TD diff --git a/demo/index.ts b/demo/index.ts index 4bca7c8..1049c48 100644 --- a/demo/index.ts +++ b/demo/index.ts @@ -22,7 +22,7 @@ increment('not a number');`, jsx: true, }), codeiumOtherDocumentsConfig.of({ - otherDocuments: [ + override: () => [ { absolutePath: "https://esm.town/v/foo.ts", text: `export const foo = 10; diff --git a/src/completionRequester.ts b/src/completionRequester.ts index 0cac4b6..500e96b 100644 --- a/src/completionRequester.ts +++ b/src/completionRequester.ts @@ -61,9 +61,7 @@ export function completionRequester() { return EditorView.updateListener.of((update: ViewUpdate) => { const config = update.view.state.facet(codeiumConfig); - const { otherDocuments } = update.view.state.facet( - codeiumOtherDocumentsConfig, - ); + const { override } = update.view.state.facet(codeiumOtherDocumentsConfig); if (!shouldRequestCompletion(update)) return; @@ -86,6 +84,8 @@ export function completionRequester() { // Check if the position has changed if (pos !== lastPos) return; + const otherDocuments = await override(); + // Request completion from the server try { const completionResult = await getCodeiumCompletions({ diff --git a/src/config.ts b/src/config.ts index ed64a0a..78b283a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -34,8 +34,10 @@ export const codeiumConfig = Facet.define< }, }); +type OtherDocuments = PartialMessage[]; + export interface CodeiumOtherDocumentsConfig { - otherDocuments?: PartialMessage[]; + override?: () => Promise | OtherDocuments; } export const codeiumOtherDocumentsConfig = Facet.define< @@ -46,7 +48,7 @@ export const codeiumOtherDocumentsConfig = Facet.define< return combineConfig>( configs, { - otherDocuments: [], + override: () => [], }, {}, );