Skip to content

Commit

Permalink
feat: terminal service override/view
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jun 7, 2023
1 parent 35a5213 commit 67b6023
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 3 deletions.
57 changes: 57 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
"types": "./dist/service-override/output.d.ts",
"default": "./dist/service-override/output.js"
},
"./service-override/terminal": {
"types": "./dist/service-override/terminal.d.ts",
"default": "./dist/service-override/terminal.js"
},
"./workers/textMate.worker": {
"types": "./dist/workers/textMate.worker.d.ts",
"default": "./dist/workers/textMate.worker.js"
Expand Down Expand Up @@ -179,6 +183,9 @@
"service-override/output": [
"./dist/service-override/output.d.ts"
],
"service-override/terminal": [
"./dist/service-override/terminal.d.ts"
],
"workers/textMate.worker": [
"./dist/workers/textMate.worker.d.ts"
],
Expand Down Expand Up @@ -274,7 +281,13 @@
"monaco-editor": "0.38.0",
"vscode-oniguruma": "^1.7.0",
"vscode-textmate": "^9.0.0",
"yauzl": "^2.10.0"
"yauzl": "^2.10.0",
"xterm": "^5.1.0",
"xterm-addon-canvas": "^0.3.0",
"xterm-addon-search": "^0.11.0",
"xterm-addon-serialize": "^0.9.0",
"xterm-addon-unicode11": "^0.5.0",
"xterm-addon-webgl": "^0.14.0"
},
"overrides": {
"typescript": "5.0.4",
Expand Down
7 changes: 5 additions & 2 deletions rollup/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ const ALLOWED_WORKBENCH_CONTRIBUTIONS = new Set([
'DialogHandlerContribution',
'ExplorerViewletViewsContribution',
'ViewsExtensionHandler',
'OutputContribution'
'OutputContribution',
'TerminalMainContribution'
])

function isCallPure (file: string, functionName: string, node: recast.types.namedTypes.CallExpression): boolean {
Expand Down Expand Up @@ -155,7 +156,8 @@ function isCallPure (file: string, functionName: string, node: recast.types.name
firstParamName.includes('Viewlets') ||
firstParamName.includes('Panels') ||
firstParamName.includes('Auxiliary') ||
firstParamName.includes('EditorPane')
firstParamName.includes('EditorPane') ||
firstParamName.includes('TerminalExtensions')
return !allowed
}
}
Expand Down Expand Up @@ -369,6 +371,7 @@ const input = {
'service-override/views': './src/service-override/views.ts',
'service-override/quickaccess': './src/service-override/quickaccess.ts',
'service-override/output': './src/service-override/output.ts',
'service-override/terminal': './src/service-override/terminal.ts',
'workers/textMate.worker': './src/workers/textMate.worker.ts',
'workers/outputLinkComputer.worker': './src/workers/outputLinkComputer.worker.ts',
monaco: './src/monaco.ts',
Expand Down
1 change: 1 addition & 0 deletions rollup/rollup.types.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default rollup.defineConfig({
'./dist/types/src/service-override/views.d.ts',
'./dist/types/src/service-override/quickaccess.d.ts',
'./dist/types/src/service-override/output.d.ts',
'./dist/types/src/service-override/terminal.d.ts',
'./dist/types/src/workers/textMate.worker.d.ts',
'./dist/types/src/workers/outputLinkComputer.worker.d.ts',
'./dist/types/src/monaco.d.ts',
Expand Down
127 changes: 127 additions & 0 deletions src/service-override/terminal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import '../vscode-services/missing-services'
import { IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
import { ITerminalBackend, ITerminalBackendRegistry, ITerminalProfileResolverService, ITerminalProfileService, TerminalExtensions } from 'vs/workbench/contrib/terminal/common/terminal'
import { ITerminalEditorService, ITerminalGroupService, ITerminalInstanceService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal'
import { TerminalService } from 'vs/workbench/contrib/terminal/browser/terminalService'
import { TerminalEditorService } from 'vs/workbench/contrib/terminal/browser/terminalEditorService'
import { TerminalGroupService } from 'vs/workbench/contrib/terminal/browser/terminalGroupService'
import { TerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminalInstanceService'
import { TerminalProfileService } from 'vs/workbench/contrib/terminal/browser/terminalProfileService'
import { ITerminalContributionService, TerminalContributionService } from 'vs/workbench/contrib/terminal/common/terminalExtensionPoints'
import { ITerminalLinkProviderService } from 'vs/workbench/contrib/terminalContrib/links/browser/links'
import { TerminalLinkProviderService } from 'vs/workbench/contrib/terminalContrib/links/browser/terminalLinkProviderService'
import { ElectronTerminalProfileResolverService } from 'vs/workbench/contrib/terminal/electron-sandbox/terminalProfileResolverService'
import { EnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariableService'
import { IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable'
import { ITerminalQuickFixService } from 'vs/workbench/contrib/terminalContrib/quickFix/browser/quickFix'
import { TerminalQuickFixService } from 'vs/workbench/contrib/terminalContrib/quickFix/browser/terminalQuickFixService'
import { Emitter, Event } from 'vs/base/common/event'
import { Registry } from 'vs/platform/registry/common/platform'
import { IProcessReadyEvent, ITerminalChildProcess, ITerminalLaunchError, ITerminalProfile, ITerminalsLayoutInfo } from 'vs/platform/terminal/common/terminal'
import { IProcessEnvironment } from 'vs/base/common/platform'
import { unsupported } from '../tools'
import 'vs/workbench/contrib/terminal/browser/terminal.contribution'

abstract class SimpleTerminalBackend implements ITerminalBackend {
remoteAuthority = undefined
onPtyHostUnresponsive = Event.None
onPtyHostResponsive = Event.None
onPtyHostRestart = Event.None
onDidRequestDetach = Event.None
attachToProcess = unsupported
attachToRevivedProcess = unsupported
listProcesses = unsupported
getProfiles = async (): Promise<ITerminalProfile[]> => []
getWslPath = unsupported
getEnvironment = async (): Promise<IProcessEnvironment> => ({})
getShellEnvironment = async (): Promise<IProcessEnvironment | undefined> => undefined
setTerminalLayoutInfo = async (): Promise<void> => {}
updateTitle = async (): Promise<void> => {}
updateIcon = async (): Promise<void> => {}
getTerminalLayoutInfo = async (): Promise<ITerminalsLayoutInfo | undefined> => undefined
reduceConnectionGraceTime = unsupported
requestDetachInstance = unsupported
acceptDetachInstanceReply = unsupported
persistTerminalState = unsupported

abstract getDefaultSystemShell: ITerminalBackend['getDefaultSystemShell']
abstract createProcess: ITerminalBackend['createProcess']
}

abstract class SimpleTerminalProcess implements ITerminalChildProcess {
private onReady = new Emitter<IProcessReadyEvent>()
constructor (
readonly id: number,
readonly pid: number,
readonly cwd: string,
readonly onData: Event<string>
) {
setTimeout(() => {
this.onReady.fire({
cwd,
pid
})
})
}

abstract start(): Promise<ITerminalLaunchError | { injectedArgs: string[] } | undefined>

abstract shutdown (immediate: boolean): void

abstract input (data: string): void

abstract resize (cols: number, rows: number): void

shouldPersist = false
onProcessData = this.onData
onProcessReady = this.onReady.event
onDidChangeProperty = Event.None
onProcessExit = Event.None
processBinary = unsupported
acknowledgeDataEvent (): void {
}

async setUnicodeVersion (): Promise<void> {
}

async getInitialCwd (): Promise<string> {
return this.cwd
}

async getCwd (): Promise<string> {
return this.cwd
}

async getLatency (): Promise<number> {
return 0
}

refreshProperty = async (): Promise<never> => undefined as never

async updateProperty (): Promise<void> {
}
}

export default function getServiceOverride (backend: ITerminalBackend): IEditorOverrideServices {
Registry.as<ITerminalBackendRegistry>(TerminalExtensions.Backend).registerTerminalBackend(backend)
return {
[ITerminalService.toString()]: new SyncDescriptor(TerminalService),
[ITerminalEditorService.toString()]: new SyncDescriptor(TerminalEditorService),
[ITerminalGroupService.toString()]: new SyncDescriptor(TerminalGroupService),
[ITerminalInstanceService.toString()]: new SyncDescriptor(TerminalInstanceService),
[ITerminalProfileService.toString()]: new SyncDescriptor(TerminalProfileService),
[ITerminalContributionService.toString()]: new SyncDescriptor(TerminalContributionService),
[ITerminalLinkProviderService.toString()]: new SyncDescriptor(TerminalLinkProviderService),
[ITerminalProfileResolverService.toString()]: new SyncDescriptor(ElectronTerminalProfileResolverService),
[IEnvironmentVariableService.toString()]: new SyncDescriptor(EnvironmentVariableService),
[ITerminalQuickFixService.toString()]: new SyncDescriptor(TerminalQuickFixService)
}
}

export {
ITerminalBackend,
ITerminalChildProcess,
SimpleTerminalBackend,
SimpleTerminalProcess
}
1 change: 1 addition & 0 deletions tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"src/service-override/views.ts",
"src/service-override/quickaccess.ts",
"src/service-override/output.ts",
"src/service-override/terminal.ts",
"src/workers/textMate.worker.ts",
"src/workers/outputLinkComputer.worker.ts",
"src/monaco.ts",
Expand Down

0 comments on commit 67b6023

Please sign in to comment.