-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reduce traffic volume between client/server (#3256)
- Loading branch information
Showing
29 changed files
with
447 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { ConfigFields as CSpellConfigFields } from '@cspell/cspell-types'; | ||
|
||
import type { CSpellUserSettings } from './cspellConfig.mjs'; | ||
|
||
export { ConfigFields as CSpellConfigFields } from '@cspell/cspell-types'; | ||
|
||
export type ConfigKeys = Exclude< | ||
keyof CSpellUserSettings, | ||
'$schema' | 'version' | 'id' | 'experimental.enableRegexpView' | 'experimental.enableSettingsViewerV2' | ||
>; | ||
|
||
type CSpellUserSettingsFields = { | ||
[key in ConfigKeys]: key; | ||
}; | ||
|
||
export const ConfigFields: CSpellUserSettingsFields = { | ||
...CSpellConfigFields, | ||
'advanced.feature.useReferenceProviderRemove': 'advanced.feature.useReferenceProviderRemove', | ||
'advanced.feature.useReferenceProviderWithRename': 'advanced.feature.useReferenceProviderWithRename', | ||
autoFormatConfigFile: 'autoFormatConfigFile', | ||
blockCheckingWhenAverageChunkSizeGreaterThan: 'blockCheckingWhenAverageChunkSizeGreaterThan', | ||
blockCheckingWhenLineLengthGreaterThan: 'blockCheckingWhenLineLengthGreaterThan', | ||
blockCheckingWhenTextChunkSizeGreaterThan: 'blockCheckingWhenTextChunkSizeGreaterThan', | ||
checkLimit: 'checkLimit', | ||
checkOnlyEnabledFileTypes: 'checkOnlyEnabledFileTypes', | ||
customDictionaries: 'customDictionaries', | ||
customFolderDictionaries: 'customFolderDictionaries', | ||
customUserDictionaries: 'customUserDictionaries', | ||
customWorkspaceDictionaries: 'customWorkspaceDictionaries', | ||
diagnosticLevel: 'diagnosticLevel', | ||
diagnosticLevelFlaggedWords: 'diagnosticLevelFlaggedWords', | ||
fixSpellingWithRenameProvider: 'fixSpellingWithRenameProvider', | ||
hideAddToDictionaryCodeActions: 'hideAddToDictionaryCodeActions', | ||
languageStatusFields: 'languageStatusFields', | ||
logLevel: 'logLevel', | ||
logFile: 'logFile', | ||
maxDuplicateProblems: 'maxDuplicateProblems', | ||
maxNumberOfProblems: 'maxNumberOfProblems', | ||
mergeCSpellSettings: 'mergeCSpellSettings', | ||
mergeCSpellSettingsFields: 'mergeCSpellSettingsFields', | ||
noSuggestDictionaries: 'noSuggestDictionaries', | ||
showAutocompleteDirectiveSuggestions: 'showAutocompleteDirectiveSuggestions', | ||
showCommandsInEditorContextMenu: 'showCommandsInEditorContextMenu', | ||
showStatus: 'showStatus', | ||
showStatusAlignment: 'showStatusAlignment', | ||
showSuggestionsLinkInEditorContextMenu: 'showSuggestionsLinkInEditorContextMenu', | ||
spellCheckDelayMs: 'spellCheckDelayMs', | ||
spellCheckOnlyWorkspaceFiles: 'spellCheckOnlyWorkspaceFiles', | ||
suggestionMenuType: 'suggestionMenuType', | ||
suggestionNumChanges: 'suggestionNumChanges', | ||
suggestionsTimeout: 'suggestionsTimeout', | ||
useLocallyInstalledCSpellDictionaries: 'useLocallyInstalledCSpellDictionaries', | ||
workspaceRootPath: 'workspaceRootPath', | ||
trustedWorkspace: 'trustedWorkspace', | ||
// File Types and Schemes | ||
allowedSchemas: 'allowedSchemas', | ||
enabledFileTypes: 'enabledFileTypes', | ||
enabledLanguageIds: 'enabledLanguageIds', | ||
enabledSchemes: 'enabledSchemes', | ||
// Behavior | ||
hideIssuesWhileTyping: 'hideIssuesWhileTyping', | ||
revealIssuesAfterDelayMS: 'revealIssuesAfterDelayMS', | ||
// Appearance | ||
useCustomDecorations: 'useCustomDecorations', | ||
doNotUseCustomDecorationForScheme: 'doNotUseCustomDecorationForScheme', | ||
textDecoration: 'textDecoration', | ||
textDecorationLine: 'textDecorationLine', | ||
textDecorationStyle: 'textDecorationStyle', | ||
textDecorationThickness: 'textDecorationThickness', | ||
textDecorationColor: 'textDecorationColor', | ||
textDecorationColorFlagged: 'textDecorationColorFlagged', | ||
textDecorationColorSuggestion: 'textDecorationColorSuggestion', | ||
overviewRulerColor: 'overviewRulerColor', | ||
dark: 'dark', | ||
light: 'light', | ||
} as const; | ||
|
||
// export const ConfigKeysNames = Object.values(ConfigKeysByField); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { isDefined } from '@internal/common-utils'; | ||
import type { DictionaryDefinition, DictionaryDefinitionCustom } from 'cspell-lib'; | ||
|
||
import type { CSpellUserSettings } from './cspellConfig/index.mjs'; | ||
import { ConfigFields } from './cspellConfig/index.mjs'; | ||
|
||
type ConfigFieldKeys = keyof CSpellUserSettings; | ||
type ConfigFieldFilter = Record<ConfigFieldKeys, boolean | undefined>; | ||
|
||
export function sanitizeSettings(settings: CSpellUserSettings, fields: ConfigFieldFilter): CSpellUserSettings; | ||
export function sanitizeSettings(settings: CSpellUserSettings | undefined, fields: ConfigFieldFilter): CSpellUserSettings | undefined; | ||
export function sanitizeSettings(settings: CSpellUserSettings | undefined, fields: ConfigFieldFilter): CSpellUserSettings | undefined { | ||
if (!settings) return settings; | ||
const includeKeys = new Set<string>( | ||
Object.entries(fields) | ||
.filter(([, value]) => value) | ||
.map(([key]) => key), | ||
); | ||
const excludeKeys = new Set<string>((['words', 'ignoreWords', 'userWords'] as const).filter((key) => !includeKeys.has(key))); | ||
const s = Object.fromEntries( | ||
Object.entries(settings).filter(([key]) => key in ConfigFields && !excludeKeys.has(key) && includeKeys.has(key)), | ||
); | ||
if ('dictionaryDefinitions' in s) { | ||
s.dictionaryDefinitions = sanitizeDictionaryDefinitions(s.dictionaryDefinitions); | ||
} | ||
return s; | ||
} | ||
|
||
function sanitizeDictionaryDefinitions(defs: CSpellUserSettings['dictionaryDefinitions']): CSpellUserSettings['dictionaryDefinitions'] { | ||
if (!defs) return defs; | ||
return defs.map((def) => sanitizeDictionaryDefinition(def)).filter(isDefined); | ||
} | ||
|
||
function sanitizeDictionaryDefinition(def: DictionaryDefinition | undefined): DictionaryDefinitionCustom | undefined { | ||
if (!def) return def; | ||
// if (!def.path) return undefined; | ||
const { name, path, description, addWords } = def as DictionaryDefinitionCustom; | ||
return { | ||
name, | ||
path, | ||
description, | ||
addWords: addWords || false, | ||
}; | ||
} | ||
|
||
export function objectKeysNested(obj: unknown): string[] { | ||
const visited = new Set<unknown>(); | ||
|
||
function _objectKeysNested(obj: unknown, depthRemaining: number): string[] { | ||
if (!depthRemaining || visited.has(obj) || !obj || typeof obj !== 'object') return []; | ||
visited.add(obj); | ||
const keys = new Set<string>(); | ||
if (Array.isArray(obj)) { | ||
const nested = obj.flatMap((o) => _objectKeysNested(o, depthRemaining - 1)); | ||
nested.map((k) => keys.add('[*].' + k)); | ||
} else { | ||
for (const [key, entry] of Object.entries(obj)) { | ||
keys.add(key); | ||
_objectKeysNested(entry, depthRemaining - 1).map((k) => keys.add(key + '.' + k)); | ||
} | ||
} | ||
return [...keys]; | ||
} | ||
|
||
return _objectKeysNested(obj, 4); | ||
} | ||
|
||
export function objectFieldSizes(obj: object): object { | ||
if (!obj) return obj; | ||
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, JSON.stringify(value)?.length || 0])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.