Skip to content

Commit

Permalink
Merge pull request #365 from CodinGame/fix-vsix-plugin-window
Browse files Browse the repository at this point in the history
Fix vsix plugin on Window
  • Loading branch information
CGNonofr authored Mar 12, 2024
2 parents 0cf636c + 6556c8c commit f73ae3e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 15 deletions.
13 changes: 6 additions & 7 deletions demo/src/setup.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getConfigurationServiceOverride, { IStoredWorkspace, initUserConfiguratio
import getKeybindingsServiceOverride, { initUserKeybindings } from '@codingame/monaco-vscode-keybindings-service-override'
import { RegisteredFileSystemProvider, RegisteredMemoryFile, RegisteredReadOnlyFile, createIndexedDBProviders, initFile, registerFileSystemOverlay } from '@codingame/monaco-vscode-files-service-override'
import * as monaco from 'monaco-editor'
import { IWorkbenchConstructionOptions, LogLevel, IEditorOverrideServices, registerWorkbenchContribution, WorkbenchPhase, IStorageService, StorageScope, StorageTarget } from 'vscode/services'
import { IWorkbenchConstructionOptions, LogLevel, IEditorOverrideServices } from 'vscode/services'
import * as vscode from 'vscode'
import getModelServiceOverride from '@codingame/monaco-vscode-model-service-override'
import getNotificationServiceOverride from '@codingame/monaco-vscode-notifications-service-override'
Expand Down Expand Up @@ -167,11 +167,6 @@ window.MonacoEnvironment = {
}
}

// Remove "account" item from activity bar
registerWorkbenchContribution('remove-accounts', accessor => {
accessor.get(IStorageService).store('workbench.activity.showAccounts', false, StorageScope.APPLICATION, StorageTarget.USER)
}, WorkbenchPhase.BlockRestore)

