From 13a5216c7e5f79b04cb5d7ba44464797940f0d41 Mon Sep 17 00:00:00 2001 From: Darian Benam Date: Sat, 12 Aug 2023 21:37:26 -0400 Subject: [PATCH] Moved two event handlers into the `extensionEventHandlers` array --- src/Main.ts | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/Main.ts b/src/Main.ts index e13ac01..0376a24 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -23,6 +23,32 @@ const DIAGNOSTIC_COLLECTION: DiagnosticCollection = languages.createDiagnosticCo export function activate(context: ExtensionContext): void { const extensionEventHandlers: Disposable[] = [ + languages.registerDocumentFormattingEditProvider(ROBOTS_DOT_TXT_LANGUAGE_ID, { + provideDocumentFormattingEdits(document: TextDocument): TextEdit[] { + return formatRobotsDotTextDocument(document); + } + }), + workspace.onDidChangeConfiguration(event => { + const robotsDotTextExtensionConfigChanged: boolean = event.affectsConfiguration("robots.text"); + + if (!robotsDotTextExtensionConfigChanged) { + return; + } + + const isSyntaxAnalysisEnabled: boolean = isRobotsDotTextSyntaxAnalysisEnabled(); + + for (const document of workspace.textDocuments) { + if (document.languageId !== ROBOTS_DOT_TXT_LANGUAGE_ID) { + continue; + } + + if (isSyntaxAnalysisEnabled) { + analyzeRobotsDotTextConfig(document, DIAGNOSTIC_COLLECTION); + } else { + clearRobotsDotTextConfigDiagnosticIssues(document, DIAGNOSTIC_COLLECTION); + } + } + }), workspace.onDidChangeTextDocument(event => { const document: TextDocument = event.document; @@ -36,34 +62,6 @@ export function activate(context: ExtensionContext): void { context.subscriptions.push(...extensionEventHandlers); - languages.registerDocumentFormattingEditProvider(ROBOTS_DOT_TXT_LANGUAGE_ID, { - provideDocumentFormattingEdits(document: TextDocument): TextEdit[] { - return formatRobotsDotTextDocument(document); - } - }); - - workspace.onDidChangeConfiguration(event => { - const robotsDotTextExtensionConfigChanged: boolean = event.affectsConfiguration("robots.text"); - - if (!robotsDotTextExtensionConfigChanged) { - return; - } - - const isSyntaxAnalysisEnabled: boolean = isRobotsDotTextSyntaxAnalysisEnabled(); - - for (const document of workspace.textDocuments) { - if (document.languageId !== ROBOTS_DOT_TXT_LANGUAGE_ID) { - continue; - } - - if (isSyntaxAnalysisEnabled) { - analyzeRobotsDotTextConfig(document, DIAGNOSTIC_COLLECTION); - } else { - clearRobotsDotTextConfigDiagnosticIssues(document, DIAGNOSTIC_COLLECTION); - } - } - }); - const activeDocument: TextDocument | undefined = window.activeTextEditor?.document; if (activeDocument?.languageId === ROBOTS_DOT_TXT_LANGUAGE_ID) {