Skip to content

Commit

Permalink
refactor: only re-fetch config when affected (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric authored Mar 10, 2024
1 parent 3cc442a commit f5a2986
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
11 changes: 9 additions & 2 deletions src/manifestAssetCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}
})
);
}
Expand Down
11 changes: 8 additions & 3 deletions src/manifestDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}
})
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/manifestLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}
})
);
}
Expand Down
11 changes: 9 additions & 2 deletions src/manifestPluginCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
}
})
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export function isManifestPluginValidationEnabled(scope?: vscode.ConfigurationSc
.get<boolean>('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.
Expand All @@ -20,6 +24,10 @@ export function isManifestFileReferencesEnabled(scope?: vscode.ConfigurationScop
.get<boolean>('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:
Expand All @@ -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')
);
}

0 comments on commit f5a2986

Please sign in to comment.