Skip to content

Commit

Permalink
fix: Put cspell autocompletion behind a configuration setting. (#1545)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Nov 18, 2021
1 parent f83fe75 commit c5b0b7f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 5 deletions.
21 changes: 21 additions & 0 deletions docs/_includes/generated-docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
| [`cSpell.numSuggestions`](#cspellnumsuggestions) | resource | Controls the number of suggestions shown. |
| [`cSpell.overrides`](#cspelloverrides) | resource | Overrides to apply based upon the file path. |
| [`cSpell.patterns`](#cspellpatterns) | resource | Defines a list of patterns that can be used in ignoreRegExpList and includeRegExpList |
| [`cSpell.showAutocompleteSuggestions`](#cspellshowautocompletesuggestions) | language-overridable | Show CSpell in-document directives as you type. |
| [`cSpell.showCommandsInEditorContextMenu`](#cspellshowcommandsineditorcontextmenu) | application | Show Spell Checker actions in Editor Context Menu |
| [`cSpell.showStatus`](#cspellshowstatus) | application | Display the spell checker status on the status bar. |
| [`cSpell.showStatusAlignment`](#cspellshowstatusalignment) | application | The side of the status bar to display the spell checker status. |
Expand Down Expand Up @@ -867,6 +868,26 @@ Default

---

### `cSpell.showAutocompleteSuggestions`

Name
: `cSpell.showAutocompleteSuggestions`

Type
: boolean

Scope
: language-overridable

Description
: Show CSpell in-document directives as you type.
**Note:** VS Code must be restarted for this setting to take effect.

Default
: _`false`_

---

### `cSpell.showCommandsInEditorContextMenu`

Name
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2526,6 +2526,13 @@
"description": "Tells the spell checker to load `.gitignore` files and skip files that match the globs in the `.gitignore` files found.",
"scope": "window",
"type": "boolean"
},
"cSpell.showAutocompleteSuggestions": {
"default": false,
"description": "Show CSpell in-document directives as you type.",
"scope": "language-overridable",
"type": "boolean",
"markdownDescription": "Show CSpell in-document directives as you type.\n**Note:** VS Code must be restarted for this setting to take effect."
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/_server/spell-checker-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,13 @@
"scope": "resource",
"type": "array"
},
"showAutocompleteSuggestions": {
"default": false,
"description": "Show CSpell in-document directives as you type.",
"markdownDescription": "Show CSpell in-document directives as you type.\n**Note:** VS Code must be restarted for this setting to take effect.",
"scope": "language-overridable",
"type": "boolean"
},
"showCommandsInEditorContextMenu": {
"default": true,
"description": "Show Spell Checker actions in Editor Context Menu",
Expand Down
10 changes: 10 additions & 0 deletions packages/_server/src/config/cspellConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ export interface SpellCheckerSettings extends SpellCheckerShouldCheckDocSettings
*/
showStatusAlignment?: 'Left' | 'Right';

/**
* Show CSpell in-document directives as you type.
* @markdownDescription
* Show CSpell in-document directives as you type.
* **Note:** VS Code must be restarted for this setting to take effect.
* @scope language-overridable
* @default false
*/
showAutocompleteSuggestions?: boolean;

/**
* Delay in ms after a document has changed before checking it for spelling errors.
* @scope application
Expand Down
35 changes: 30 additions & 5 deletions packages/client/src/autocomplete.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as vscode from 'vscode';
import { getCSpellDiags } from './diags';
import * as di from './di';
import { inspectConfigByScopeAndKey, getSettingFromVSConfig } from './settings/vsConfig';

// cspell:ignore bibtex doctex expl jlweave rsweave
// See [Issue #1450](https://github.com/streetsidesoftware/vscode-spell-checker/issues/1450)
const blockLangIdsForInlineCompletion = new Set(['tex', 'bibtex', 'latex', 'latex-expl3', 'jlweave', 'rsweave', 'doctex']);

export async function registerCspellInlineCompletionProviders(subscriptions: { dispose(): any }[]): Promise<void> {
const langIds = await vscode.languages.getLanguages();
const inlineCompletionLangIds = langIds.filter((lang) => !blockLangIdsForInlineCompletion.has(lang) && !lang.includes('latex'));
const inlineCompletionLangIds = await calcInlineCompletionIds();
subscriptions.push(
vscode.languages.registerCompletionItemProvider(inlineCompletionLangIds, cspellInlineCompletionProvider, ':'),
vscode.languages.registerCompletionItemProvider('*', cspellInlineCompletionProvider, ' '),
vscode.languages.registerCompletionItemProvider('*', cspellInlineDictionaryNameCompletionProvider, ' '),
vscode.languages.registerCompletionItemProvider('*', cspellInlineIssuesCompletionProvider, ' ')
vscode.languages.registerCompletionItemProvider(inlineCompletionLangIds, cspellInlineCompletionProvider, ' '),
vscode.languages.registerCompletionItemProvider(inlineCompletionLangIds, cspellInlineDictionaryNameCompletionProvider, ' '),
vscode.languages.registerCompletionItemProvider(inlineCompletionLangIds, cspellInlineIssuesCompletionProvider, ' ')
);
}

Expand Down Expand Up @@ -204,3 +204,28 @@ const cspellInlineIssuesCompletionProvider: vscode.CompletionItemProvider = {
return item;
},
};

interface ShowSuggestionsSettings {
value: boolean;
byLangId: Map<string, boolean>;
}

function getShowSuggestionsSettings(): ShowSuggestionsSettings {
const key = 'showAutocompleteSuggestions';
const setting = inspectConfigByScopeAndKey(undefined, key);
const byLangOverrideIds = setting.languageIds ?? [];

const value = getSettingFromVSConfig(key, undefined) ?? false;
const byLangOverrides = byLangOverrideIds.map(
(languageId) => [languageId, getSettingFromVSConfig(key, { languageId })] as [string, boolean]
);
const byLangId = new Map(byLangOverrides);
return { value, byLangId };
}

async function calcInlineCompletionIds(): Promise<string[]> {
const langIds = await vscode.languages.getLanguages();
const { value, byLangId } = getShowSuggestionsSettings();
const inlineCompletionLangIds = langIds.filter((lang) => byLangId.get(lang) ?? (!blockLangIdsForInlineCompletion.has(lang) && value));
return inlineCompletionLangIds;
}
1 change: 1 addition & 0 deletions packages/client/src/settings/configFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ConfigFields: CSpellUserSettingsFields = {
pnpFiles: 'pnpFiles',
readonly: 'readonly',
reporters: 'reporters',
showAutocompleteSuggestions: 'showAutocompleteSuggestions',
showCommandsInEditorContextMenu: 'showCommandsInEditorContextMenu',
showStatus: 'showStatus',
showStatusAlignment: 'showStatusAlignment',
Expand Down

0 comments on commit c5b0b7f

Please sign in to comment.