Skip to content

Commit

Permalink
breaking change: specify otherDocuments as a function instead of an a…
Browse files Browse the repository at this point in the history
…rray
  • Loading branch information
tmcw committed Apr 11, 2024
1 parent 7f7e849 commit 360aa79
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/completionRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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({
Expand Down
6 changes: 4 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export const codeiumConfig = Facet.define<
},
});

type OtherDocuments = PartialMessage<Document>[];

export interface CodeiumOtherDocumentsConfig {
otherDocuments?: PartialMessage<Document>[];
override?: () => Promise<OtherDocuments> | OtherDocuments;
}

export const codeiumOtherDocumentsConfig = Facet.define<
Expand All @@ -46,7 +48,7 @@ export const codeiumOtherDocumentsConfig = Facet.define<
return combineConfig<Required<CodeiumOtherDocumentsConfig>>(
configs,
{
otherDocuments: [],
override: () => [],
},
{},
);
Expand Down

0 comments on commit 360aa79

Please sign in to comment.