Skip to content

Commit

Permalink
Add markdown validation status item
Browse files Browse the repository at this point in the history
Fixes #236399
  • Loading branch information
mjbvz committed Dec 17, 2024
1 parent d08f30d commit 7cc28c3
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,61 @@ class AddToIgnoreLinksQuickFixProvider implements vscode.CodeActionProvider {
}
}

function registerMarkdownStatusItem(selector: vscode.DocumentSelector, commandManager: CommandManager): vscode.Disposable {
const statusItem = vscode.languages.createLanguageStatusItem('markdownStatus', selector);

const enabledSettingId = 'validate.enabled';
const commandId = '_markdown.toggleValidation';

const commandSub = commandManager.register({
id: commandId,
execute: (enabled: boolean) => {
vscode.workspace.getConfiguration('markdown').update(enabledSettingId, enabled);
}
});

const update = () => {
const activeDoc = vscode.window.activeTextEditor?.document;
const markdownDoc = activeDoc?.languageId === 'markdown' ? activeDoc : undefined;

const enabled = vscode.workspace.getConfiguration('markdown', markdownDoc).get(enabledSettingId);
if (enabled) {
statusItem.text = vscode.l10n.t('Link validation enabled');
statusItem.command = {
command: commandId,
arguments: [false],
title: vscode.l10n.t('Disable'),
tooltip: vscode.l10n.t('Disable validation of Markdown links'),
};
} else {
statusItem.text = vscode.l10n.t('Link validation disabled');
statusItem.command = {
command: commandId,
arguments: [true],
title: vscode.l10n.t('Enable'),
tooltip: vscode.l10n.t('Enable validation of Markdown links'),
};
}
};
update();

return vscode.Disposable.from(
statusItem,
commandSub,
vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('markdown.' + enabledSettingId)) {
update();
}
}),
);
}

export function registerDiagnosticSupport(
selector: vscode.DocumentSelector,
commandManager: CommandManager,
): vscode.Disposable {
return AddToIgnoreLinksQuickFixProvider.register(selector, commandManager);
return vscode.Disposable.from(
AddToIgnoreLinksQuickFixProvider.register(selector, commandManager),
registerMarkdownStatusItem(selector, commandManager),
);
}

0 comments on commit 7cc28c3

Please sign in to comment.