Add markdown validation status item

Fixes #236399
pull/236400/head
Matt Bierner 2024-12-17 11:30:32 -08:00
parent d08f30ded4
commit 7cc28c3e81
1 changed files with 52 additions and 1 deletions

View File

@ -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),
);
}