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

Function activate

src/extension/extension.ts:131–753  ·  view source on GitHub ↗
(context: vs.ExtensionContext, isRestart = false)

Source from the content-addressed store, hash-verified

129export const perSessionWebviewStateKey = `webviewState_${(new Date()).getTime()}_${getRandomInt(1, 1000)}`;
130
131export async function activate(context: vs.ExtensionContext, isRestart = false) {
132 extensionThisSessionStart = Date.now();
133
134 // Ring logger is only set up once and persists over silent restarts.
135 if (!ringLogger)
136 ringLogger = logger.onLog((message) => ringLog.log(message.toLine(800)));
137
138 if (isDevExtension)
139 context.subscriptions.push(logToConsole(logger));
140
141 // Clear any caches, for example projects that we detected. We might be reloading because
142 // a Flutter project was added to a Dart-only workspace.
143 clearCaches();
144
145 void vs.commands.executeCommand("setContext", IS_RUNNING_LOCALLY_CONTEXT, isRunningLocally);
146 buildLogHeaders();
147 if (!extensionLog)
148 extensionLog = setupLog(getExtensionLogPath(), LogCategory.General, false);
149
150 const webClient = new WebClient(extensionVersion);
151
152 util.logTime("Code called activate");
153
154 // Wire up a reload command that will re-initialise everything.
155 context.subscriptions.push(vs.commands.registerCommand("_dart.reloadExtension", async (reason?: ExtensionRestartReason, data?: string) => {
156 reason ??= ExtensionRestartReason.Unknown;
157 logger.warn(`Performing extension reload (${reason}, ${data})...`);
158 analytics.logExtensionRestart(reason, data);
159 await deactivate(true, reason);
160 await disposeAllAsync(context.subscriptions);
161 await activate(context, true);
162 logger.info("Done reloading extension!");
163 }));
164
165 // Configure if using flutter-dev.
166 setFlutterDev(config.useFlutterDev);
167
168 previousSettingsObject = getSettingsThatRequireRestart();
169
170 util.logTime();
171 analytics = new Analytics(logger);
172
173 // Helper to set the tool env using current analytics/env settings.
174 const setEnvHelper = () => setupToolEnv({ suppressAnalytics: analytics.isSuppressed, envOverrides: config.env });
175 setEnvHelper(); // Set initial values.
176
177 // Rebuild toolEnv when related config changes. This needs to be set up before the SDK search, since it
178 // is what causes the config reload when the SDK paths are selected during "Locate SDK".
179 context.subscriptions.push(vs.workspace.onDidChangeConfiguration((e) => {
180 config.reload();
181 if (e.affectsConfiguration("dart.env") || e.affectsConfiguration("dart.allowAnalytics") || e.affectsConfiguration("telemetry.telemetryLevel"))
182 setEnvHelper();
183 }));
184
185 const sdkUtils = new SdkUtils(logger, context, analytics);
186 const workspaceContextUnverified = await sdkUtils.scanWorkspace();
187 extensionApiModel.setSdks(workspaceContextUnverified.sdks);
188 analytics.workspaceContext = workspaceContextUnverified;

Callers

nothing calls this directly

Calls 15

scanWorkspaceMethod · 0.95
handleMissingSdksMethod · 0.95
connectToDtdMethod · 0.95
handleDebugSessionEndMethod · 0.95
logToConsoleFunction · 0.90
clearCachesFunction · 0.90
getExtensionLogPathFunction · 0.90
disposeAllAsyncFunction · 0.90
setFlutterDevFunction · 0.90

Tested by

no test coverage detected