@@ -72,10 +72,61 @@ class AddToIgnoreLinksQuickFixProvider implements vscode.CodeActionProvider {
72
72
}
73
73
}
74
74
75
+ function registerMarkdownStatusItem ( selector : vscode . DocumentSelector , commandManager : CommandManager ) : vscode . Disposable {
76
+ const statusItem = vscode . languages . createLanguageStatusItem ( 'markdownStatus' , selector ) ;
77
+
78
+ const enabledSettingId = 'validate.enabled' ;
79
+ const commandId = '_markdown.toggleValidation' ;
80
+
81
+ const commandSub = commandManager . register ( {
82
+ id : commandId ,
83
+ execute : ( enabled : boolean ) => {
84
+ vscode . workspace . getConfiguration ( 'markdown' ) . update ( enabledSettingId , enabled ) ;
85
+ }
86
+ } ) ;
87
+
88
+ const update = ( ) => {
89
+ const activeDoc = vscode . window . activeTextEditor ?. document ;
90
+ const markdownDoc = activeDoc ?. languageId === 'markdown' ? activeDoc : undefined ;
91
+
92
+ const enabled = vscode . workspace . getConfiguration ( 'markdown' , markdownDoc ) . get ( enabledSettingId ) ;
93
+ if ( enabled ) {
94
+ statusItem . text = vscode . l10n . t ( 'Link validation enabled' ) ;
95
+ statusItem . command = {
96
+ command : commandId ,
97
+ arguments : [ false ] ,
98
+ title : vscode . l10n . t ( 'Disable' ) ,
99
+ tooltip : vscode . l10n . t ( 'Disable validation of Markdown links' ) ,
100
+ } ;
101
+ } else {
102
+ statusItem . text = vscode . l10n . t ( 'Link validation disabled' ) ;
103
+ statusItem . command = {
104
+ command : commandId ,
105
+ arguments : [ true ] ,
106
+ title : vscode . l10n . t ( 'Enable' ) ,
107
+ tooltip : vscode . l10n . t ( 'Enable validation of Markdown links' ) ,
108
+ } ;
109
+ }
110
+ } ;
111
+ update ( ) ;
112
+
113
+ return vscode . Disposable . from (
114
+ statusItem ,
115
+ commandSub ,
116
+ vscode . workspace . onDidChangeConfiguration ( e => {
117
+ if ( e . affectsConfiguration ( 'markdown.' + enabledSettingId ) ) {
118
+ update ( ) ;
119
+ }
120
+ } ) ,
121
+ ) ;
122
+ }
75
123
76
124
export function registerDiagnosticSupport (
77
125
selector : vscode . DocumentSelector ,
78
126
commandManager : CommandManager ,
79
127
) : vscode . Disposable {
80
- return AddToIgnoreLinksQuickFixProvider . register ( selector , commandManager ) ;
128
+ return vscode . Disposable . from (
129
+ AddToIgnoreLinksQuickFixProvider . register ( selector , commandManager ) ,
130
+ registerMarkdownStatusItem ( selector , commandManager ) ,
131
+ ) ;
81
132
}
0 commit comments