Skip to content

Commit

Permalink
Moved two event handlers into the extensionEventHandlers array
Browse files Browse the repository at this point in the history
  • Loading branch information
BeardedFish committed Aug 13, 2023
1 parent 01abf37 commit 13a5216
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit 13a5216

Please sign in to comment.