Skip to content

Commit

Permalink
refactor: extract code
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jun 16, 2023
1 parent 0bc6736 commit 43e8931
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
26 changes: 26 additions & 0 deletions src/createApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type * as vscode from 'vscode'
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import * as api from './api'
import createL10nApi from './vscode-services/l10n'
import createLanguagesApi from './vscode-services/languages'
import createCommandsApi from './vscode-services/commands'
import createWorkspaceApi from './vscode-services/workspace'
import createWindowApi from './vscode-services/window'
import createEnvApi from './vscode-services/env'
import createDebugApi from './vscode-services/debug'
import createExtensionsApi from './vscode-services/extensions'

export default function createApi (extension: IExtensionDescription): typeof vscode {
const workspace = createWorkspaceApi(() => extension)
return {
...api,
extensions: createExtensionsApi(() => extension),
debug: createDebugApi(() => extension),
env: createEnvApi(() => extension),
commands: createCommandsApi(() => extension),
window: createWindowApi(() => extension, workspace),
workspace: createWorkspaceApi(() => extension),
languages: createLanguagesApi(() => extension),
l10n: createL10nApi(() => extension)
}
}
16 changes: 1 addition & 15 deletions src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { initialize as initializeExtHostServices, onExtHostInitialized, getExtHo
import { unsupported } from './tools'
import { setDefaultExtension } from './default-extension'
import 'vs/workbench/contrib/search/browser/search.contribution'
import createApi from './createApi'

export function consoleExtensionMessageHandler (msg: IMessage): void {
if (msg.type === Severity.Error) {
Expand All @@ -51,21 +52,6 @@ export async function initialize (extension?: IExtensionDescription): Promise<vo
await initializeExtHostServices()
}

export function createApi (extension: IExtensionDescription): typeof vscode {
const workspace = createWorkspaceApi(() => extension)
return {
...api,
extensions: createExtensionsApi(() => extension),
debug: createDebugApi(() => extension),
env: createEnvApi(() => extension),
commands: createCommandsApi(() => extension),
window: createWindowApi(() => extension, workspace),
workspace: createWorkspaceApi(() => extension),
languages: createLanguagesApi(() => extension),
l10n: createL10nApi(() => extension)
}
}

const hasOwnProperty = Object.hasOwnProperty
function handleExtensionPoint<T extends IExtensionContributions[keyof IExtensionContributions]> (extensionPoint: ExtensionPoint<T>, availableExtensions: IExtensionDescription[], messageHandler: (msg: IMessage) => void): void {
const users: IExtensionPointUser<T>[] = []
Expand Down

0 comments on commit 43e8931

Please sign in to comment.