Skip to content

Commit

Permalink
fix: Be able to enable/disable file type from info view (#3266)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed May 16, 2024
1 parent 9c3334b commit 5a5a435
Show file tree
Hide file tree
Showing 28 changed files with 539 additions and 244 deletions.
1 change: 1 addition & 0 deletions docs/_includes/generated-docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
| `cSpell.issueViewer.item.autoFixSpellingIssues` | Fix issue with preferred suggestion in the current document.<br>**When:**<br> `view == cspell-info.issuesView` |
| `cSpell.issueViewer.item.openSuggestionsForIssue` | Show Suggestions<br>**When:**<br> `view == cspell-info.issuesView` |
| `cSpell.logPerfTimeline` | Log CSpell performance times to console |
| `cSpell.openFileInfoView` | Open Spell Checker File Information View |
| `cSpell.openIssuesPanel` | Open Spell Checker Issues Panel |
| `cSpell.removeWordFromFolderDictionary` | Remove Words from the Folder Dictionary |
| `cSpell.removeWordFromUserDictionary` | Remove Words from the Global Dictionary |
Expand Down
59 changes: 23 additions & 36 deletions package-lock.json

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

14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,26 @@
"shortTitle": "Open Spelling Issues",
"icon": "$(eye)"
},
{
"command": "cSpell.openFileInfoView",
"category": "Spell",
"title": "Open Spell Checker File Information View",
"shortTitle": "Open File Info",
"icon": "$(eye)"
},
{
"command": "cSpell.restart",
"category": "Spell",
"title": "Restart Spell Checker Server",
"shortTitle": "Restart Spell Checker",
"icon": "$(sync)"
},
{
"command": "cspell.showActionsMenu",
"category": "Spell",
"title": "Show Spell Checker Actions Menu",
"shortTitle": "Spell Checker Actions",
"icon": "$(list-unordered)"
}
],
"languages": [
Expand Down
4 changes: 2 additions & 2 deletions packages/_server/src/config/documentSettings.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
isUriAllowedBySettings,
isUriBlockedBySettings,
} from './documentSettings.mjs';
import { isLanguageEnabled } from './extractEnabledFileTypes.mjs';
import { isFileTypeEnabled } from './extractEnabledFileTypes.mjs';
import { getConfiguration, getWorkspaceFolders } from './vscode.config.mjs';

const { toEqualCaseInsensitive: expectToEqualCaseInsensitive } = extendExpect(expect);
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('Validate DocumentSettings', () => {
${'typescript'} | ${{ enableFiletypes: ['!*'], checkOnlyEnabledFileTypes: false }} | ${true}
${'java'} | ${{ enableFiletypes: ['!*', 'java'], checkOnlyEnabledFileTypes: true }} | ${true}
`('isLanguageEnabled $languageId $settings', ({ languageId, settings, expected }) => {
expect(isLanguageEnabled(languageId, settings)).toBe(expected);
expect(isFileTypeEnabled(languageId, settings)).toBe(expected);
});

test('isExcludedBy', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/_server/src/config/extractEnabledFileTypes.mts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function normalizeEnableFiletypes(enableFiletypes: string[]): string[] {
return ids;
}

export function isLanguageEnabled(languageId: string, settings: CSpellUserSettings): boolean {
export function isFileTypeEnabled(languageId: string, settings: CSpellUserSettings): boolean {
const enabledFileTypes = extractEnabledFileTypes(settings);
const enabled = enabledFileTypes[languageId];
if (enabled !== undefined) return enabled;
Expand Down
8 changes: 4 additions & 4 deletions packages/_server/src/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
isUriBlockedBySettings,
stringifyPatterns,
} from './config/documentSettings.mjs';
import { isLanguageEnabled } from './config/extractEnabledFileTypes.mjs';
import { isFileTypeEnabled } from './config/extractEnabledFileTypes.mjs';
import { objectFieldSizes, objectKeysNested, sanitizeSettings } from './config/sanitizeSettings.mjs';
import type { TextDocumentUri } from './config/vscode.config.mjs';
import { defaultCheckLimit } from './constants.mjs';
Expand Down Expand Up @@ -502,7 +502,7 @@ export function run(): void {
const { uri, languageId } = textDocument;
return (
!!settings.enabled &&
(!languageId || isLanguageEnabled(languageId, settings)) &&
(!languageId || isFileTypeEnabled(languageId, settings)) &&
!(await isUriExcluded(uri)) &&
!isBlocked(textDocument, settings)
);
Expand Down Expand Up @@ -542,7 +542,7 @@ export function run(): void {
): Promise<Api.IsSpellCheckEnabledResult> {
log('calcIncludeExcludeInfo', params.uri);
const { uri, languageId } = params;
const languageEnabled = languageId ? isLanguageEnabled(languageId, settings) : undefined;
const languageIdEnabled = languageId ? isFileTypeEnabled(languageId, settings) : undefined;

const {
include: fileIsIncluded = true,
Expand All @@ -565,7 +565,7 @@ export function run(): void {
fileEnabled,
fileIsExcluded,
fileIsIncluded,
languageIdEnabled: languageEnabled,
languageIdEnabled: languageIdEnabled,
languageId,
gitignored,
gitignoreInfo,
Expand Down

0 comments on commit 5a5a435

Please sign in to comment.