()
| 797 | |
| 798 | |
| 799 | function 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 = ` |
| 831 | Your SDK path changed unexpectedly during startup. |
| 832 | |
| 833 | Please 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 | |
| 847 | function getSettingsThatRequireRestart(): Record<string, string | number | boolean | undefined> { |
| 848 | return { |
no test coverage detected