Skip to content

Commit

Permalink
fix: Make sure commit message issues work (#3956)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Dec 22, 2024
1 parent 3b8eef7 commit 9e76cde
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/_server/src/server.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
isUriBlockedBySettings,
stringifyPatterns,
} from './config/documentSettings.mjs';
import { isUrlIncludedByDefault } from './config/docUriHelper.mjs';
import { isFileTypeEnabled } from './config/extractEnabledFileTypes.mjs';
import { sanitizeSettings } from './config/sanitizeSettings.mjs';
import type { TextDocumentUri } from './config/vscode.config.mjs';
Expand Down Expand Up @@ -592,6 +593,7 @@ export function run(): void {
};
}
async function isUriExcluded(uri: string): Promise<boolean> {
if (isUrlIncludedByDefault(uri)) return false;
const ie = await calcFileIncludeExclude(uri);
return !ie.include || ie.exclude || !!ie.ignored;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/actionMenu.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Disposable, QuickPickItem } from 'vscode';
import vscode from 'vscode';

import { knownCommands } from './commands.mjs';
import { extensionId } from './constants.js';
import { getClient } from './di.mjs';
import { updateEnabledFileTypeForResource, updateEnabledSchemesResource } from './settings/settings.mjs';
import { handleErrors } from './util/errors.js';
Expand Down Expand Up @@ -57,7 +58,7 @@ async function actionMenu(options: ActionsMenuOptions) {
command: 'workbench.action.openGlobalKeybindings',
arguments: ['Spell:'],
}),
itemCommand({ title: '$(gear) Edit Settings...', command: 'workbench.action.openSettings', arguments: ['cSpell'] }),
itemCommand({ title: '$(gear) Edit Settings...', command: 'workbench.action.openSettings', arguments: [extensionId] }),
].filter(isDefined);

return quickPickMenu({ items, title: 'Spell Checker Actions Menu' }).catch(() => undefined);
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/client/client.mts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CSpellClient implements Disposable {
},
middleware: {
handleDiagnostics(uri, diagnostics, next) {
// console.error(`${new Date().toISOString()} Client handleDiagnostics: ${uri.toString()}`);
logger.log(`${new Date().toISOString()} Client handleDiagnostics: ${uri.toString()}`);
next(uri, diagnostics);
},
},
Expand Down
9 changes: 5 additions & 4 deletions packages/client/src/decorators/decorateIssues.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import vscode, { ColorThemeKind, MarkdownString, Range, window, workspace } from

import type { PartialCSpellUserSettings } from '../client/index.mjs';
import { commandUri, createTextEditCommand } from '../commands.mjs';
import { extensionId } from '../constants.js';
import type { Disposable } from '../disposable.js';
import type { IssueTracker, SpellingCheckerIssue } from '../issueTracker.mjs';
import type { CSpellSettings } from '../settings/index.mjs';
Expand Down Expand Up @@ -209,7 +210,7 @@ export class SpellingIssueDecorator implements Disposable {
}

