MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / handleConfigurationChange

Function handleConfigurationChange

src/extension/extension.ts:799–845  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

797
798
799function handleConfigurationChange() {
800 // TODOs
801 // SDK
802 const prevObject = previousSettingsObject;
803 // TODO(dantup): Could we switch this to using `affectsConfiguration`?
804 const newObject = getSettingsThatRequireRestart();
805 const changedSettingsNames = prevObject
806 ? Object.keys(prevObject).filter((k) => prevObject[k] !== newObject[k])
807 : [];
808 previousSettingsObject = newObject;
809
810 if (prevObject && changedSettingsNames.length > 0) {
811 // Delay the restart slightly, because the config change may be transmitted to the LSP server
812 // and shutting the server down too quickly results in that trying to write to a closed
813 // stream.
814 logger.warn(`Configuration changed, reloading:`);
815 for (const changedSettingsName of changedSettingsNames)
816 logger.info(` Setting ${changedSettingsName} changed from "${prevObject[changedSettingsName]}" to "${newObject[changedSettingsName]}"`);
817 changedSettingsNames.sort();
818
819 // If the SDK path changed and it's been < 1s since we started activating, it suggests something may be changing the SDK path automatically and
820 // could be negatively affecting performance (we'll start an analysis server, terminate it, start another). In this case, prompt users to try
821 // file issues so we can try to track down what's causing it.
822 if (changedSettingsNames.includes("sdkPath") || changedSettingsNames.includes("flutterSdkPath")) {
823 const sessionDurationMs = Date.now() - extensionThisSessionStart;
824 if (sessionDurationMs <= 1500) {
825 const ringLogContents = ringLog.toString();
826 const tempLogPath = path.join(os.tmpdir(), `log-${getRandomInt(0x1000, 0x10000).toString(16)}.txt`);
827
828 void vs.window.showWarningMessage(`Your SDK path changed unexpectedly during startup. Please review the log and file an issue on GitHub.`, showLogAction).then(async (action) => {
829 if (action === showLogAction) {
830 const logContents = `
831Your SDK path changed unexpectedly during startup.
832
833Please file an issue at https://github.com/Dart-Code/Dart-Code/issues/new?template=BLANK_ISSUE&title=SDK%20path%20changed%20during%20startup
834
835${ringLogContents.split("\n").filter((l) => l.includes("[General]") || l.includes("[Warn]") || l.includes("[Error]")).join("\n")}
836 `.trim();
837 await util.openLogContents(undefined, logContents, tempLogPath);
838 }
839 });
840 }
841 }
842
843 setTimeout(() => util.promptToReloadExtension(logger, { restartReason: ExtensionRestartReason.ConfigurationChange, restartData: changedSettingsNames.join(",") }), 50);
844 }
845}
846
847function getSettingsThatRequireRestart(): Record<string, string | number | boolean | undefined> {
848 return {

Callers 1

activateFunction · 0.85

Calls 5

getRandomIntFunction · 0.90
warnMethod · 0.65
infoMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected