惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
U
Unit 42
Vercel News
Vercel News
Martin Fowler
Martin Fowler
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
C
Check Point Blog
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
博客园_首页
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
Last Week in AI
Last Week in AI
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
V
Visual Studio Blog
小众软件
小众软件

Yesterday17's Blog

2026 新年解密红包 / Melody Flag | Yesterday17's Blog 谈谈 Iori 的设计思路(二):如何实现一个 Showroom 录制工具? | Yesterday17's Blog 谈谈 Iori 的设计思路(一):从 Nico Timeshift 说起 | Yesterday17's Blog Iori Minyami 0.1.0 发布 | Yesterday17's Blog 2025 新年解密红包 / Melody Flag | Yesterday17's Blog 使用 Cloudflare Warp 解决罗森票务的海外登录问题 | Yesterday17's Blog How To Blog 04: The Astro v5 Era | Yesterday17's Blog 谈谈 tokio::select! 的公平性 | Yesterday17's Blog Learning Pingora 05 - Connect with TLS | Yesterday17's Blog Leaving Bytedance | Yesterday17's Blog 大橋彩香 AsiaTour「Reflection」上海公演 个人向记录 & Repo | Yesterday17's Blog Recoving from burnout - What happened? | Yesterday17 Yubikey 重建手册 | Yesterday17's Blog How To Blog 03: Heimus | Yesterday17's Blog 🪧 Blog Migration Accouncement | Yesterday17's Blog How To Blog 02: Astro❤️Password | Yesterday17's Blog How To Blog 01: Why, How, and the Future | Yesterday17's Blog Learning Pingora 04 - Establish L4 Connection | Yesterday17's Blog Learning Pingora 03 - Upstreams and Peers | Yesterday17's Blog Learning Pingora 02 - A Simple HTTP Server | Yesterday17's Blog Learning Pingora 01 - Getting Started | Yesterday17's Blog 2024 新年解密红包 / Melody Flag | Yesterday17's Blog 向新的一年飞驰——记录 2023 | Yesterday17's Blog 「サクラノ刻」对话选摘(2) | Yesterday17's Blog PGP Key Revocation 注销声明 | Yesterday17's Blog 「サクラノ刻」对话选摘(1) | Yesterday17's Blog 2023 新年解密红包 / Melody Flag | Yesterday17's Blog 『蒼の彼方のフォーリズム』通关感想 | Yesterday17's Blog 单显卡直通教程 | Yesterday17's Blog 对博客与笔记的思考 | Yesterday17's Blog
Learn Your IDE - VSCode 是如何仅重启插件的? | Yesterday1...
Yesterday17 · 2024-04-05 · via Yesterday17's Blog

VSCode1.88更新日志中宣布了 Restart extensions 的功能:

在本地 VSCode 中,现在不需要 Reload Window 就可以重启插件了。这不禁让我好奇,他们到底做了些什么?

ToC

  • 找找
  • 看看

找找

让我们先用关键词 Reload Extensions 来找一找:

this.enabled = true;

this.class = ExtensionRuntimeStateAction.EnabledClass;

this.tooltip = runtimeState.reason;

this.label = runtimeState.action === ExtensionRuntimeActionType.ReloadWindow ? localize('reload window', 'Reload Window')

: runtimeState.action === ExtensionRuntimeActionType.RestartExtensions ? localize('restart extensions', 'Restart Extensions')

: runtimeState.action === ExtensionRuntimeActionType.QuitAndInstall ? localize('restart product', 'Restart to Update')

: runtimeState.action === ExtensionRuntimeActionType.ApplyUpdate || runtimeState.action === ExtensionRuntimeActionType.DownloadUpdate ? localize('update product', 'Update {0}', this.productService.nameShort) : '';

}

找到了 runtimeState.action。它是怎么定义的呢?

export const enum ExtensionRuntimeActionType {

ReloadWindow = "reloadWindow",

RestartExtensions = "restartExtensions",

DownloadUpdate = "downloadUpdate",

ApplyUpdate = "applyUpdate",

QuitAndInstall = "quitAndInstall",

}