private getConfiguration() {
const cfg = workspace.getConfiguration('cSpell') as PartialCSpellUserSettings<
const cfg = workspace.getConfiguration(extensionId) as PartialCSpellUserSettings<
'hideIssuesWhileTyping' | 'revealIssuesAfterDelayMS' | 'doNotUseCustomDecorationForScheme'
>;
this.hideIssuesWhileTyping = cfg.hideIssuesWhileTyping ?? defaultHideIssuesWhileTyping;
Expand Down Expand Up @@ -237,11 +238,11 @@ export class SpellingIssueDecorator implements Disposable {
}
| undefined {
this.clearDecoration();
const useCustomDecorations = this.visible && (workspace.getConfiguration('cSpell').get<boolean>('useCustomDecorations') ?? true);
const useCustomDecorations = this.visible && (workspace.getConfiguration(extensionId).get<boolean>('useCustomDecorations') ?? true);
if (!useCustomDecorations) return undefined;

const mode = calcMode(window.activeColorTheme.kind);
const cfg = workspace.getConfiguration('cSpell') as PartialCSpellUserSettings<
const cfg = workspace.getConfiguration(extensionId) as PartialCSpellUserSettings<
| 'dark'
| 'doNotUseCustomDecorationForScheme'
| 'hideIssuesWhileTyping'
Expand Down Expand Up @@ -362,7 +363,7 @@ export class SpellingIssueDecorator implements Disposable {
}

#onConfigChange(e: vscode.ConfigurationChangeEvent) {
if (!e.affectsConfiguration('cSpell')) return;
if (!e.affectsConfiguration(extensionId)) return;
this.resetDecorator();
}

Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/decorators/traceDecorations.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { TextEditorDecorationType } from 'vscode';
import vscode from 'vscode';

import type { CSpellClient } from '../client/index.mjs';
import { extensionId } from '../constants.js';
import type { Disposable } from '../disposable.js';
import { createEmitter, map, pipe, throttle } from '../Subscribables/index.js';
import { logError } from '../util/errors.js';
Expand All @@ -27,7 +28,7 @@ export class SpellingExclusionsDecorator implements Disposable {
this.disposables.push(
() => this.clearDecoration(),
vscode.window.onDidChangeActiveTextEditor((e) => this.refreshEditor(e)),
vscode.workspace.onDidChangeConfiguration((e) => e.affectsConfiguration('cSpell') && this.refreshEditor(undefined)),
vscode.workspace.onDidChangeConfiguration((e) => e.affectsConfiguration(extensionId) && this.refreshEditor(undefined)),
vscode.workspace.onDidChangeTextDocument((e) => this.refreshDocument(e.document)),
vscode.languages.registerHoverProvider('*', this.getHoverProvider()),
pipe(
Expand Down
6 changes: 3 additions & 3 deletions packages/client/src/diags.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createDisposableList } from 'utils-disposables';
import type { Diagnostic, Disposable, Event, Range, Selection, TabChangeEvent, TextDocument, TextEditor, Uri } from 'vscode';
import vscode from 'vscode';

import { diagnosticSource } from './constants.js';
import { diagnosticSource, extensionId } from './constants.js';
import { getDependencies } from './di.mjs';
import type { SpellingDiagnostic } from './issueTracker.mjs';
import type { CSpellSettings } from './settings/CSpellSettings.mjs';
Expand Down Expand Up @@ -88,12 +88,12 @@ function determineWordRangeToAddToDictionaryFromSelection(
export function registerDiagWatcher(show: boolean, onShowChange: Event<boolean>): Disposable {
const dList = createDisposableList();
const issueTracker = getDependencies().issueTracker;
const collection = vscode.languages.createDiagnosticCollection('cSpell');
const collection = vscode.languages.createDiagnosticCollection(diagnosticSource);
let overrides: CSpellSettings[typeof ConfigFields.doNotUseCustomDecorationForScheme];
let useDiagnosticCollection = true;

function updateConfig() {
const cfg = vscode.workspace.getConfiguration('cSpell');
const cfg = vscode.workspace.getConfiguration(extensionId);
useDiagnosticCollection = !cfg.get(ConfigFields.useCustomDecorations);
overrides = cfg.get(ConfigFields.doNotUseCustomDecorationForScheme);
}
Expand Down
2 changes: 0 additions & 2 deletions packages/client/src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ async function _activate(context: ExtensionContext, eIssueTracker: vscode.EventE
dataFileDirUri: vscode.Uri.joinPath(dataFileUri, '..').toJSON(),
workspaceState: context.workspaceState.keys(),
globalState: context.globalState.keys(),
// contextKeys: cki.filter((k) => k.key.startsWith('cSpell')),
// commands: commands.filter((c) => c.toLowerCase().includes('command')),
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/client/src/issueViewer/IssueTreeItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export abstract class IssueTreeItemBase {
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
abstract getChildren(): ProviderResult<IssueTreeItemBase[]>;
abstract getParent(): ProviderResult<IssueTreeItemBase>;
abstract toString(): string;
}
17 changes: 17 additions & 0 deletions packages/client/src/issueViewer/issuesViewerByFile.mts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ class FileWithIssuesTreeItem extends IssueTreeItemBase {
this.targets = this.context.issueTracker.getConfigurationTargets(this.document.uri).then((r) => ({ targets: r.configTargets }));
return this.targets;
};

toString(): string {
return `FileWithIssuesTreeItem: ${this.document.uri.toString()}`;
}
}

class FileIssueTreeItem extends IssueTreeItemBase {
Expand Down Expand Up @@ -413,6 +417,7 @@ class FileIssueTreeItem extends IssueTreeItemBase {
getChildren() {
if (this.children) return this.children;
this.pChildren ??= this.#getChildren();
return undefined;
}

async #getChildren() {
Expand Down Expand Up @@ -447,6 +452,10 @@ class FileIssueTreeItem extends IssueTreeItemBase {
// return md;
}

toString(): string {
return `FileIssueTreeItem: ${this.issue.diag.message}`;
}

static compare(a: FileIssueTreeItem, b: FileIssueTreeItem) {
const cellComp = a.cellIndex - b.cellIndex;
if (cellComp) return cellComp;
Expand Down Expand Up @@ -499,6 +508,10 @@ class IssueSuggestionTreeItem extends IssueTreeItemBase {
isPreferred(): boolean {
return this.suggestion.isPreferred || false;
}

toString(): string {
return `IssueSuggestionTreeItem: ${this.issue.word} -> ${this.suggestion.word}`;
}
}

class IssueAddToTargetTreeItem extends IssueTreeItemBase {
Expand Down Expand Up @@ -544,6 +557,10 @@ class IssueAddToTargetTreeItem extends IssueTreeItemBase {
'addWordsToConfig',
);
}

toString(): string {
return `IssueAddToTargetTreeItem: ${this.issue.word} to ${this.target.name}`;
}
}

interface FileIssue {
Expand Down
20 changes: 20 additions & 0 deletions packages/client/src/issueViewer/unknownWordsViewer.mts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ class WordIssueTreeItem extends IssueTreeItemBase {
this.suggestions = gatherSuggestions(this.suggestionsByDocument);
this.context.invalidate(this);
}

toString(): string {
return `WordIssueTreeItem ${this.word}`;
}
}

class IssueLocationsTreeItem extends IssueTreeItemBase {
Expand All @@ -338,6 +342,10 @@ class IssueLocationsTreeItem extends IssueTreeItemBase {
getParent(): IssueTreeItemBase | undefined {
return this.parent;
}

toString(): string {
return `IssueLocationsTreeItem ${this.word}`;
}
}

class IssueFixesTreeItem extends IssueTreeItemBase {
Expand All @@ -363,6 +371,10 @@ class IssueFixesTreeItem extends IssueTreeItemBase {
getParent(): IssueTreeItemBase | undefined {
return this.parent;
}

toString(): string {
return `IssueFixesTreeItem ${this.word}`;
}
}

class IssueLocationTreeItem extends IssueTreeItemBase {
Expand Down Expand Up @@ -410,6 +422,10 @@ class IssueLocationTreeItem extends IssueTreeItemBase {
return this.issue.range;
}

toString(): string {
return `IssueLocationTreeItem ${this.issue.word}`;
}

static compare(a: IssueLocationTreeItem, b: IssueLocationTreeItem) {
const uriA = a.cell?.document.uri || a.doc.uri;
const uriB = b.cell?.document.uri || b.doc.uri;
Expand Down Expand Up @@ -478,6 +494,10 @@ class IssueSuggestionTreeItem extends IssueTreeItemBase {
isPreferred(): boolean {
return this.suggestion.isPreferred || false;
}

toString(): string {
return `IssueSuggestionTreeItem ${this.word}`;
}
}

function collectIssues(context: Context): WordIssueTreeItem[] {
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/statusbar/languageStatus.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import vscode from 'vscode';

import type { ServerResponseIsSpellCheckEnabledForFile } from '../client/client.mjs';
import { knownCommands } from '../commands.mjs';
import { extensionId } from '../constants.js';
import { getClient, getIssueTracker } from '../di.mjs';
import type { IssuesStats } from '../issueTracker.mjs';
import { handleErrors } from '../util/errors.js';
Expand All @@ -28,7 +29,7 @@ export function createLanguageStatus(options: LanguageStatusOptions): Disposable
dList.push(vscode.window.onDidChangeActiveTextEditor(queueUpdate));
dList.push(
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('cSpell')) queueUpdate();
if (e.affectsConfiguration(extensionId)) queueUpdate();
}),
);
dList.push(getIssueTracker().onDidChangeDiagnostics(() => updateNow()));
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/storage/context.mts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function _setContext(context: ContextTypes): Promise<void> {
* @param prefix - optional prefix to use for the context keys
*/
export async function setContext(context: ContextTypes, prefix = 'cSpell.context'): Promise<void> {
assert(prefix.startsWith('cSpell'));
assert(prefix.startsWith(extensionId));
const kvpValues = [...flatten(prefix, context)];
const filteredKvpValues = kvpValues.filter(([k, v]) => v !== currentContext.get(k));

Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/vscode/createIsUriVisibleFilter.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { type Uri, window } from 'vscode';

import { findTabsWithUriInput } from './tabs.mjs';

const alwaysVisibleSchemes = new Set(['vscode-scm']);

export function createIsUriVisibleFilter(onlyVisible: boolean): (uri: Uri) => boolean {
if (!onlyVisible) return () => true;
// Use the path to avoid scheme issues.
Expand All @@ -12,7 +14,7 @@ export function createIsUriVisibleFilter(onlyVisible: boolean): (uri: Uri) => bo
...window.visibleTextEditors.map((e) => e.document.uri.toString()),
]);
return (uri: Uri) => {
const h = visibleUris.has(uri.toString());
const h = visibleUris.has(uri.toString()) || alwaysVisibleSchemes.has(uri.scheme);
// console.log('isUriVisible', uri.toString(), h);
return h;
};
Expand Down

0 comments on commit 9e76cde

Please sign in to comment.