const params = new URL(document.location.href).searchParams
export const remoteAuthority = params.get('remoteAuthority') ?? undefined
export const connectionToken = params.get('connectionToken') ?? undefined
Expand Down Expand Up @@ -284,7 +279,11 @@ export const commonServices: IEditorOverrideServices = {
...getMarkersServiceOverride(),
...getAccessibilityServiceOverride(),
...getLanguageDetectionWorkerServiceOverride(),
...getStorageServiceOverride(),
...getStorageServiceOverride({
fallbackOverride: {
'workbench.activity.showAccounts': false
}
}),
...getRemoteAgentServiceOverride({ scanRemoteExtensions: true }),
...getLifecycleServiceOverride(),
...getEnvironmentServiceOverride(),
Expand Down
2 changes: 1 addition & 1 deletion src/rollup-vsix-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function readVsix (file: string): Promise<IFs> {
}

function getVsixPath (file: string) {
return path.relative('/', path.resolve('/', file))
return path.posix.relative('/', path.posix.resolve('/', file))
}

export default function plugin ({
Expand Down
2 changes: 1 addition & 1 deletion src/service-override/extensionGallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ExtensionManagementServerServiceOverride extends ExtensionManagementServer
@ILabelService readonly labelService: ILabelService,
@IInstantiationService readonly instantiationService: IInstantiationService
) {
super(isWebOnly ? remoteAgentService : new EmptyRemoteAgentService(), labelService, instantiationService)
super(isWebOnly ? new EmptyRemoteAgentService() : remoteAgentService, labelService, instantiationService)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/service-override/remoteAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ import { IRemoteUserDataProfilesService } from 'vs/workbench/services/userDataPr
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile'
import { IActiveLanguagePackService } from 'vs/workbench/services/localization/common/locale'
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { ITunnelService } from 'vs/platform/tunnel/common/tunnel'
import { TunnelService } from 'vs/workbench/services/tunnel/browser/tunnelService'
import getEnvironmentServiceOverride from './environment'
import { getWorkbenchConstructionOptions } from '../workbench'
import { registerServiceInitializePreParticipant } from '../lifecycle'
import 'vs/workbench/contrib/remote/common/remote.contribution'
import 'vs/workbench/contrib/remote/browser/remote.contribution'
import 'vs/workbench/contrib/remote/browser/remoteStartEntry.contribution'

class CustomRemoteSocketFactoryService extends RemoteSocketFactoryService {
constructor (@IBrowserWorkbenchEnvironmentService browserWorkbenchEnvironmentService: IBrowserWorkbenchEnvironmentService) {
Expand Down Expand Up @@ -91,6 +94,7 @@ export default function getServiceOverride ({ scanRemoteExtensions = false }: Re
[IRemoteAuthorityResolverService.toString()]: new SyncDescriptor(InjectedRemoteAuthorityResolverService, []),
[IRemoteExplorerService.toString()]: new SyncDescriptor(RemoteExplorerService, [], true),
[IExternalUriOpenerService.toString()]: new SyncDescriptor(ExternalUriOpenerService, [], true),
[IRemoteExtensionsScannerService.toString()]: new SyncDescriptor(CustomRemoteExtensionsScannerService, [scanRemoteExtensions], true)
[IRemoteExtensionsScannerService.toString()]: new SyncDescriptor(CustomRemoteExtensionsScannerService, [scanRemoteExtensions], true),
[ITunnelService.toString()]: new SyncDescriptor(TunnelService, [], true)
}
}
67 changes: 62 additions & 5 deletions src/service-override/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ExternalStorageService extends AbstractStorageService {
private readonly profileStorage = this._register(new ExternalStorage(StorageScope.PROFILE, this.provider))
private readonly workspaceStorage = this._register(new ExternalStorage(StorageScope.WORKSPACE, this.provider))

constructor (protected readonly provider: IStorageProvider) {
constructor (protected readonly provider: IStorageProvider, private fallbackOverride?: Record<string, unknown>) {
super({
flushInterval: 5000
})
Expand Down Expand Up @@ -129,6 +129,30 @@ class ExternalStorageService extends AbstractStorageService {
hasScope (_scope: IAnyWorkspaceIdentifier | IUserDataProfile): boolean {
return false
}

override get(key: string, scope: VSStorageScope, fallbackValue: string): string
override get(key: string, scope: VSStorageScope): string | undefined
override get (key: string, scope: VSStorageScope, fallbackValue?: string): string | undefined {
return this.getStorage(scope).get(key, (this.fallbackOverride?.[key] as string | undefined) ?? fallbackValue)
}

override getBoolean(key: string, scope: VSStorageScope, fallbackValue: boolean): boolean
override getBoolean(key: string, scope: VSStorageScope): boolean | undefined
override getBoolean (key: string, scope: VSStorageScope, fallbackValue?: boolean): boolean | undefined {
return this.getStorage(scope).getBoolean(key, (this.fallbackOverride?.[key] as boolean | undefined) ?? fallbackValue)
}

override getNumber(key: string, scope: VSStorageScope, fallbackValue: number): number
override getNumber(key: string, scope: VSStorageScope): number | undefined
override getNumber (key: string, scope: VSStorageScope, fallbackValue?: number): number | undefined {
return this.getStorage(scope).getNumber(key, (this.fallbackOverride?.[key] as number | undefined) ?? fallbackValue)
}

override getObject(key: string, scope: VSStorageScope, fallbackValue: object): object
override getObject(key: string, scope: VSStorageScope): object | undefined
override getObject (key: string, scope: VSStorageScope, fallbackValue?: object): object | undefined {
return this.getStorage(scope).getObject(key, (this.fallbackOverride?.[key] as object | undefined) ?? fallbackValue)
}
}

registerServiceInitializePreParticipant(async (accessor) => {
Expand All @@ -147,22 +171,55 @@ registerServiceInitializePreParticipant(async (accessor) => {

class InjectedBrowserStorageService extends BrowserStorageService {
constructor (
private fallbackOverride: Record<string, unknown> | undefined,
@IUserDataProfileService userDataProfileService: IUserDataProfileService,
@ILogService logService: ILogService
) {
super(getWorkspaceIdentifier(), userDataProfileService, logService)
}

override get(key: string, scope: VSStorageScope, fallbackValue: string): string
override get(key: string, scope: VSStorageScope): string | undefined
override get (key: string, scope: VSStorageScope, fallbackValue?: string): string | undefined {
return this.getStorage(scope)?.get(key, (this.fallbackOverride?.[key] as string | undefined) ?? fallbackValue)
}

override getBoolean(key: string, scope: VSStorageScope, fallbackValue: boolean): boolean
override getBoolean(key: string, scope: VSStorageScope): boolean | undefined
override getBoolean (key: string, scope: VSStorageScope, fallbackValue?: boolean): boolean | undefined {
return this.getStorage(scope)?.getBoolean(key, (this.fallbackOverride?.[key] as boolean | undefined) ?? fallbackValue)
}

override getNumber(key: string, scope: VSStorageScope, fallbackValue: number): number
override getNumber(key: string, scope: VSStorageScope): number | undefined
override getNumber (key: string, scope: VSStorageScope, fallbackValue?: number): number | undefined {
return this.getStorage(scope)?.getNumber(key, (this.fallbackOverride?.[key] as number | undefined) ?? fallbackValue)
}

override getObject(key: string, scope: VSStorageScope, fallbackValue: object): object
override getObject(key: string, scope: VSStorageScope): object | undefined
override getObject (key: string, scope: VSStorageScope, fallbackValue?: object): object | undefined {
return this.getStorage(scope)?.getObject(key, (this.fallbackOverride?.[key] as object | undefined) ?? fallbackValue)
}
}

interface StorageServiceParameters {
customProvider?: IStorageProvider
/**
* Allows to override the storage key default values
*/
fallbackOverride?: Record<string, unknown>
}

export default function getStorageServiceOverride (provider?: IStorageProvider): IEditorOverrideServices {
if (provider != null) {
export default function getStorageServiceOverride ({ customProvider, fallbackOverride }: StorageServiceParameters = {}): IEditorOverrideServices {
if (customProvider != null) {
return {
[IStorageService.toString()]: new SyncDescriptor(ExternalStorageService, [provider], true),
[IStorageService.toString()]: new SyncDescriptor(ExternalStorageService, [customProvider, fallbackOverride], true),
[IExtensionStorageService.toString()]: new SyncDescriptor(ExtensionStorageService, [], true)
}
} else {
return {
[IStorageService.toString()]: new SyncDescriptor(InjectedBrowserStorageService, [], true),
[IStorageService.toString()]: new SyncDescriptor(InjectedBrowserStorageService, [fallbackOverride], true),
[IExtensionStorageService.toString()]: new SyncDescriptor(ExtensionStorageService, [], true)
}
}
Expand Down

0 comments on commit f73ae3e

Please sign in to comment.