Skip to content

Commit

Permalink
fix: make sure noSuggest custom dictionaries are possible. (#2431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jan 7, 2023
1 parent 0e40853 commit 4a23e09
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 18 deletions.
205 changes: 205 additions & 0 deletions package.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/_server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"clean": "rimraf dist temp out coverage",
"lint": "eslint \"src/**/*.ts\"",
"build": "yarn run compile && yarn run build-schema",
"build-schema": "ts-json-schema-generator --no-top-ref --expose none --path src/config/cspellConfig.ts --type SpellCheckerSettingsVSCode --validation-keywords markdownDescription --validation-keywords scope --validation-keywords patternErrorMessage --validation-keywords deprecationMessage --validation-keywords enumDescriptions --validation-keywords deprecated --validation-keywords order -o spell-checker-config.schema.json",
"build-schema": "ts-json-schema-generator --no-top-ref --expose none --path src/config/cspellConfig/cspellConfig.ts --type SpellCheckerSettingsVSCode --validation-keywords markdownDescription --validation-keywords scope --validation-keywords patternErrorMessage --validation-keywords deprecationMessage --validation-keywords enumDescriptions --validation-keywords deprecated --validation-keywords order -o spell-checker-config.schema.json",
"clean-build": "yarn run clean && yarn run build",
"clean-build-production": "yarn run clean && yarn run compile",
"build-production": "yarn run clean-build-production",
Expand Down
172 changes: 172 additions & 0 deletions packages/_server/spell-checker-config.schema.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion packages/_server/src/config/WorkspacePathResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { debugExports, createWorkspaceNamesResolver, resolveSettings } from './W
import * as Path from 'path';
import { WorkspaceFolder } from 'vscode-languageserver/node';
import { URI as Uri } from 'vscode-uri';
import { CSpellUserSettings, CustomDictionaries } from '../config/cspellConfig';
import { CSpellUserSettings, CustomDictionaries } from './cspellConfig';
import { logError } from 'common-utils/log.js';

jest.mock('vscode-languageserver/node');
Expand Down Expand Up @@ -204,6 +204,10 @@ describe('Validate workspace substitution resolver', () => {
path: '${root}/node_modules/@company/terms/company-terms.txt',
addWords: false,
},
'ignore-words': {
path: '${root}/node_modules/@company/terms/ignored-terms.txt',
noSuggest: true,
},
'Project Dictionary': {
addWords: true,
},
Expand Down Expand Up @@ -365,6 +369,7 @@ describe('Validate workspace substitution resolver', () => {
'Root Dictionary',
'Workspace Dictionary 2',
'company-terms',
'ignore-words',
'python-terms',
'typescript',
])
Expand All @@ -381,6 +386,7 @@ describe('Validate workspace substitution resolver', () => {
'Workspace Dictionary 2',
'company-terms',
'python-terms',
'ignore-words',
'legacy-definition',
'legacy-definition-file',
])
Expand Down
2 changes: 1 addition & 1 deletion packages/_server/src/config/WorkspacePathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as os from 'os';
import * as Path from 'path';
import { WorkspaceFolder } from 'vscode-languageserver/node';
import { URI as Uri } from 'vscode-uri';
import { CSpellUserSettings } from '../config/cspellConfig';
import { CSpellUserSettings } from './cspellConfig';
import { extractDictionaryDefinitions, extractDictionaryList } from './customDictionaries';

export type WorkspaceGlobResolverFn = (glob: Glob) => GlobDef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ import type {
OverrideSettings,
SimpleGlob,
} from '@cspell/cspell-types';
export type {
CustomDictionaryScope,
DictionaryDefinition,
DictionaryDefinitionCustom,
DictionaryFileTypes,
LanguageSetting,
} from '@cspell/cspell-types';

export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings {
/**
Expand Down Expand Up @@ -427,7 +420,7 @@ export type CustomDictionaries = {
[Name in DictionaryId]: EnableCustomDictionary | CustomDictionariesDictionary;
};

export type CustomDictionaryEntry = CustomDictionary | DictionaryId;
export type CustomDictionaryEntry = CustomDictionaryAugmentExistingDictionary | CustomDictionary | DictionaryId;

type OptionalField<T, K extends keyof T> = { [k in K]?: T[k] } & Omit<T, K>;

Expand All @@ -436,9 +429,9 @@ type OptionalField<T, K extends keyof T> = { [k in K]?: T[k] } & Omit<T, K>;
* @markdownDescription
* Define a custom dictionary to be included.
*/
export interface CustomDictionariesDictionary extends OptionalField<CustomDictionary, 'name'> {}
export type CustomDictionariesDictionary = OptionalField<CustomDictionaryAugmentExistingDictionary | CustomDictionary, 'name'>;

export interface CustomDictionary {
interface CustomDictionaryBase extends Pick<DictionaryDefCustom, 'noSuggest'> {
/**
* @title Name of Dictionary
* @markdownDescription
Expand Down Expand Up @@ -530,6 +523,20 @@ export interface CustomDictionary {
*/
scope?: CustomDictionaryScope | CustomDictionaryScope[];
}
export interface CustomDictionaryAugmentExistingDictionary extends CustomDictionaryBase {
/**
* @hidden
*/
path?: FsPath;
/**
* @hidden
*/
noSuggest?: undefined;
}

export interface CustomDictionary extends CustomDictionaryBase, Omit<DictionaryDefCustom, keyof CustomDictionaryBase> {
path: FsPath;
}

/**
* @hidden
Expand Down Expand Up @@ -901,9 +908,11 @@ export interface CSpellUserSettings extends SpellCheckerSettings, CSpellSettings
export type SpellCheckerSettingsProperties = keyof SpellCheckerSettings;
export type SpellCheckerSettingsVSCodePropertyKeys = `cspell.${keyof CSpellUserSettings}`;

type DictionaryDef =
| Omit<DictionaryDefinitionPreferred, 'type' | 'useCompounds' | 'repMap'>
| Omit<DictionaryDefinitionCustom, 'type' | 'useCompounds' | 'repMap'>;
type DictionaryDefPreferred = Omit<DictionaryDefinitionPreferred, 'type' | 'useCompounds' | 'repMap'>;

type DictionaryDefCustom = Omit<DictionaryDefinitionCustom, 'type' | 'useCompounds' | 'repMap'>;

type DictionaryDef = DictionaryDefPreferred | DictionaryDefCustom;

interface DictionaryDefinitions {
/**
Expand Down
22 changes: 22 additions & 0 deletions packages/_server/src/config/cspellConfig/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type {
CustomDictionaryScope,
DictionaryDefinition,
DictionaryDefinitionCustom,
DictionaryFileTypes,
LanguageSetting,
} from '@cspell/cspell-types';
export type {
AllSpellCheckerSettingsInVSCode,
CSpellUserSettings,
CustomDictionaries,
CustomDictionariesDictionary,
CustomDictionary,
CustomDictionaryAugmentExistingDictionary,
CustomDictionaryEntry,
CustomDictionaryWithScope,
SpellCheckerSettings,
SpellCheckerSettingsProperties,
SpellCheckerSettingsVSCode,
SpellCheckerSettingsVSCodeBase,
SpellCheckerSettingsVSCodePropertyKeys,
} from './cspellConfig';
2 changes: 1 addition & 1 deletion packages/_server/src/config/documentSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as os from 'os';
import * as Path from 'path';
import { Connection, WorkspaceFolder } from 'vscode-languageserver/node';
import { URI as Uri } from 'vscode-uri';
import { CSpellUserSettings } from '../config/cspellConfig';
import { CSpellUserSettings } from './cspellConfig';
import { escapeRegExp } from 'common-utils/util.js';
import {
correctBadSettings,
Expand Down
2 changes: 1 addition & 1 deletion packages/_server/src/config/documentSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import * as path from 'path';
import { Connection, WorkspaceFolder } from 'vscode-languageserver/node';
import { URI as Uri, Utils as UriUtils } from 'vscode-uri';
import { VSCodeSettingsCspell } from '../api';
import { CSpellUserSettings } from '../config/cspellConfig';
import { CSpellUserSettings } from './cspellConfig';
import { extensionId } from '../constants';
import { uniqueFilter } from '../utils';
import { canAddWordsToDictionary } from './customDictionaries';
Expand Down

0 comments on commit 4a23e09

Please sign in to comment.