@@ -26,6 +26,8 @@ import {
2626import { CodeTerminalSettingPrefix } from '../common/preference' ;
2727import { ShellType , WindowsShellType } from '../common/shell' ;
2828
29+ import { XTerm } from './xterm' ;
30+
2931export interface EventMessage {
3032 data : string ;
3133}
@@ -100,93 +102,13 @@ export class NodePtyTerminalService implements ITerminalService {
100102 ptyInstance : pty ,
101103 } ) ;
102104
103- /**
104- *
105- * @param sessionId
106- * @param _
107- * @param rows
108- * @param cols
109- * @param options
110- * @param shellType
111- * @returns
112- */
113- async attach (
105+ async attachByLaunchConfig (
114106 sessionId : string ,
115- _ : Terminal ,
116- rows : number ,
117107 cols : number ,
118- options : TerminalOptions = { } ,
119- shellType ?: ShellType ,
108+ rows : number ,
109+ launchConfig : IShellLaunchConfig ,
110+ _xterm : XTerm ,
120111 ) {
121- let shellPath = options . shellPath ;
122- const shellArgs = typeof options . shellArgs === 'string' ? [ options . shellArgs ] : options . shellArgs || [ ] ;
123- const platformKey = await this . getCodePlatformKey ( ) ;
124- const terminalOs = await this . getOs ( ) ;
125- if ( ! shellPath ) {
126- // if terminal options.shellPath is not set, we should resolve the shell path from preference: `terminal.type`
127- if ( shellType && shellType !== 'default' ) {
128- if ( terminalOs === OperatingSystem . Windows ) {
129- shellPath = await this . serviceClientRPC . $resolveWindowsShellPath ( shellType as WindowsShellType ) ;
130- } else {
131- shellPath = await this . serviceClientRPC . $resolveUnixShellPath ( shellType ) ;
132- }
133-
134- if ( ! shellPath ) {
135- // TODO: we can show error message here
136- // "the shell you want to launch is not exists"
137- }
138- }
139-
140- // and now, we have the following two situations:
141- if ( ! shellPath ) {
142- if ( ! shellType || shellType === 'default' ) {
143- // 1. `terminal.type` is set to a falsy value, or set to `default`
144- if ( terminalOs === OperatingSystem . Windows ) {
145- // in windows, at least we can launch the cmd.exe
146- const { type : _type , path } = await this . serviceClientRPC . $resolvePotentialWindowsShellPath ( ) ;
147- shellType = _type ;
148- shellPath = path ;
149- } else {
150- // in unix, at least we can launch the sh
151- shellPath = await this . serviceClientRPC . $resolvePotentialUnixShellPath ( ) ;
152- }
153- } else {
154- // 2. `terminal.type` is set to a truthy value, but the shell path is not resolved, for example cannot resolve 'git-bash'
155- // but in this situation, we preserve the user settings, launch the type as shell path
156- // on PtyService we also have a fallback to check the shellPath is valid
157- shellPath = shellType ;
158- }
159- }
160-
161- // if we still can not find the shell path, we use shellType as the target shell path
162- if ( ! shellPath && shellType !== 'default' ) {
163- shellPath = shellType ;
164- }
165-
166- const platformSpecificArgs = this . preferenceService . get < string [ ] > (
167- `${ CodeTerminalSettingPrefix . ShellArgs } ${ platformKey } ` ,
168- [ ] ,
169- ) ;
170-
171- shellArgs . push ( ...platformSpecificArgs ) ;
172-
173- if ( shellType === WindowsShellType [ 'git-bash' ] ) {
174- shellArgs . push ( '--login' ) ;
175- }
176- }
177-
178- const launchConfig : IShellLaunchConfig = {
179- executable : shellPath ,
180- cwd : options . cwd ,
181- args : shellArgs ,
182- env : options . env ,
183- name : options . name ,
184- strictEnv : options . strictEnv ,
185- } ;
186- return this . attachByLaunchConfig ( sessionId , cols , rows , launchConfig ) ;
187- }
188-
189- async attachByLaunchConfig ( sessionId : string , cols : number , rows : number , launchConfig : IShellLaunchConfig ) {
190112 // If code runs to here, it means that we want to create a real terminal.
191113 // So if `launchConfig.executable` is not set, we should use the default shell.
192114 if ( ! launchConfig . executable ) {
0 commit comments