From f5a2986db374869cc53bcf27cb32d23cf1271429 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Sun, 10 Mar 2024 13:41:27 +0100 Subject: [PATCH] refactor: only re-fetch config when affected (#256) --- src/manifestAssetCompletions.ts | 11 +++++++++-- src/manifestDiagnostics.ts | 11 ++++++++--- src/manifestLinks.ts | 8 +++++--- src/manifestPluginCompletions.ts | 11 +++++++++-- src/settings.ts | 15 +++++++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/manifestAssetCompletions.ts b/src/manifestAssetCompletions.ts index 8412884..d7941fd 100644 --- a/src/manifestAssetCompletions.ts +++ b/src/manifestAssetCompletions.ts @@ -5,6 +5,8 @@ import vscode from 'vscode'; import { manifestPattern } from './expo/manifest'; import { ExpoProjectCache } from './expo/project'; import { + changedManifestFileReferencesEnabled, + changedManifestFileReferencesExcludedFiles, getManifestFileReferencesExcludedFiles, isManifestFileReferencesEnabled, } from './settings'; @@ -34,8 +36,13 @@ export class ManifestAssetCompletionsProvider extends ExpoCompletionsProvider { extension.subscriptions.push( vscode.workspace.onDidChangeConfiguration((event) => { - this.isEnabled = isManifestFileReferencesEnabled(); - this.excludedFiles = getManifestFileReferencesExcludedFiles(); + if (changedManifestFileReferencesEnabled(event)) { + this.isEnabled = isManifestFileReferencesEnabled(); + } + + if (changedManifestFileReferencesExcludedFiles(event)) { + this.excludedFiles = getManifestFileReferencesExcludedFiles(); + } }) ); } diff --git a/src/manifestDiagnostics.ts b/src/manifestDiagnostics.ts index f8177f9..77c5503 100644 --- a/src/manifestDiagnostics.ts +++ b/src/manifestDiagnostics.ts @@ -4,7 +4,10 @@ import vscode from 'vscode'; import { type FileReference, getFileReferences, manifestPattern } from './expo/manifest'; import { getPluginDefinition, resolvePluginFunctionUnsafe } from './expo/plugin'; import { ExpoProject, ExpoProjectCache } from './expo/project'; -import { isManifestPluginValidationEnabled } from './settings'; +import { + changedManifesPluginValidationEnabled, + isManifestPluginValidationEnabled, +} from './settings'; import { debug } from './utils/debug'; import { getDocumentRange } from './utils/json'; import { resetModuleFrom } from './utils/module'; @@ -30,8 +33,10 @@ export class ManifestDiagnosticsProvider extends ExpoDiagnosticsProvider { this.isEnabled = isManifestPluginValidationEnabled(); extension.subscriptions.push( - vscode.workspace.onDidChangeConfiguration(() => { - this.isEnabled = isManifestPluginValidationEnabled(); + vscode.workspace.onDidChangeConfiguration((event) => { + if (changedManifesPluginValidationEnabled(event)) { + this.isEnabled = isManifestPluginValidationEnabled(); + } }) ); } diff --git a/src/manifestLinks.ts b/src/manifestLinks.ts index 43943e3..6205cdf 100644 --- a/src/manifestLinks.ts +++ b/src/manifestLinks.ts @@ -4,7 +4,7 @@ import vscode from 'vscode'; import { getFileReferences, manifestPattern } from './expo/manifest'; import { getPluginDefinition, resolvePluginInfo } from './expo/plugin'; import { ExpoProjectCache } from './expo/project'; -import { isManifestFileReferencesEnabled } from './settings'; +import { changedManifestFileReferencesEnabled, isManifestFileReferencesEnabled } from './settings'; import { debug } from './utils/debug'; import { getDocumentRange } from './utils/json'; import { ExpoLinkProvider } from './utils/vscode'; @@ -19,8 +19,10 @@ export class ManifestLinksProvider extends ExpoLinkProvider { this.isEnabled = isManifestFileReferencesEnabled(); extension.subscriptions.push( - vscode.workspace.onDidChangeConfiguration(() => { - this.isEnabled = isManifestFileReferencesEnabled(); + vscode.workspace.onDidChangeConfiguration((event) => { + if (changedManifestFileReferencesEnabled(event)) { + this.isEnabled = isManifestFileReferencesEnabled(); + } }) ); } diff --git a/src/manifestPluginCompletions.ts b/src/manifestPluginCompletions.ts index ba93375..ae53090 100644 --- a/src/manifestPluginCompletions.ts +++ b/src/manifestPluginCompletions.ts @@ -6,6 +6,8 @@ import { manifestPattern } from './expo/manifest'; import { type PluginInfo, resolveInstalledPluginInfo, resolvePluginInfo } from './expo/plugin'; import { ExpoProjectCache } from './expo/project'; import { + changedManifestFileReferencesEnabled, + changedManifestFileReferencesExcludedFiles, getManifestFileReferencesExcludedFiles, isManifestFileReferencesEnabled, } from './settings'; @@ -32,8 +34,13 @@ export class ManifestPluginCompletionsProvider extends ExpoCompletionsProvider { extension.subscriptions.push( vscode.workspace.onDidChangeConfiguration((event) => { - this.isEnabled = isManifestFileReferencesEnabled(); - this.excludedFiles = getManifestFileReferencesExcludedFiles(); + if (changedManifestFileReferencesEnabled(event)) { + this.isEnabled = isManifestFileReferencesEnabled(); + } + + if (changedManifestFileReferencesExcludedFiles(event)) { + this.excludedFiles = getManifestFileReferencesExcludedFiles(); + } }) ); } diff --git a/src/settings.ts b/src/settings.ts index 7f58561..c1a0026 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -10,6 +10,10 @@ export function isManifestPluginValidationEnabled(scope?: vscode.ConfigurationSc .get('pluginValidation', true); } +export function changedManifesPluginValidationEnabled(event: vscode.ConfigurationChangeEvent) { + return event.affectsConfiguration('expo.appManifest.pluginValidation'); +} + /** * Determine if we should show file references auto-complete in app manifests. * This uses the `expo.appManifest.fileReferences` setting from the configuration scope. @@ -20,6 +24,10 @@ export function isManifestFileReferencesEnabled(scope?: vscode.ConfigurationScop .get('fileReferences', true); } +export function changedManifestFileReferencesEnabled(event: vscode.ConfigurationChangeEvent) { + return event.affectsConfiguration('expo.appManifest.fileReferences'); +} + /** * Get the excluded files configuration, used to filter out path-based suggestions. * This is a combination of multiple glob patterns: @@ -36,3 +44,10 @@ export function getManifestFileReferencesExcludedFiles(scope?: vscode.Configurat }), }; } + +export function changedManifestFileReferencesExcludedFiles(event: vscode.ConfigurationChangeEvent) { + return ( + event.affectsConfiguration('files.exclude') || + event.affectsConfiguration('expo.appManifest.fileReferences.excludeGlobPatterns') + ); +}