parent
d08f30ded4
commit
7cc28c3e81
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue