Skip to content

Commit

Permalink
chore: Update CSpell to 8.1.0 (#2950)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Dec 4, 2023
1 parent f09dab7 commit e0905ba
Show file tree
Hide file tree
Showing 74 changed files with 605 additions and 482 deletions.
2 changes: 2 additions & 0 deletions Spell Checker.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"program": "${workspaceFolder:Client}/../../node_modules/jest/bin/jest",
"cwd": "${fileDirname}",
"args": ["--runInBand", "${fileBasename}"],
"env": { "NODE_OPTIONS": "--experimental-vm-modules" },
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
Expand All @@ -71,6 +72,7 @@
"program": "${workspaceFolder:Client}/../../node_modules/jest/bin/jest",
"cwd": "${fileWorkspaceFolder}",
"args": ["--runInBand"],
"env": { "NODE_OPTIONS": "--experimental-vm-modules" },
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
Expand Down
504 changes: 211 additions & 293 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3351,10 +3351,10 @@
"vitest": "^0.34.6"
},
"dependencies": {
"@cspell/cspell-bundled-dicts": "^8.0.0",
"@cspell/cspell-types": "^8.0.0",
"@cspell/cspell-bundled-dicts": "^8.1.0",
"@cspell/cspell-types": "^8.1.0",
"@types/react": "^17.0.70",
"cspell": "^8.0.0",
"cspell": "^8.1.0",
"regexp-worker": "^2.0.2"
},
"comment-resolutions": {
Expand Down
4 changes: 2 additions & 2 deletions packages/__cspell-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"yargs": "^17.7.2"
},
"dependencies": {
"@cspell/cspell-types": "^8.0.0",
"cspell-lib": "^8.0.0"
"@cspell/cspell-types": "^8.1.0",
"cspell-lib": "^8.1.0"
},
"engines": {
"node": ">18.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/__cspell-helper/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { CSpellSettings } from '@cspell/cspell-types';
import { getDefaultSettings, getGlobalSettings, mergeSettings, searchForConfig } from 'cspell-lib';
import { getDefaultSettings, getGlobalSettingsAsync, mergeSettings, searchForConfig } from 'cspell-lib';

export interface CSpellExports {
getDefaultSettings(useDefaultDicts?: boolean): CSpellSettings;
getGlobalSettings(): CSpellSettings;
getDefaultSettings(useDefaultDicts?: boolean): Promise<CSpellSettings>;
getGlobalSettings(): Promise<CSpellSettings>;
mergeSettings(left: CSpellSettings, ...rest: CSpellSettings[]): CSpellSettings;
searchForConfig(fromFile?: string): Promise<CSpellSettings | undefined>;
}

export async function importCSpellLib(): Promise<CSpellExports> {
return {
getDefaultSettings,
getGlobalSettings,
getGlobalSettings: getGlobalSettingsAsync,
mergeSettings,
searchForConfig,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/_integrationTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@cspell/cspell-types": "^8.0.0",
"@cspell/cspell-types": "^8.1.0",
"@types/chai": "^4.3.10",
"@types/decompress": "^4.2.7",
"@types/glob": "^8.1.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/_server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"yargs": "^17.7.2"
},
"dependencies": {
"@cspell/cspell-bundled-dicts": "^8.0.0",
"@cspell/cspell-pipe": "^8.0.0",
"@cspell/cspell-types": "^8.0.0",
"@cspell/cspell-bundled-dicts": "^8.1.0",
"@cspell/cspell-pipe": "^8.1.0",
"@cspell/cspell-types": "^8.1.0",
"@internal/common-utils": "file:../__utils",
"cspell-gitignore": "^8.0.0",
"cspell-glob": "^8.0.0",
"cspell-lib": "^8.0.0",
"cspell-gitignore": "^8.1.0",
"cspell-glob": "^8.1.0",
"cspell-lib": "^8.1.0",
"gensequence": "^6.0.0",
"json-rpc-api": "file:../json-rpc-api",
"node-watch": "^0.7.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/_server/src/SuggestionsGenerator.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Validate Suggestions', () => {
);

async function getSettings(doc: DocInfo) {
const settings = await cspell.constructSettingsForText(cspell.getDefaultSettings(), doc.text || '', doc.languageId);
const settings = await cspell.constructSettingsForText(await cspell.getDefaultSettings(), doc.text || '', doc.languageId);
const dictionary = await cspell.getDictionary(settings);
return { settings, dictionary };
}
Expand Down
20 changes: 12 additions & 8 deletions packages/_server/src/config/documentSettings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class DocumentSettings {
constructor(
readonly connection: Connection,
readonly api: ServerSideApi,
readonly defaultSettings: CSpellUserSettings = _defaultSettings,
readonly defaultSettings: CSpellUserSettings | Promise<CSpellUserSettings> = _defaultSettings,
) {}

async getSettings(document: TextDocumentUri): Promise<CSpellUserSettings> {
Expand Down Expand Up @@ -210,10 +210,10 @@ export class DocumentSettings {
return this._folders();
}

private _importSettings() {
private async _importSettings() {
log('importSettings');
const importPaths = [...this.configsToImport].sort();
return mergeSettings({}, ...readSettingsFiles(importPaths));
return readAndMergeSettingsFiles(importPaths);
}

private async _fetchWorkspaceConfiguration(uri: DocumentUri): Promise<WorkspaceConfigForDocument> {
Expand Down Expand Up @@ -338,12 +338,12 @@ export class DocumentSettings {
const settings = vscodeCSpellConfigSettingsForDocument.noConfigSearch ? undefined : await searchForConfig(searchForFsPath);
const rootFolder = this.rootSchemaAndDomainFolderForUri(docUri);
const folder = await this.findMatchingFolder(docUri, folders[0] || rootFolder);
const vscodeCSpellSettings = resolveConfigImports(vscodeCSpellConfigSettingsForDocument, folder.uri);
const vscodeCSpellSettings = await resolveConfigImports(vscodeCSpellConfigSettingsForDocument, folder.uri);
const globRootFolder = folder !== rootFolder ? folder : folders[0] || folder;

const mergedSettingsFromVSCode = mergeSettings(this.importedSettings(), vscodeCSpellSettings);
const mergedSettingsFromVSCode = mergeSettings(await this.importedSettings(), vscodeCSpellSettings);
const mergedSettings = mergeSettings(
this.defaultSettings,
await Promise.resolve(this.defaultSettings),
filterMergeFields(
mergedSettingsFromVSCode,
vscodeCSpellSettings['mergeCSpellSettings'] || !settings,
Expand Down Expand Up @@ -407,19 +407,23 @@ export class DocumentSettings {
}
}

function resolveConfigImports(config: CSpellUserSettings, folderUri: string): CSpellUserSettings {
async function resolveConfigImports(config: CSpellUserSettings, folderUri: string): Promise<CSpellUserSettings> {
log('resolveConfigImports:', folderUri);
const uriFsPath = path.normalize(Uri.parse(folderUri).fsPath);
const imports = typeof config.import === 'string' ? [config.import] : config.import || [];
const importAbsPath = imports.map((file) => resolvePath(uriFsPath, file));
log(`resolvingConfigImports: [\n${imports.join('\n')}]`);
log(`resolvingConfigImports ABS: [\n${importAbsPath.join('\n')}]`);
const { import: _import, ...result } = importAbsPath.length
? mergeSettings({}, ...readSettingsFiles([...importAbsPath]), config)
? mergeSettings(await readAndMergeSettingsFiles(importAbsPath), config)
: config;
return result;
}

async function readAndMergeSettingsFiles(importAbsPaths: string[]): Promise<CSpellSettingsWithSourceTrace> {
return mergeSettings({}, ...(await Promise.all(readSettingsFiles([...importAbsPaths]))));
}

function readSettingsFiles(paths: string[]) {
// log('readSettingsFiles:', paths);
const existingPaths = paths.filter((filename) => exists(filename));
Expand Down
22 changes: 11 additions & 11 deletions packages/_server/src/config/documentSettings.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ describe('Validate DocumentSettings', () => {
const mockFolders: WorkspaceFolder[] = [workspaceFolderRoot, workspaceFolderClient, workspaceFolderServer];
mockGetWorkspaceFolders.mockReturnValue(Promise.resolve(mockFolders));
mockGetConfiguration.mockReturnValue(Promise.resolve([{}, {}]));
const docSettings = newDocumentSettings(getDefaultSettings());
const docSettings = newDocumentSettings(await getDefaultSettings());
const uri = Uri.file(Path.resolve(pathWorkspaceRoot, filename)).toString();
const result = await docSettings.findCSpellConfigurationFilesForUri(uri);
// Note: toLowerCase is needed because on MacOS and Windows cSpell.json and cspell.json will be considered the same file.
Expand All @@ -420,7 +420,7 @@ describe('Validate DocumentSettings', () => {
const mockFolders: WorkspaceFolder[] = [];
mockGetWorkspaceFolders.mockReturnValue(Promise.resolve(mockFolders));
mockGetConfiguration.mockReturnValue(Promise.resolve([{}, {}]));
const docSettings = newDocumentSettings(getDefaultSettings());
const docSettings = newDocumentSettings(await getDefaultSettings());
const uri = Uri.file(Path.resolve(pathWorkspaceRoot, filename)).toString();
const result = await docSettings.findCSpellConfigurationFilesForUri(uri);
// Note: toLowerCase is needed because on MacOS and Windows cSpell.json and cspell.json will be considered the same file.
Expand All @@ -438,25 +438,25 @@ describe('Validate DocumentSettings', () => {
});

describe('Validate RegExp corrections', () => {
test('fixRegEx', () => {
const defaultSettings = cspell.getDefaultSettings();
test('fixRegEx', async () => {
const defaultSettings = await cspell.getDefaultSettings();
const patterns = defaultSettings.patterns;

// Make sure it doesn't change the defaults.
expect(defaultSettings.patterns?.map((p) => p.pattern).map(debugExports.fixRegEx)).toEqual(
defaultSettings.patterns?.map((p) => p.pattern),
);
expect(patterns?.map((p) => p.pattern).map(debugExports.fixRegEx)).toEqual(patterns?.map((p) => p.pattern));
const sampleRegEx: Pattern[] = ['/#.*/', '/"""(.*?\\n?)+?"""/g', "/'''(.*?\\n?)+?'''/g", 'strings'];
const expectedRegEx: Pattern[] = ['/#.*/', '/(""")[^\\1]*?\\1/g', "/(''')[^\\1]*?\\1/g", 'strings'];
expect(sampleRegEx.map(debugExports.fixRegEx)).toEqual(expectedRegEx);
});

test('fixPattern', () => {
const defaultSettings = cspell.getDefaultSettings();
test('fixPattern', async () => {
const defaultSettings = await cspell.getDefaultSettings();
// Make sure it doesn't change the defaults.
expect(defaultSettings.patterns?.map(debugExports.fixPattern)).toEqual(defaultSettings.patterns);
});

test('fixPattern', () => {
const defaultSettings = cspell.getDefaultSettings();
test('fixPattern', async () => {
const defaultSettings = await cspell.getDefaultSettings();
// Make sure it doesn't change the defaults.
expect(correctBadSettings(defaultSettings)).toEqual(defaultSettings);

Expand Down
15 changes: 9 additions & 6 deletions packages/_server/src/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ const overRideDefaults: CSpellUserSettings = {

// Turn off the spell checker by default. The setting files should have it set.
// This prevents the spell checker from running too soon.
const defaultSettings: CSpellUserSettings = {
...CSpell.mergeSettings(getDefaultSettings(), CSpell.getGlobalSettings(), overRideDefaults),
checkLimit: defaultCheckLimit,
// enabled: false,
};
const defaultSettings = calcDefaultSettings();
const defaultDebounceMs = 50;
// Refresh the dictionary cache every 1000ms.
const dictionaryRefreshRateMs = 1000;

async function calcDefaultSettings(): Promise<CSpellUserSettings> {
return {
...CSpell.mergeSettings(await getDefaultSettings(), await CSpell.getGlobalSettingsAsync(), overRideDefaults),
checkLimit: defaultCheckLimit,
};
}

export function run(): void {
// debounce buffer
const disposables = createDisposableList();
Expand Down Expand Up @@ -508,7 +511,7 @@ export function run(): void {

async function getBaseSettings(doc: TextDocumentUri | undefined) {
const settings = await getActiveSettings(doc);
return { ...CSpell.mergeSettings(defaultSettings, settings), enabledLanguageIds: settings.enabledLanguageIds };
return { ...CSpell.mergeSettings(await defaultSettings, settings), enabledLanguageIds: settings.enabledLanguageIds };
}

async function getSettingsToUseForDocument(doc: TextDocument) {
Expand Down
2 changes: 1 addition & 1 deletion packages/_server/src/validator.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as Validator from './validator.mjs';

// cSpell:ignore brouwn jumpped lazzy wrongg mispelled ctrip nmove mischecked

const defaultSettings: CSpellSettings = { ...getDefaultSettings(), enabledLanguageIds: ['plaintext', 'javascript'] };
const defaultSettings: CSpellSettings = { ...(await getDefaultSettings()), enabledLanguageIds: ['plaintext', 'javascript'] };

const timeout = 30000; // 30 seconds

Expand Down
4 changes: 2 additions & 2 deletions packages/_serverPatternMatcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@cspell/cspell-types": "^8.0.0",
"@cspell/cspell-types": "^8.1.0",
"@internal/common-utils": "file:../__utils",
"cspell-lib": "^8.0.0",
"cspell-lib": "^8.1.0",
"regexp-worker": "^2.0.2",
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-languageserver": "^9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/_serverPatternMatcher/src/PatternMatcher.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isRegExpMatch, isRegExpMatchTimeout, PatternMatcher } from './PatternMa

const settings = {
patterns: [],
...getDefaultSettings(),
...(await getDefaultSettings()),
};

const defaultTimeout = 5000;
Expand Down
10 changes: 10 additions & 0 deletions packages/client/__mocks__/vscode-languageclient/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const DiagnosticSeverity = {
Error: 1,
Warning: 2,
Information: 3,
Hint: 4,
};

module.exports = {
DiagnosticSeverity,
};
6 changes: 6 additions & 0 deletions packages/client/__mocks__/vscode.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createVSCodeMock } from 'jest-mock-vscode';
import { vi } from 'vitest';

const vscode = createVSCodeMock(vi);

module.exports = vscode;
15 changes: 6 additions & 9 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
"build:esbuild": "node ./build.mjs",
"build:api": "tsc -p tsconfig.api.json",
"build:tsc": "tsc -p tsconfig.test.json",
"build:src": "tsc -p tsconfig.json",
"clean-build-production": "npm run clean && npm run build:production",
"clean-build": "npm run clean && npm run build",
"clean": "shx rm -rf dist temp out coverage",
"version": "npm run package-extension",
"test": "jest",
"test-watch": "jest --watch",
"test": "vitest run",
"test-watch": "vitest",
"watch": "concurrently npm:watch:esbuild npm:watch:api npm:watch:tsc",
"watch:esbuild": "npm run build:esbuild -- --watch",
"watch:api": "npm run build:api.d.ts -- --watch",
Expand All @@ -41,24 +42,20 @@
"devDependencies": {
"@internal/cspell-helper": "file:../__cspell-helper",
"@internal/locale-resolver": "file:../__locale-resolver",
"@types/jest": "^29.5.8",
"@types/jest-when": "^3.5.5",
"@types/kefir": "^3.8.10",
"@types/source-map-support": "^0.5.10",
"cross-env": "^7.0.3",
"cspell-lib": "^8.0.0",
"jest": "^29.7.0",
"jest-when": "^3.6.0",
"cspell-lib": "^8.1.0",
"lorem-ipsum": "^2.0.8",
"rfdc": "^1.3.0",
"source-map-support": "^0.5.21",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"vitest-when": "^0.2.0",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@cspell/cspell-types": "^8.0.0",
"@cspell/cspell-types": "^8.1.0",
"@internal/common-utils": "file:../__utils",
"@internal/settings-webview": "file:../_settingsViewer",
"code-spell-checker-server": "file:../_server",
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/Subscribables/StoreValue.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test, vi } from 'vitest';

import { createEmitter, createSubscribable } from './createFunctions';
import { awaitSubscribable } from './helpers/awaitSubscribable';
import { createStoreValue } from './StoreValue';
Expand All @@ -8,7 +10,7 @@ describe('StoreValue', () => {
expect(store.value).toBe(5);
store.set(7);
expect(store.value).toBe(7);
const cb = jest.fn();
const cb = vi.fn();
store.subscribe(cb);
expect(cb).toHaveBeenLastCalledWith(7);
store.dispose();
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/Subscribables/SubscribableView.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { disposeOf } from 'utils-disposables';
import { describe, expect, test } from 'vitest';

import { map, rx } from '.';
import { createEmitter } from './createFunctions';
Expand Down
6 changes: 4 additions & 2 deletions packages/client/src/Subscribables/Subscribables.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { describe, expect, test, vi } from 'vitest';

import { createEmitter, createSubscribable } from './createFunctions';
import { awaitSubscribable } from './helpers/awaitSubscribable';
import { delayUnsubscribe } from './operators/delayUnsubscribe';

describe('Subscribables', () => {
test('createEmitter', () => {
const emitter = createEmitter<number>();
const sub = jest.fn();
const sub = vi.fn();
emitter.subscribe(sub);
expect(sub).not.toHaveBeenCalled();
emitter.notify(7);
expect(sub).toHaveBeenLastCalledWith(7);
const sub2 = jest.fn();
const sub2 = vi.fn();
const d2 = emitter.subscribe(sub2);
expect(sub2).not.toHaveBeenCalled();
emitter.notify(49);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from 'vitest';

import { awaitSubscribableAll } from './awaitSubscribable';
import { fromIterable } from './fromIterable';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, test } from 'vitest';

import { awaitAsyncIterable } from './awaitAsyncIterable';
import { fromIterable } from './fromIterable';
import { toAsyncIterable } from './toAsyncIterable';
Expand Down
Loading

0 comments on commit e0905ba

Please sign in to comment.