Skip to content

Commit

Permalink
dev: Work towards using a webview to display spelling information. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Oct 5, 2023
1 parent ffc6bd2 commit aa35ee6
Show file tree
Hide file tree
Showing 65 changed files with 2,060 additions and 451 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 1 addition & 10 deletions packages/_integrationTests/src/extension.test.cts
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,9 @@ const apiSignature: Api = {
describe('Launch code spell extension', function () {
this.timeout(120000);
const docUri = getDocUri('diagnostics.txt');
const spellCheckNotifications: OnSpellCheckDocumentStep[] = [];
const disposables: { dispose: () => void }[] = [];

this.beforeAll(async () => {
const ext = await activateExtension();
disposables.push(ext.extApi.cSpellClient().onSpellCheckDocumentNotification((n) => spellCheckNotifications.push(n)));
});

this.afterEach(async () => {
disposables.forEach((d) => d.dispose());
disposables.length = 0;
await sleep(1000);
await activateExtension();
});

it('Verify the extension starts', async () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/client/src/infoViewer/infoHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export async function calcSettings(
client: CSpellClient,
log: Logger,
): Promise<Settings> {
const activeFolderUri = folderUri || getDefaultWorkspaceFolderUri();
const activeFolderUri = folderUri || getDefaultWorkspaceFolderUri(document?.uri);
const config = inspectConfig(activeFolderUri);
const docConfig = await client.getConfigurationForDocument(document);
const settings: Settings = {
knownLanguageIds: [...client.languageIds].sort(),
dictionaries: extractDictionariesFromConfig(docConfig.settings),
configs: extractViewerConfigFromConfig(config, docConfig, document, log),
workspace: mapWorkspace(client.allowedSchemas, vscode.workspace),
activeFileUri: document && document.uri.toString(),
activeFileUri: document?.uri.toString(),
activeFolderUri: activeFolderUri?.toString(),
};
return settings;
Expand Down Expand Up @@ -187,8 +187,9 @@ function getDefaultWorkspaceFolder() {
return vscode.workspace.workspaceFolders?.[0];
}

function getDefaultWorkspaceFolderUri() {
return getDefaultWorkspaceFolder()?.uri;
function getDefaultWorkspaceFolderUri(docUri?: Uri) {
const docFolder = docUri && vscode.workspace.getWorkspaceFolder(docUri);
return docFolder || getDefaultWorkspaceFolder()?.uri;
}

function normalizeFilenameToFriendlyName(filename: string | Uri): string {
Expand Down
227 changes: 0 additions & 227 deletions packages/client/src/webview/AppState/Subscribables.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createEmitter, createSubscribable } from './createFunctions';
import { awaitSubscribable } from './helpers/awaitSubscribable';
import { createStoreValue } from './StoreValue';

describe('StoreValue', () => {
test('createStoreValue', async () => {
const store = createStoreValue(5);
expect(store.value).toBe(5);
store.set(7);
expect(store.value).toBe(7);
const cb = jest.fn();
store.subscribe(cb);
expect(cb).toHaveBeenLastCalledWith(7);
store.dispose();
});

test('createSubscribableValue', async () => {
const source = createEmitter<number>();
const sub = createSubscribable((s) => source.subscribe(s));
const pValue = awaitSubscribable(sub);
source.notify(6);
await expect(pValue).resolves.toBe(6);
sub.dispose();
});
});
54 changes: 54 additions & 0 deletions packages/client/src/webview/AppState/Subscribables/StoreValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import deepEqual from 'fast-deep-equal';

import { toSubscriberFn } from './helpers/toSubscriber';
import { AbstractSubscribable } from './internal/AbstractSubscribable';
import type { Subscribable, SubscribableValue, SubscriberLike } from './Subscribables';

export interface StoreValue<T> extends SubscribableValue<T> {
value: T;
set(v: T): void;
update(u: (v: T) => T): void;
}

export function createStoreValue<T>(v: T): StoreValue<T> {
return new StoreValueImpl(v);
}

class StoreValueImpl<T> extends AbstractSubscribable<T> implements StoreValue<T> {
private _value: T;
constructor(value: T) {
super();
this._value = value;
}

get value() {
return this._value;
}

set value(v: T) {
this.set(v);
}

set(value: T) {
// Do not update if the value has not changed.
if (this._value === value || deepEqual(this._value, value)) return;
this._value = value;
this.notify(value);
return;
}

subscribe(s: SubscriberLike<T>) {
const dispose = super.subscribe(s);
const sFn = toSubscriberFn(s);
sFn(this._value);
return dispose;
}

update(u: (v: T) => T) {
return this.set(u(this._value));
}
}

export type MakeSubscribable<T, RO extends keyof T | never = never> = {
[K in keyof T]: K extends RO ? Subscribable<T[K]> : StoreValue<T[K]>;
};
Loading

0 comments on commit aa35ee6

Please sign in to comment.