Skip to content

Commit

Permalink
feat: implement more api
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jun 7, 2023
1 parent bddac6a commit 06590af
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 97 deletions.
8 changes: 4 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ const api: typeof vscode = {
TaskPanelKind: unsupported,
TaskRevealKind: unsupported,
TaskScope: unsupported,
TerminalLink: unsupported,
TerminalLocation: unsupported,
TerminalProfile: unsupported,
TerminalLink: extHostTypes.TerminalLink,
TerminalLocation: extHostTypes.TerminalLocation,
TerminalProfile: extHostTypes.TerminalProfile,
TextDocumentSaveReason: extHostTypes.TextDocumentSaveReason,
TextEdit: extHostTypes.TextEdit,
TextEditorCursorStyle: editorOptions.TextEditorCursorStyle,
Expand Down Expand Up @@ -196,7 +196,7 @@ const api: typeof vscode = {
SnippetTextEdit: extHostTypes.SnippetTextEdit,
NotebookEdit: unsupported,
LogLevel: log.LogLevel,
TerminalExitReason: unsupported,
TerminalExitReason: extHostTypes.TerminalExitReason,
CommentThreadState: unsupported,
TelemetryTrustedValue: telemetryUtils.TelemetryTrustedValue
}
Expand Down
6 changes: 4 additions & 2 deletions src/vscode-services/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitData
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices'
import { getExtHostServices } from './extHost'
import { unsupported } from '../tools'

export default function create (getExtension: () => IExtensionDescription): typeof vscode.env {
return {
Expand All @@ -25,7 +24,10 @@ export default function create (getExtension: () => IExtensionDescription): type
return extHostClipboard.value
},
remoteName: undefined,
get shell () { return unsupported() },
get shell () {
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.getDefaultShell(false)
},
get uiKind () {
return StandaloneServices.get(IExtHostInitDataService).uiKind
},
Expand Down
63 changes: 16 additions & 47 deletions src/vscode-services/extHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ import { ExtHostTreeViews } from 'vs/workbench/api/common/extHostTreeViews'
import { ExtHostStorage } from 'vs/workbench/api/common/extHostStorage'
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'
import { ExtHostStatusBar } from 'vs/workbench/api/common/extHostStatusBar'
import { ExtHostTheming } from 'vs/workbench/api/common/extHostTheming'
import { ExtHostTerminalService } from 'vs/workbench/api/node/extHostTerminalService'
import 'vs/workbench/api/browser/mainThreadLocalization'
import 'vs/workbench/api/browser/mainThreadCommands'
import 'vs/workbench/api/browser/mainThreadWindow'
Expand All @@ -85,6 +87,9 @@ import 'vs/workbench/api/browser/mainThreadSaveParticipant'
import 'vs/workbench/api/browser/mainThreadTreeViews'
import 'vs/workbench/api/browser/mainThreadStorage'
import 'vs/workbench/api/browser/mainThreadStatusBar'
import 'vs/workbench/api/browser/mainThreadTheming'
import 'vs/workbench/api/browser/mainThreadTerminalService'
import 'vs/workbench/api/browser/mainThreadEditorTabs'
import * as errors from 'vs/base/common/errors'
import { Barrier } from 'vs/base/common/async'
import { unsupported } from '../tools'
Expand Down Expand Up @@ -216,52 +221,7 @@ registerSingleton(IExtHostDecorations, ExtHostDecorations, InstantiationType.Eag
registerSingleton(IExtHostDebugService, WorkerExtHostDebugService, InstantiationType.Eager)
registerSingleton(IExtHostVariableResolverProvider, ExtHostVariableResolverProviderService, InstantiationType.Eager)
registerSingleton(IExtHostOutputService, ExtHostOutputService, InstantiationType.Delayed)
registerSingleton(IExtHostTerminalService, class ExtHostTerminalService implements IExtHostTerminalService {
_serviceBrand: undefined
activeTerminal = undefined
terminals = []
onDidCloseTerminal = Event.None
onDidOpenTerminal = Event.None
onDidChangeActiveTerminal = Event.None
onDidChangeTerminalDimensions = Event.None
onDidChangeTerminalState = Event.None
onDidWriteTerminalData = Event.None
onDidChangeShell = Event.None
createTerminal = unsupported
createTerminalFromOptions = unsupported
createExtensionTerminal = unsupported
attachPtyToTerminal = unsupported
getDefaultShell = unsupported
getDefaultShellArgs = unsupported
registerLinkProvider = unsupported
registerProfileProvider = unsupported
registerTerminalQuickFixProvider = unsupported
getEnvironmentVariableCollection = unsupported
$acceptTerminalClosed = unsupported
$acceptTerminalOpened = unsupported
$acceptActiveTerminalChanged = unsupported
$acceptTerminalProcessId = unsupported
$acceptTerminalProcessData = unsupported
$acceptTerminalTitleChange = unsupported
$acceptTerminalDimensions = unsupported
$acceptTerminalMaximumDimensions = unsupported
$acceptTerminalInteraction = unsupported
$startExtensionTerminal = unsupported
$acceptProcessAckDataEvent = unsupported
$acceptProcessInput = unsupported
$acceptProcessResize = unsupported
$acceptProcessShutdown = unsupported
$acceptProcessRequestInitialCwd = unsupported
$acceptProcessRequestCwd = unsupported
$acceptProcessRequestLatency = unsupported
$provideLinks = unsupported
$activateLink = unsupported
$initEnvironmentVariableCollections = unsupported
$acceptDefaultProfile = unsupported
$createContributedProfileTerminal = unsupported
$provideTerminalQuickFixes = unsupported
dispose = unsupported
}, InstantiationType.Eager)
registerSingleton(IExtHostTerminalService, ExtHostTerminalService, InstantiationType.Eager)
registerSingleton(IExtHostLocalizationService, ExtHostLocalizationService, InstantiationType.Delayed)

const mainContext: IMainContext & IInternalExtHostContext = {
Expand Down Expand Up @@ -316,16 +276,21 @@ async function createExtHostServices () {
const extHostTunnelService = StandaloneServices.get(IExtHostTunnelService)
const extHostTelemetry = StandaloneServices.get(IExtHostTelemetry)
const extHostInitData = StandaloneServices.get(IExtHostInitDataService)
const extHostEditorTabs = StandaloneServices.get(IExtHostEditorTabs)

// register addressable instances
rpcProtocol.set(ExtHostContext.ExtHostFileSystemInfo, extHostFileSystemInfo)
rpcProtocol.set(ExtHostContext.ExtHostTunnelService, extHostTunnelService)
rpcProtocol.set(ExtHostContext.ExtHostTelemetry, extHostTelemetry)
rpcProtocol.set(ExtHostContext.ExtHostEditorTabs, extHostEditorTabs)

// automatically create and register addressable instances
const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, StandaloneServices.get(IExtHostDecorations))
const extHostCommands = rpcProtocol.set(ExtHostContext.ExtHostCommands, StandaloneServices.get(IExtHostCommands))
const extHostDocumentsAndEditors = rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, StandaloneServices.get(IExtHostDocumentsAndEditors))
const extHostLocalization = rpcProtocol.set(ExtHostContext.ExtHostLocalization, StandaloneServices.get(IExtHostLocalizationService))
const extHostTerminalService = rpcProtocol.set(ExtHostContext.ExtHostTerminalService, StandaloneServices.get(IExtHostTerminalService))
const extHostTheming = rpcProtocol.set(ExtHostContext.ExtHostTheming, new ExtHostTheming(rpcProtocol))

// manually create and register addressable instances
const extHostQuickOpen = rpcProtocol.set(ExtHostContext.ExtHostQuickOpen, createExtHostQuickOpen(mainContext, <IExtHostWorkspaceProvider><unknown>null, extHostCommands))
Expand Down Expand Up @@ -416,7 +381,11 @@ async function createExtHostServices () {
extHostTreeViews,
extHostStorage,
extHostLocalization,
extHostStatusBar
extHostStatusBar,
extHostTerminalService,
extHostEditorTabs,
extHostDecorations,
extHostTheming
}
}

Expand Down
102 changes: 58 additions & 44 deletions src/vscode-services/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Event } from 'vs/base/common/event'
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes'
import { StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices'
import { IModelService } from 'vs/editor/common/services/model'
import { DisposableStore } from 'vs/base/common/lifecycle'
import { ITextModel } from 'vs/editor/common/model'
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions'
import { getExtHostServices } from './extHost'
Expand Down Expand Up @@ -126,7 +125,16 @@ export default function create (getExtension: () => IExtensionDescription, works

return extHostStatusBar.setStatusBarMessage(text, timeoutOrThenable)
},
createTerminal: unsupported,
createTerminal (nameOrOptions?: vscode.TerminalOptions | vscode.ExtensionTerminalOptions | string, shellPath?: string, shellArgs?: readonly string[] | string): vscode.Terminal {
const { extHostTerminalService } = getExtHostServices()
if (typeof nameOrOptions === 'object') {
if ('pty' in nameOrOptions) {
return extHostTerminalService.createExtensionTerminal(nameOrOptions)
}
return extHostTerminalService.createTerminalFromOptions(nameOrOptions)
}
return extHostTerminalService.createTerminal(nameOrOptions, shellPath, shellArgs)
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
registerTreeDataProvider (viewId: string, treeDataProvider: vscode.TreeDataProvider<any>): vscode.Disposable {
const { extHostTreeViews } = getExtHostServices()
Expand Down Expand Up @@ -172,17 +180,29 @@ export default function create (getExtension: () => IExtensionDescription, works
const { extHostEditors } = getExtHostServices()
return extHostEditors.onDidChangeTextEditorViewColumn(listener, thisArg, disposables)
},
get activeTerminal () {
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.activeTerminal
},
get terminals () {
return unsupported()
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.terminals
},
get activeTerminal () {
return unsupported()
onDidChangeActiveTerminal (listener, thisArg?, disposables?) {
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.onDidChangeActiveTerminal(listener, thisArg, disposables)
},
onDidCloseTerminal (listener, thisArg?, disposables?) {
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables)
},
onDidOpenTerminal (listener, thisArg?, disposables?) {
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.onDidOpenTerminal(listener, thisArg, disposables)
},
onDidChangeActiveTerminal: Event.None,
onDidOpenTerminal: Event.None,
onDidCloseTerminal: Event.None,
get state () {
return unsupported()
const { extHostWindow } = getExtHostServices()
return extHostWindow.state
},
onDidChangeWindowState (listener, thisArg?, disposables?) {
const { extHostWindow } = getExtHostServices()
Expand All @@ -191,41 +211,35 @@ export default function create (getExtension: () => IExtensionDescription, works
registerUriHandler: unsupported,
registerWebviewViewProvider: unsupported,
registerCustomEditorProvider: unsupported,
registerTerminalLinkProvider: unsupported,
get activeColorTheme () {
return unsupported()
},
onDidChangeActiveColorTheme: Event.None,
registerFileDecorationProvider: unsupported,
registerTerminalProfileProvider: unsupported,
onDidChangeTerminalState: Event.None,
tabGroups: {
get all () {
return [tabGroup]
},
activeTabGroup: tabGroup,
onDidChangeTabGroups: Event.None,
onDidChangeTabs (listener) {
const modelService = StandaloneServices.get(IModelService)
const store = new DisposableStore()
store.add(modelService.onModelAdded((model) => {
listener({
opened: [getTabFromModel(model, tabGroup)],
closed: [],
changed: []
})
}))
store.add(modelService.onModelRemoved((model) => {
listener({
opened: [],
closed: [getTabFromModel(model, tabGroup)],
changed: []
})
}))

return store
},
close: unsupported
registerTerminalLinkProvider (provider: vscode.TerminalLinkProvider): vscode.Disposable {
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.registerLinkProvider(provider)
},
get activeColorTheme (): vscode.ColorTheme {
const { extHostTheming } = getExtHostServices()
return extHostTheming.activeColorTheme
},
onDidChangeActiveColorTheme (listener, thisArg?, disposables?) {
const { extHostTheming } = getExtHostServices()
return extHostTheming.onDidChangeActiveColorTheme(listener, thisArg, disposables)
},
registerFileDecorationProvider (provider: vscode.FileDecorationProvider) {
const { extHostDecorations } = getExtHostServices()
const extension = getExtension()
return extHostDecorations.registerFileDecorationProvider(provider, extension)
},
registerTerminalProfileProvider (id: string, provider: vscode.TerminalProfileProvider): vscode.Disposable {
const { extHostTerminalService } = getExtHostServices()
const extension = getExtension()
return extHostTerminalService.registerProfileProvider(extension, id, provider)
},
onDidChangeTerminalState (listener, thisArg?, disposables?) {
const { extHostTerminalService } = getExtHostServices()
return extHostTerminalService.onDidChangeTerminalState(listener, thisArg, disposables)
},
get tabGroups (): vscode.TabGroups {
const { extHostEditorTabs } = getExtHostServices()
return extHostEditorTabs.tabGroups
},
showNotebookDocument: unsupported,
visibleNotebookEditors: [],
Expand Down

0 comments on commit 06590af

Please sign in to comment.