看来是加了个 ExtensionRuntimeActionType.RestartExtensions。继续追引用:

override async run(): Promise<any> {

21 collapsed lines

const runtimeState = this.extension?.runtimeState;

if (!runtimeState?.action) {

return;

}

type ExtensionRuntimeStateActionClassification = {

owner: 'sandy081';

comment: 'Extension runtime state action event';

action: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Executed action' };

};

type ExtensionRuntimeStateActionEvent = {

action: string;

};

this.telemetryService.publicLog2<ExtensionRuntimeStateActionEvent, ExtensionRuntimeStateActionClassification>('extensions:runtimestate:action', {

action: runtimeState.action

});

if (runtimeState?.action === ExtensionRuntimeActionType.ReloadWindow) {

return this.hostService.reload();

}

else if (runtimeState?.action === ExtensionRuntimeActionType.RestartExtensions) {

return this.extensionsWorkbenchService.updateRunningExtensions();

}

13 collapsed lines

else if (runtimeState?.action === ExtensionRuntimeActionType.DownloadUpdate) {

return this.updateService.downloadUpdate();

}

else if (runtimeState?.action === ExtensionRuntimeActionType.ApplyUpdate) {

return this.updateService.applyUpdate();

}

else if (runtimeState?.action === ExtensionRuntimeActionType.QuitAndInstall) {

return this.updateService.quitAndInstall();

}

}

看来核心逻辑都在 updateRunningExtensions 里了。

看看

看看 updateRunningExtensions

async updateRunningExtensions(): Promise<void> {

const toAdd: ILocalExtension[] = [];

const toRemove: string[] = [];

const extensionsToCheck = [...this.local];

const notExistingRunningExtensions = this.extensionService.extensions.filter(e => !this.local.some(local => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, local.identifier)));

if (notExistingRunningExtensions.length) {

const extensions = await this.getExtensions(notExistingRunningExtensions.map(e => ({ id: e.identifier.value })), CancellationToken.None);

extensionsToCheck.push(...extensions);

}

for (const extension of extensionsToCheck) {

const runtimeState = extension.runtimeState;

if (!runtimeState || runtimeState.action !== ExtensionRuntimeActionType.RestartExtensions) {

continue;

}

if (extension.state === ExtensionState.Uninstalled) {

toRemove.push(extension.identifier.id);

continue;

}

if (!extension.local) {

continue;

}

const isEnabled = this.extensionEnablementService.isEnabled(extension.local);

if (isEnabled) {

const runningExtension = this.extensionService.extensions.find(e => areSameExtensions({ id: e.identifier.value, uuid: e.uuid }, extension.identifier));

if (runningExtension) {

toRemove.push(runningExtension.identifier.value);

}

toAdd.push(extension.local);

} else {

toRemove.push(extension.identifier.id);

}

}

if (toAdd.length || toRemove.length) {

if (await this.extensionService.stopExtensionHosts(nls.localize('restart', "Enable or Disable extensions"))) {

await this.extensionService.startExtensionHosts({ toAdd, toRemove });

}

}

}

还以为会有什么魔法,结果居然是先 StopStart??

这里 startExtensionHosts() 的签名相比于之前的版本增加了 toAddtoRemove 两个参数,传到内部之后是直接调用了 _handleDeltaExtensions

public async startExtensionHosts(updates?: { toAdd: IExtension[]; toRemove: string[] }): Promise<void> {

this._doStopExtensionHosts();

if (updates) {

await this._handleDeltaExtensions(new DeltaExtensionsQueueItem(updates.toAdd, updates.toRemove));

}

const lock = await this._registry.acquireLock('startExtensionHosts');

try {

this._startExtensionHostsIfNecessary(false, Array.from(this._allRequestedActivateEvents.keys()));

const localProcessExtensionHosts = this._getExtensionHostManagers(ExtensionHostKind.LocalProcess);

await Promise.all(localProcessExtensionHosts.map(extHost => extHost.ready()));

} finally {

lock.dispose();

}

}

没意思,还以为是做了什么好东西,这样实现居然还不支持 Remote,软软没救了,散了散了)