Skip to content

Commit

Permalink
feat: Implement configuration api using services
Browse files Browse the repository at this point in the history
  • Loading branch information
CGNonofr committed Jul 19, 2022
1 parent b1deb2a commit 8eef8a5
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 26 deletions.
7 changes: 4 additions & 3 deletions src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type * as vscode from 'vscode'
import type { IProgressService } from 'vs/platform/progress/common/progress'
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { NotificationsFilter } from 'vs/platform/notification/common/notification'
import { IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration'

export {
Severity
Expand All @@ -18,8 +19,6 @@ export interface Workspace {
workspaceFolders?: typeof vscode.workspace.workspaceFolders
updateWorkspaceFolders?: typeof vscode.workspace.updateWorkspaceFolders
onDidChangeWorkspaceFolders?: typeof vscode.workspace.onDidChangeWorkspaceFolders
getConfiguration?: typeof vscode.workspace.getConfiguration
onDidChangeConfiguration?: vscode.Event<vscode.ConfigurationChangeEvent>
onWillSaveTextDocument?: vscode.Event<vscode.TextDocumentWillSaveEvent>
onDidSaveTextDocument?: vscode.Event<vscode.TextDocument>
createFileSystemWatcher?: typeof vscode.workspace.createFileSystemWatcher
Expand Down Expand Up @@ -85,7 +84,9 @@ export { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/b
export { IPathService } from 'vs/workbench/services/path/common/pathService'
export { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'
export { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService'
export { IConfigurationService } from 'vs/platform/configuration/common/configuration'

export {
NotificationsFilter
NotificationsFilter,
IConfigurationChangeEvent
}
79 changes: 74 additions & 5 deletions src/vscode-services/extHost.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands'
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService'
import { ConsoleMainLogger, LogService } from 'vs/platform/log/common/log'
import { ConsoleMainLogger, ILogService, LogLevel, LogService } from 'vs/platform/log/common/log'
import { MainThreadCommands } from 'vs/workbench/api/browser/mainThreadCommands'
import { IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers'
import { ExtensionHostKind, NullExtensionService } from 'vs/workbench/services/extensions/common/extensions'
import { Event } from 'vs/base/common/event'
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { URI } from 'vs/base/common/uri'
import { ExtHostApiDeprecationService } from 'vs/workbench/api/common/extHostApiDeprecationService'
import { ExtHostContext, IMainContext, MainContext } from 'vs/workbench/api/common/extHost.protocol'
import { ExtHostConfigurationShape, ExtHostContext, IConfigurationInitData, IMainContext, MainContext, MainThreadConfigurationShape } from 'vs/workbench/api/common/extHost.protocol'
import { ExtHostDiagnostics } from 'vs/workbench/api/common/extHostDiagnostics'
import { ExtHostFileSystemInfo } from 'vs/workbench/api/common/extHostFileSystemInfo'
import * as monaco from 'monaco-editor'
Expand All @@ -19,7 +19,7 @@ import { VSBuffer } from 'vs/base/common/buffer'
import { Proxied, ProxyIdentifier } from 'vs/workbench/services/extensions/common/proxyIdentifier'
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments'
import { createExtHostQuickOpen } from 'vs/workbench/api/common/extHostQuickOpen'
import { IExtHostWorkspaceProvider } from 'vs/workbench/api/common/extHostWorkspace'
import { ExtHostWorkspace, IExtHostWorkspace, IExtHostWorkspaceProvider } from 'vs/workbench/api/common/extHostWorkspace'
import { MainThreadQuickOpen } from 'vs/workbench/api/browser/mainThreadQuickOpen'
import { ExtHostMessageService } from 'vs/workbench/api/common/extHostMessageService'
import { MainThreadMessageService } from 'vs/workbench/api/browser/mainThreadMessageService'
Expand Down Expand Up @@ -75,7 +75,14 @@ import { ExtHostLanguageFeatures } from 'vs/workbench/api/common/extHostLanguage
import { MainThreadLanguageFeatures } from 'vs/workbench/api/browser/mainThreadLanguageFeatures'
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'
import { IConfigurationChange, IConfigurationService } from 'vs/platform/configuration/common/configuration'
import { ExtHostConfigProvider } from 'vs/workbench/api/common/extHostConfiguration'
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService'
import { MainThreadConfiguration } from 'vs/workbench/api/browser/mainThreadConfiguration'
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'
import { UIKind } from 'vs/workbench/services/extensions/common/extensionHostProtocol'
import { unsupported } from '../tools'
import { Services } from '../services'

export const DEFAULT_EXTENSION: IExtensionDescription = {
identifier: new ExtensionIdentifier('monaco'),
Expand Down Expand Up @@ -137,6 +144,41 @@ class MainThreadMessageServiceWithoutSource extends MainThreadMessageService {
}
}

/**
* The vscode ExtHostConfiguration use a barrier and its getConfigProvider returns a promise, let's use a simpler version
*/
export class SyncExtHostConfiguration implements ExtHostConfigurationShape {
readonly _serviceBrand: undefined

private readonly _proxy: MainThreadConfigurationShape
private readonly _logService: ILogService
private readonly _extHostWorkspace: ExtHostWorkspace
private _actual: ExtHostConfigProvider | null

constructor (
@IExtHostRpcService extHostRpc: IExtHostRpcService,
@IExtHostWorkspace extHostWorkspace: IExtHostWorkspace,
@ILogService logService: ILogService
) {
this._proxy = extHostRpc.getProxy(MainContext.MainThreadConfiguration)
this._extHostWorkspace = extHostWorkspace
this._logService = logService
this._actual = null
}

public getConfigProvider (): ExtHostConfigProvider {
return this._actual!
}

$initializeConfiguration (data: IConfigurationInitData): void {
this._actual = new ExtHostConfigProvider(this._proxy, this._extHostWorkspace, data, this._logService)
}

$acceptConfigurationChanged (data: IConfigurationInitData, change: IConfigurationChange): void {
this.getConfigProvider().$acceptConfigurationChanged(data, change)
}
}

function createExtHostServices () {
const commandsService = StandaloneServices.get(ICommandService)
const notificationService = StandaloneServices.get(INotificationService)
Expand Down Expand Up @@ -168,6 +210,7 @@ function createExtHostServices () {
const languageConfigurationService = StandaloneServices.get(ILanguageConfigurationService)
const languageFeaturesService = StandaloneServices.get(ILanguageFeaturesService)
const configurationService = StandaloneServices.get(IConfigurationService)
const workspaceContextService = StandaloneServices.get(IWorkspaceContextService)

const imessagePassingProtocol = new SimpleMessagePassingProtocol()

Expand All @@ -193,6 +236,27 @@ function createExtHostServices () {
}
}

const initData: IExtHostInitDataService = {
_serviceBrand: undefined,
version: '1.0.0',
parentPid: 0,
get environment () { return unsupported() },
resolvedExtensions: [],
hostExtensions: [],
extensions: [Services.get().extension ?? DEFAULT_EXTENSION],
get telemetryInfo () { return unsupported() },
logLevel: LogLevel.Trace,
get logsLocation () { return unsupported() },
get logFile () { return unsupported() },
autoStart: false,
remote: {
isRemote: false,
authority: undefined,
connectionData: null
},
uiKind: UIKind.Web
}

const extHostLogService = new LogService(new ConsoleMainLogger())
const extensionService = new NullExtensionService()
const extHostApiDeprecationService = new ExtHostApiDeprecationService(mainContext, extHostLogService)
Expand All @@ -215,6 +279,8 @@ function createExtHostServices () {
const extHostEditors = rpcProtocol.set(ExtHostContext.ExtHostEditors, new ExtHostEditors(mainContext, extHostDocumentsAndEditors))
const extHostClipboard = new ExtHostClipboard(mainContext)
const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, uriTransformerService, extHostDocuments, extHostCommands, extHostDiagnostics, extHostLogService, extHostApiDeprecationService))
const extHostWorkspace = rpcProtocol.set(ExtHostContext.ExtHostWorkspace, new ExtHostWorkspace(mainContext, initData, extHostFileSystemInfo, extHostLogService))
const extHostConfiguration = rpcProtocol.set(ExtHostContext.ExtHostConfiguration, new SyncExtHostConfiguration(mainContext, extHostWorkspace, extHostLogService))

rpcProtocol.set(ExtHostContext.ExtHostTelemetry, new ExtHostTelemetry())
rpcProtocol.set(MainContext.MainThreadMessageService, new MainThreadMessageServiceWithoutSource(mainContext, notificationService, commandsService, dialogService))
Expand All @@ -227,6 +293,7 @@ function createExtHostServices () {
rpcProtocol.set(MainContext.MainThreadLanguages, new MainThreadLanguages(mainContext, languageService, modelService, textModelService, languageStatusService))
rpcProtocol.set(MainContext.MainThreadClipboard, new MainThreadClipboard(mainContext, clipboardService))
rpcProtocol.set(MainContext.MainThreadLanguageFeatures, new MainThreadLanguageFeatures(mainContext, languageService, languageConfigurationService, languageFeaturesService))
rpcProtocol.set(MainContext.MainThreadConfiguration, new MainThreadConfiguration(mainContext, workspaceContextService, configurationService, workbenchEnvironmentService))

// eslint-disable-next-line no-new
new MainThreadDocumentsAndEditors(
Expand Down Expand Up @@ -265,7 +332,9 @@ function createExtHostServices () {
extHostLanguages,
extHostWindow,
extHostClipboard,
extHostLanguageFeatures
extHostLanguageFeatures,
extHostWorkspace,
extHostConfiguration
}
}

Expand Down
28 changes: 10 additions & 18 deletions src/vscode-services/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type * as vscode from 'vscode'
import { Event } from 'vs/base/common/event'
import { URI } from 'vs/base/common/uri'
import { getExtHostServices } from './extHost'
import { DEFAULT_EXTENSION, getExtHostServices } from './extHost'
import { unsupported } from '../tools'
import { Services } from '../services'

Expand Down Expand Up @@ -63,24 +63,16 @@ const workspace: typeof vscode.workspace = {
return extHostBulkEdits.applyWorkspaceEdit(edit)
},
getConfiguration: (section, scope) => {
const { workspace } = Services.get()
if (workspace?.getConfiguration != null) {
return workspace.getConfiguration(section, scope)
}
return {
get: <T>(section: string, defaultValue?: T): T | undefined => {
return defaultValue
},
has: () => {
return false
},
inspect: unsupported,
update: unsupported
}
const { extHostConfiguration } = getExtHostServices()

const configProvider = extHostConfiguration.getConfigProvider()
return configProvider.getConfiguration(section, scope, Services.get().extension ?? DEFAULT_EXTENSION)
},
get onDidChangeConfiguration (): typeof vscode.workspace.onDidChangeConfiguration {
const { workspace } = Services.get()
return workspace?.onDidChangeConfiguration ?? Event.None
onDidChangeConfiguration (listener, thisArgs, disposables) {
const { extHostConfiguration } = getExtHostServices()

const configProvider = extHostConfiguration.getConfigProvider()
return configProvider.onDidChangeConfiguration(listener, thisArgs, disposables)
},
get rootPath () {
const { workspace } = Services.get()
Expand Down

0 comments on commit 8eef8a5

Please sign in to comment.