RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { EditorState } from '@codemirror/state';
|
||||
import { EditorView, keymap } from '@codemirror/view';
|
||||
import { history, historyKeymap, defaultKeymap } from '@codemirror/commands';
|
||||
import { completionExtension } from './codemirror';
|
||||
import { completionHub } from './hub';
|
||||
import { ExternalSession } from '../plugins/externalSession';
|
||||
const editor = (parent: string, documentId: string) => new EditorView({ parent: document.querySelector(parent)!, state: EditorState.create({ doc: 'The ', selection: { anchor: 4 }, extensions: [history(), keymap.of([...historyKeymap, ...defaultKeymap]), completionExtension(documentId)] }) });
|
||||
const writer = editor('#writer', 'fixture');
|
||||
const source = editor('#source', 'fixture-source');
|
||||
// Plugin browser tests read the source text through `model`.
|
||||
const model = { getValue: () => source.state.doc.toString() };
|
||||
let stopProvider = completionHub.registerProvider({ id: 'fixture', delayMs: 100, complete: async () => 'quiet harbor.' });
|
||||
Object.assign(window, { completionTest: { writer, source, model, completionHub, stopProvider,
|
||||
async plugin(code: string) {
|
||||
stopProvider();
|
||||
const session = new ExternalSession('test.autocomplete', {
|
||||
settings: { read: async () => ({ enabled: true, endpoint: 'http://127.0.0.1:8012' }), write: async () => {} },
|
||||
workspace: { list: async () => [], read: async () => '', write: async () => {} }, assets: { read: async () => new Uint8Array() },
|
||||
completionTransport: async (request, signal, onLine) => {
|
||||
if (request.route === '/v1/models') { onLine('{"data":[{"id":"fixture-model"}]}'); return; }
|
||||
await new Promise(resolve => setTimeout(resolve, 25));
|
||||
if (!signal.aborted) onLine('data: {"choices":[{"delta":{"content":"quiet harbor."}}]}\n');
|
||||
},
|
||||
}, () => {}, () => {});
|
||||
const url = URL.createObjectURL(new Blob([code], { type: 'text/javascript' }));
|
||||
try { await session.start(await import(/* @vite-ignore */ url)); } finally { URL.revokeObjectURL(url); }
|
||||
await session.mount('settings', document.querySelector('#plugin') as HTMLElement);
|
||||
return session;
|
||||
},
|
||||
destroy() { stopProvider(); writer.destroy(); source.destroy(); },
|
||||
} });
|
||||
Reference in New Issue
Block a user