Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Feb 19, 2024
1 parent 8b67fec commit 652cbd6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ export async function registerRemoteExtension (directory: string): Promise<Regis
return registerExtension(manifest, ExtensionHostKind.Remote, { path: directory })
}

const forcedExtensionHostKinds = new Map<string, ExtensionHostKind>()
const extensions: IExtension[] = []
export function getExtensionManifests (): IExtension[] {
return extensions
}
export function getForcedExtensionHostKind (id: string): ExtensionHostKind | undefined {
return forcedExtensionHostKinds.get(id)
}

export function registerExtension (manifest: IExtensionManifest, extHostKind: ExtensionHostKind.LocalProcess, params?: RegisterExtensionParams): RegisterLocalProcessExtensionResult
export function registerExtension (manifest: IExtensionManifest, extHostKind: ExtensionHostKind.LocalWebWorker, params?: RegisterExtensionParams): RegisterLocalExtensionResult
Expand Down Expand Up @@ -134,6 +138,9 @@ export function registerExtension (manifest: IExtensionManifest, extHostKind?: E
changelogUrl: changelogPath != null ? URI.joinPath(realLocation, changelogPath) : undefined
}

if (extHostKind != null) {
forcedExtensionHostKinds.set(id, extHostKind)
}
if (extHostKind !== ExtensionHostKind.Remote) {
extensions.push(extension)
}
Expand Down Expand Up @@ -164,6 +171,7 @@ export function registerExtension (manifest: IExtensionManifest, extHostKind?: E
if (index >= 0) {
extensions.splice(extensions.indexOf(extension), 1)
}
forcedExtensionHostKinds.delete(id)

await deltaExtensions({ toAdd: [], toRemove: [extension] })
}
Expand Down
22 changes: 2 additions & 20 deletions src/service-override/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { changeUrlDomain } from './tools/url'
import { CustomSchemas } from './files'
import type { LocalExtensionHost } from '../localExtensionHost'
import { registerAssets } from '../assets'
import { getForcedExtensionHostKind } from '../extensions'
import 'vs/workbench/api/browser/extensionHost.contribution'

export interface WorkerConfig {
Expand Down Expand Up @@ -129,7 +130,6 @@ class BrowserExtensionHostFactoryOverride extends BrowserExtensionHostFactory {
}

class LocalBrowserExtensionHostKindPicker extends BrowserExtensionHostKindPicker {
private extensionHostKinds = new Map<string, ExtensionHostKind>()
constructor (
private readonly allowedExtHostKinds: ExtensionHostKind[],
@ILogService _logService: ILogService
Expand All @@ -138,7 +138,7 @@ class LocalBrowserExtensionHostKindPicker extends BrowserExtensionHostKindPicker
}

public override pickExtensionHostKind (extensionId: ExtensionIdentifier, extensionKinds: ExtensionKind[], isInstalledLocally: boolean, isInstalledRemotely: boolean, preference: ExtensionRunningPreference): ExtensionHostKind | null {
const forcedKind = this.extensionHostKinds.get(extensionId.value)
const forcedKind = getForcedExtensionHostKind(extensionId.value)
if (forcedKind != null) {
return forcedKind
}
Expand All @@ -148,14 +148,6 @@ class LocalBrowserExtensionHostKindPicker extends BrowserExtensionHostKindPicker
}
return detectedKind
}

public setForcedExtensionHostKind (id: string, kind: ExtensionHostKind): void {
this.extensionHostKinds.set(id, kind)
}

public removeForcedExtensionHostKind (id: string): void {
this.extensionHostKinds.delete(id)
}
}

export interface IExtensionWithExtHostKind extends IExtension {
Expand Down Expand Up @@ -230,16 +222,6 @@ export class ExtensionServiceOverride extends ExtensionService implements IExten
}

public async deltaExtensions (toAdd: IExtensionWithExtHostKind[], toRemove: IExtension[]): Promise<void> {
const extHostPicker = (this._extensionHostKindPicker as LocalBrowserExtensionHostKindPicker)
for (const extension of toRemove) {
extHostPicker.removeForcedExtensionHostKind(extension.identifier.id)
}
for (const extension of toAdd) {
if (extension.extHostKind != null) {
extHostPicker.setForcedExtensionHostKind(extension.identifier.id, extension.extHostKind)
}
}

await this._handleDeltaExtensions(new DeltaExtensionsQueueItem(toAdd, toRemove))
}

Expand Down

0 comments on commit 652cbd6

Please sign in to comment.