Skip to content

Commit

Permalink
dev: Progress towards viewing Spell Checker information. (#2829)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Sep 24, 2023
1 parent f810117 commit ae0f6cf
Show file tree
Hide file tree
Showing 44 changed files with 699 additions and 552 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ indent_size = 2

[*.tsx]
indent_size = 2

[*.svelte]
indent_size = 2
48 changes: 0 additions & 48 deletions .prettierrc.json

This file was deleted.

32 changes: 32 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
printWidth: 140
plugins:
- prettier-plugin-svelte
singleQuote: true
tabWidth: 4
endOfLine: lf
overrides:
- files: "**/*.{yaml,yml}"
options:
tabWidth: 2
singleQuote: false
- files: "**/*.svelte"
options:
tabWidth: 2
- files: "**/*.json"
options:
tabWidth: 4
singleQuote: false
- files: "**/*.schema.json"
options:
tabWidth: 2
singleQuote: false
- files: "**/package.json"
options:
tabWidth: 2
singleQuote: false
- files: packages/_settingsViewer/src/test/**
options:
printWidth: 280
- files: packages/client/src/**/configUpdater.ts
options:
printWidth: 200
4 changes: 0 additions & 4 deletions Spell Checker.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
"name": "Settings Viewer",
"path": "packages/_settingsViewer"
},
{
"name": "Settings Viewer Next",
"path": "packages/_settingsViewerNext"
},
{
"name": "Integration Tests",
"path": "packages/_integrationTests"
Expand Down
27 changes: 11 additions & 16 deletions package-lock.json

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

22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,37 +171,42 @@
"viewsContainers": {
"activitybar": [
{
"id": "cspell-explorer",
"id": "cspell-regexp-explorer",
"title": "Spell Checker Info",
"icon": "resources/dark/check_circle.svg",
"when": "config.cSpell.experimental.enableRegexpView"
},
{
"id": "hello-world-todo-explorer",
"id": "cspell-info-explorer",
"title": "Todo Example",
"icon": "resources/todo-list.svg"
}
]
},
"views": {
"cspell-explorer": [
"cspell-regexp-explorer": [
{
"id": "cSpellRegExpView",
"name": "Regular Expressions",
"when": "config.cSpell.experimental.enableRegexpView"
}
],
"hello-world-todo-explorer": [
"cspell-info-explorer": [
{
"type": "webview",
"id": "hello-world-svelte.todoView",
"id": "cspell-info.infoView",
"name": "Spell Checker"
},
{
"type": "webview",
"id": "cspell-info.todoView",
"name": "Todo Webview"
}
]
},
"commands": [
{
"command": "hello-world-svelte.showHelloWorld",
"command": "cspell-info.showHelloWorld",
"title": "Hello World (Svelte): Show",
"enablement": "config.cSpell.experimental.enableSettingsViewerV2",
"category": "Spell"
Expand Down Expand Up @@ -2556,7 +2561,7 @@
"build-release": "npm run build && npm run package-extension",
"gen-docs": "npm --workspace=@internal/docs run gen-docs",
"package-extension": "vsce package -o ./build",
"prettier:check": "prettier \"**/*.{ts,tsx,js,json,md}\" -c",
"prettier:check": "prettier \"**/*.{ts,tsx,js,json,md,svelte}\" -c",
"prettier:fix": "npm run prettier:check -- -w",
"prettier:fix-schema": "prettier -w \"**/*.schema.json\"",
"test-vsce-build": "shx mkdir -p temp && vsce package -o ./temp/code-spell-checker.vsix",
Expand All @@ -2567,7 +2572,7 @@
"lint-docs": "prettier -w \"docs/**/*.{md,markdown,yaml,yml,json,html,htm,js,ts}\"",
"lint-docs-ci": "prettier -c \"docs/**/*.{md,markdown,yaml,yml,json,html,htm,js,ts}\"",
"test-client-integration": "npm --workspace=@internal/integration-tests run test-integration",
"test": "npm --workspaces run test",
"test": "npm --workspaces run test && echo OK",
"update-packages": "npx npm-check-updates --root -ws --target semver -u && npm i",
"preinstall": "npx only-allow npm"
},
Expand Down Expand Up @@ -2600,6 +2605,7 @@
"jest-when": "^3.6.0",
"ovsx": "^0.8.3",
"prettier": "^3.0.3",
"prettier-plugin-svelte": "^3.0.3",
"rollup": "^3.29.3",
"rollup-plugin-dts": "^6.0.2",
"shx": "^0.3.4",
Expand Down
61 changes: 38 additions & 23 deletions packages/client/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ import { setOfSupportedSchemes, supportedSchemes } from '@internal/common-utils/
import type { WorkspaceConfigForDocument } from 'code-spell-checker-server/api';
import type { Command, Diagnostic, DiagnosticCollection, ExtensionContext, Position, Range, TextDocument } from 'vscode';
import { CodeAction, CodeActionKind, DiagnosticSeverity, Disposable, languages as vsCodeSupportedLanguages, Uri, workspace } from 'vscode';
import type { ForkOptions, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
import * as VSCodeLangClient from 'vscode-languageclient/node';
import { LanguageClient, TransportKind } from 'vscode-languageclient/node';
import type {
CodeActionParams,
Command as LanguageClientCommand,
ForkOptions,
LanguageClientOptions,
ServerOptions,
} from 'vscode-languageclient/node';
import {
CodeAction as VSCodeLangClientCodeAction,
CodeActionContext as VSCodeLangClientCodeActionContext,
Diagnostic as VSCodeLangClientDiagnostic,
DiagnosticSeverity as VSCodeLangClientDiagnosticSeverity,
LanguageClient,
Position as VSCodeLangClientPosition,
Range as VSCodeLangClientRange,
TextDocumentIdentifier as VSCodeLangClientTextDocumentIdentifier,
TransportKind as VSCodeLangClientTransportKind,
} from 'vscode-languageclient/node';

import { diagnosticSource } from '../constants';
import type { Inspect } from '../settings';
Expand Down Expand Up @@ -99,8 +114,8 @@ export class CSpellClient implements Disposable {
// If the extension is launched in debug mode the debug server options are use
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { module, transport: TransportKind.ipc, options },
debug: { module, transport: TransportKind.ipc, options: debugOptions },
run: { module, transport: VSCodeLangClientTransportKind.ipc, options },
debug: { module, transport: VSCodeLangClientTransportKind.ipc, options: debugOptions },
};

// Create the language client and start the client.
Expand Down Expand Up @@ -217,10 +232,10 @@ export class CSpellClient implements Disposable {
}

public async requestSpellingSuggestions(doc: TextDocument, range: Range, diagnostics: Diagnostic[]): Promise<CodeAction[]> {
const params: VSCodeLangClient.CodeActionParams = {
textDocument: VSCodeLangClient.TextDocumentIdentifier.create(doc.uri.toString()),
const params: CodeActionParams = {
textDocument: VSCodeLangClientTextDocumentIdentifier.create(doc.uri.toString()),
range: mapRangeToLangClient(range),
context: VSCodeLangClient.CodeActionContext.create(diagnostics.map(mapDiagnosticToLangClient)),
context: VSCodeLangClientCodeActionContext.create(diagnostics.map(mapDiagnosticToLangClient)),
};
const r = await requestCodeAction(this.client, params);
if (!r) return [];
Expand Down Expand Up @@ -287,34 +302,34 @@ function toConfigTarget<T>(ins: Inspect<T> | undefined, allowFolder: boolean): F
};
}

function isCodeAction(c: VSCodeLangClient.Command | VSCodeLangClient.CodeAction): c is VSCodeLangClient.CodeAction {
return VSCodeLangClient.CodeAction.is(c);
function isCodeAction(c: LanguageClientCommand | VSCodeLangClientCodeAction): c is VSCodeLangClientCodeAction {
return VSCodeLangClientCodeAction.is(c);
}

function mapCodeAction(c: VSCodeLangClient.CodeAction): CodeAction {
function mapCodeAction(c: VSCodeLangClientCodeAction): CodeAction {
const kind = (c.kind !== undefined && CodeActionKind.Empty.append(c.kind)) || undefined;
const action = new CodeAction(c.title, kind);
action.command = c.command && mapCommand(c.command);
return action;
}

function mapCommand(c: VSCodeLangClient.Command): Command {
function mapCommand(c: LanguageClientCommand): Command {
return c;
}

type MapDiagnosticSeverity = {
[key in DiagnosticSeverity]: VSCodeLangClient.DiagnosticSeverity;
[key in DiagnosticSeverity]: VSCodeLangClientDiagnosticSeverity;
};

const diagSeverityMap: MapDiagnosticSeverity = {
[DiagnosticSeverity.Error]: VSCodeLangClient.DiagnosticSeverity.Error,
[DiagnosticSeverity.Warning]: VSCodeLangClient.DiagnosticSeverity.Warning,
[DiagnosticSeverity.Information]: VSCodeLangClient.DiagnosticSeverity.Information,
[DiagnosticSeverity.Hint]: VSCodeLangClient.DiagnosticSeverity.Hint,
[DiagnosticSeverity.Error]: VSCodeLangClientDiagnosticSeverity.Error,
[DiagnosticSeverity.Warning]: VSCodeLangClientDiagnosticSeverity.Warning,
[DiagnosticSeverity.Information]: VSCodeLangClientDiagnosticSeverity.Information,
[DiagnosticSeverity.Hint]: VSCodeLangClientDiagnosticSeverity.Hint,
};

function mapDiagnosticToLangClient(d: Diagnostic): VSCodeLangClient.Diagnostic {
const diag = VSCodeLangClient.Diagnostic.create(
function mapDiagnosticToLangClient(d: Diagnostic): VSCodeLangClientDiagnostic {
const diag = VSCodeLangClientDiagnostic.create(
mapRangeToLangClient(d.range),
d.message,
diagSeverityMap[d.severity],
Expand All @@ -324,12 +339,12 @@ function mapDiagnosticToLangClient(d: Diagnostic): VSCodeLangClient.Diagnostic {
return diag;
}

function mapRangeToLangClient(r: Range): VSCodeLangClient.Range {
function mapRangeToLangClient(r: Range): VSCodeLangClientRange {
const { start, end } = r;
return VSCodeLangClient.Range.create(mapPositionToLangClient(start), mapPositionToLangClient(end));
return VSCodeLangClientRange.create(mapPositionToLangClient(start), mapPositionToLangClient(end));
}

function mapPositionToLangClient(p: Position): VSCodeLangClient.Position {
function mapPositionToLangClient(p: Position): VSCodeLangClientPosition {
const { line, character } = p;
return VSCodeLangClient.Position.create(line, character);
return VSCodeLangClientPosition.create(line, character);
}
1 change: 0 additions & 1 deletion packages/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { initStatusBar } from './statusbar';
import { logErrors, silenceErrors } from './util/errors';
import { performance } from './util/perf';
import { activate as activateWebview } from './webview';
// import { activate as settingsViewerActivate } from 'settings-viewer-next';

performance.mark('cspell_done_import');

Expand Down
Loading

0 comments on commit ae0f6cf

Please sign in to comment.