diff --git a/src/diagnostics.ts b/src/diagnostics.ts index d284628..58e87d2 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -1,7 +1,7 @@ // Diagnostics (warnings and errors) "use strict"; -import { Diagnostic, DiagnosticCollection, DiagnosticSeverity, ExtensionContext, Range, TextDocument, window, workspace } from "vscode"; +import { commands, Diagnostic, DiagnosticCollection, DiagnosticSeverity, ExtensionContext, languages, Range, TextDocument, window, workspace } from "vscode"; import { NavigationData } from "./navigation-data"; import { extractFilename } from "./workspace"; @@ -52,12 +52,31 @@ const rxStoreCheck = /\s+store\.(\w+)[^a-zA-Z_]?/g; const rxTabCheck = /^(\t+)/g; const rsComparisonCheck = /\s+(if|while)\s+(\w+)\s*(=)\s*(\w+)\s*/g; +/** + * Set up diagnostics + * @param context extension context + */ +export function diagnosticsInit(context: ExtensionContext) { + const diagnostics = languages.createDiagnosticCollection("renpy"); + context.subscriptions.push(diagnostics); + + // custom command - refresh diagnostics + const refreshDiagnosticsCommand = commands.registerCommand("renpy.refreshDiagnostics", () => { + if (window.activeTextEditor) { + refreshDiagnostics(window.activeTextEditor.document, diagnostics); + } + }); + context.subscriptions.push(refreshDiagnosticsCommand); + + subscribeToDocumentChanges(context, diagnostics); +} + /** * Analyzes the text document for problems. * @param doc text document to analyze * @param diagnostics diagnostic collection */ -export function refreshDiagnostics(doc: TextDocument, diagnosticCollection: DiagnosticCollection): void { +function refreshDiagnostics(doc: TextDocument, diagnosticCollection: DiagnosticCollection): void { if (doc.languageId !== "renpy") { return; } @@ -167,7 +186,7 @@ export function refreshDiagnostics(doc: TextDocument, diagnosticCollection: Diag diagnosticCollection.set(doc.uri, diagnostics); } -export function subscribeToDocumentChanges(context: ExtensionContext, diagnostics: DiagnosticCollection): void { +function subscribeToDocumentChanges(context: ExtensionContext, diagnostics: DiagnosticCollection): void { if (window.activeTextEditor) { refreshDiagnostics(window.activeTextEditor.document, diagnostics); } diff --git a/src/extension.ts b/src/extension.ts index 9f04b2f..4a47704 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -43,7 +43,7 @@ import { import { RenpyColorProvider } from "./color"; import { getStatusBarText, NavigationData } from "./navigation-data"; import { cleanUpPath, getAudioFolder, getImagesFolder, getNavigationJsonFilepath, getWorkspaceFolder, stripWorkspaceFromFile } from "./workspace"; -import { refreshDiagnostics, subscribeToDocumentChanges } from "./diagnostics"; +import { diagnosticsInit } from "./diagnostics"; import { getSemanticTokens } from "./semantics"; import { getHover } from "./hover"; import { getCompletionList } from "./completion"; @@ -212,9 +212,7 @@ export async function activate(context: ExtensionContext): Promise { ); // diagnostics (errors and warnings) - const diagnostics = languages.createDiagnosticCollection("renpy"); - context.subscriptions.push(diagnostics); - subscribeToDocumentChanges(context, diagnostics); + diagnosticsInit(context); // custom command - refresh data const refreshCommand = commands.registerCommand("renpy.refreshNavigationData", async () => { @@ -241,14 +239,6 @@ export async function activate(context: ExtensionContext): Promise { }); context.subscriptions.push(gotoFileLocationCommand); - // custom command - refresh diagnostics - const refreshDiagnosticsCommand = commands.registerCommand("renpy.refreshDiagnostics", () => { - if (window.activeTextEditor) { - refreshDiagnostics(window.activeTextEditor.document, diagnostics); - } - }); - context.subscriptions.push(refreshDiagnosticsCommand); - // custom command - toggle token debug view let isShowingTokenDebugView = false; const toggleTokenDebugViewCommand = commands.registerCommand("renpy.toggleTokenDebugView", () => {