Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CSpell REPL #3109

Merged
merged 27 commits into from Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.js
Expand Up @@ -34,6 +34,8 @@ const config = {
'**/build/**',
'package-lock.json',
'**/scripts/ts-json-schema-generator.cjs',
'**/fixtures/**/*.js',
'**/webpack*.js',
],
plugins: ['import', 'unicorn', 'simple-import-sort'],
rules: {
Expand All @@ -57,7 +59,7 @@ const config = {
},
overrides: [
{
files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.tsx'],
files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.tsx', '**/*.js', '**/*.mjs'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:import/typescript'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
Expand Down
6 changes: 6 additions & 0 deletions cspell-words.txt
@@ -1,4 +1,5 @@
# Project Words
abortable
acanthopterygious
activitybar
aeiouy
Expand Down Expand Up @@ -63,13 +64,16 @@ nohoist
noreply
nospace
onfinally
optionator
outfile
overridable
OVSX
paginator
permalinks
Positionals
Preformat
preinstall
Pseudoterminal
quickfix
quotemark
readonly
Expand All @@ -95,6 +99,8 @@ tsbuildInfo
tslib
typechecking
unelevated
unindented
unindents
untracked
untrusted
uri's
Expand Down
3 changes: 3 additions & 0 deletions cspell.config.yaml
Expand Up @@ -53,6 +53,9 @@ overrides:
ignoreWords:
- colour
- canot
- filename: '**/*.test.*'
dictionaries:
- lorem-ipsum
useGitignore: true
words:
- dbaeumer
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/generated-docs/commands.md
Expand Up @@ -19,6 +19,7 @@
| `cSpell.addWordToWorkspaceSettings` | Add Words to Workspace Settings |
| `cSpell.autoFixSpellingIssues` | Fix all issues with a preferred suggestion in the current document. |
| `cSpell.createCSpellConfig` | Create a CSpell Configuration File. |
| `cSpell.createCSpellTerminal` | Create CSpell REPL Terminal |
| `cSpell.createCustomDictionary` | Create a Custom Dictionary File. |
| `cSpell.disableCurrentFileType` | Disable Spell Checking File Type |
| `cSpell.disableCurrentLanguage` | Disable Spell Checking Document Language |
Expand Down
@@ -1,7 +1,10 @@
// eslint-disable-next-line node/no-unpublished-require
const package = require('../../package.json');
import { createRequire } from 'module';

const commands = package.contributes.commands;
const require = createRequire(import.meta.url);

const pkgJson = require('../../package.json');

const commands = pkgJson.contributes.commands;

const compare = new Intl.Collator().compare;

Expand Down
6 changes: 6 additions & 0 deletions docs/_scripts/package.json
@@ -0,0 +1,6 @@
{
"type": "commonjs",
"engines": {
"node": ">=18"
}
}
2 changes: 1 addition & 1 deletion docs/package.json
Expand Up @@ -11,7 +11,7 @@
"test": "echo Skip Docs",
"gen-docs": "npm run gen-config-docs && npm run gen-command-docs && npm run lint",
"gen-config-docs": "node _scripts/extract-config.mjs > _includes/generated-docs/configuration.md",
"gen-command-docs": "node _scripts/extract-commands.js > _includes/generated-docs/commands.md",
"gen-command-docs": "node _scripts/extract-commands.mjs > _includes/generated-docs/commands.md",
"lint": "prettier -w \"**/*.{md,markdown,yaml,yml,json,html,htm,js}\"",
"serve": "bundle exec jekyll serve"
},
Expand Down
91 changes: 77 additions & 14 deletions package-lock.json

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

6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -565,6 +565,12 @@
"category": "Spell",
"title": "Toggle Trace Mode",
"icon": "$(search)"
},
{
"command": "cSpell.createCSpellTerminal",
"category": "Spell",
"title": "Create CSpell REPL Terminal",
"icon": "$(terminal)"
}
],
"languages": [
Expand Down
22 changes: 17 additions & 5 deletions packages/_server/src/DocumentValidationController.mts
Expand Up @@ -33,13 +33,21 @@ export class DocumentValidationController {
return this.docValMap.get(doc.uri);
}

getDocumentValidator(docInfo: TextDocumentInfoWithText | TextDocument) {
delete(doc: TextDocumentRef) {
this.docValMap.delete(doc.uri);
}

getDocumentValidator(docInfo: TextDocumentInfoWithText | TextDocument, cache = true) {
const uri = docInfo.uri;
const docValEntry = this.docValMap.get(uri);
if (docValEntry) return docValEntry.docVal;
if (docValEntry) {
return docValEntry.docVal;
}

const entry = this.createDocValEntry(docInfo);
this.docValMap.set(uri, entry);
if (cache) {
this.docValMap.set(uri, entry);
}
return entry.docVal;
}

Expand All @@ -61,15 +69,18 @@ export class DocumentValidationController {
}

private handleOnDidClose(e: TextDocumentChangeEvent<TextDocument>) {
this.docValMap.delete(e.document.uri);
this.delete(e.document);
}

private handleOnDidChangeContent(e: TextDocumentChangeEvent<TextDocument>) {
this._handleOnDidChangeContent(e).catch(() => undefined);
}

private async _handleOnDidChangeContent(e: TextDocumentChangeEvent<TextDocument>) {
const { document } = e;
await this.updateDocument(e.document);
}

async updateDocument(document: TextDocument) {
const entry = this.docValMap.get(document.uri);
if (!entry) return;
const { settings, docVal } = entry;
Expand All @@ -80,6 +91,7 @@ export class DocumentValidationController {
return;
}
await _docVal.updateDocumentText(document.getText());
return _docVal;
}
}

Expand Down