Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f8bd0e3d
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f8bd0e3d
编写于
6月 29, 2019
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use findExecutable based on tasks function
上级
ea5435a4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
45 deletion
+70
-45
src/vs/workbench/contrib/terminal/node/terminalEnvironment.ts
...vs/workbench/contrib/terminal/node/terminalEnvironment.ts
+56
-3
src/vs/workbench/contrib/terminal/node/terminalProcess.ts
src/vs/workbench/contrib/terminal/node/terminalProcess.ts
+14
-42
未找到文件。
src/vs/workbench/contrib/terminal/node/terminalEnvironment.ts
浏览文件 @
f8bd0e3d
...
...
@@ -4,8 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import
{
IProcessEnvironment
,
isLinux
,
isMacintosh
,
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
readFile
}
from
'
vs/base/node/pfs
'
;
import
{
basename
}
from
'
vs/base/common/path
'
;
import
{
readFile
,
exists
}
from
'
vs/base/node/pfs
'
;
import
*
as
path
from
'
vs/base/common/path
'
;
import
{
isString
}
from
'
vs/base/common/types
'
;
let
mainProcessParentEnv
:
IProcessEnvironment
|
undefined
;
...
...
@@ -18,7 +19,7 @@ export async function getMainProcessParentEnv(): Promise<IProcessEnvironment> {
// env using /proc/<pid>/environ.
if
(
isLinux
)
{
const
mainProcessId
=
process
.
ppid
;
const
codeProcessName
=
basename
(
process
.
argv
[
0
]);
const
codeProcessName
=
path
.
basename
(
process
.
argv
[
0
]);
let
pid
:
number
=
0
;
let
ppid
:
number
=
mainProcessId
;
let
name
:
string
=
codeProcessName
;
...
...
@@ -76,4 +77,56 @@ export async function getMainProcessParentEnv(): Promise<IProcessEnvironment> {
}
return
mainProcessParentEnv
!
;
}
export
async
function
findExecutable
(
command
:
string
,
cwd
?:
string
,
paths
?:
string
[]):
Promise
<
string
|
undefined
>
{
// If we have an absolute path then we take it.
if
(
path
.
isAbsolute
(
command
))
{
return
await
exists
(
command
)
?
command
:
undefined
;
}
if
(
cwd
===
undefined
)
{
cwd
=
process
.
cwd
();
}
const
dir
=
path
.
dirname
(
command
);
if
(
dir
!==
'
.
'
)
{
// We have a directory and the directory is relative (see above). Make the path absolute
// to the current working directory.
const
fullPath
=
path
.
join
(
cwd
,
command
);
return
await
exists
(
fullPath
)
?
fullPath
:
undefined
;
}
if
(
paths
===
undefined
&&
isString
(
process
.
env
.
PATH
))
{
paths
=
process
.
env
.
PATH
.
split
(
path
.
delimiter
);
}
// No PATH environment. Make path absolute to the cwd.
if
(
paths
===
undefined
||
paths
.
length
===
0
)
{
const
fullPath
=
path
.
join
(
cwd
,
command
);
return
await
exists
(
fullPath
)
?
fullPath
:
undefined
;
}
// We have a simple file name. We get the path variable from the env
// and try to find the executable on the path.
for
(
let
pathEntry
of
paths
)
{
// The path entry is absolute.
let
fullPath
:
string
;
if
(
path
.
isAbsolute
(
pathEntry
))
{
fullPath
=
path
.
join
(
pathEntry
,
command
);
}
else
{
fullPath
=
path
.
join
(
cwd
,
pathEntry
,
command
);
}
if
(
await
exists
(
fullPath
))
{
return
fullPath
;
}
if
(
isWindows
)
{
let
withExtension
=
fullPath
+
'
.com
'
;
if
(
await
exists
(
withExtension
))
{
return
withExtension
;
}
withExtension
=
fullPath
+
'
.exe
'
;
if
(
await
exists
(
withExtension
))
{
return
withExtension
;
}
}
}
const
fullPath
=
path
.
join
(
cwd
,
command
);
return
await
exists
(
fullPath
)
?
fullPath
:
undefined
;
}
\ No newline at end of file
src/vs/workbench/contrib/terminal/node/terminalProcess.ts
浏览文件 @
f8bd0e3d
...
...
@@ -15,6 +15,8 @@ import { IShellLaunchConfig, ITerminalChildProcess, SHELL_PATH_INVALID_EXIT_CODE
import
{
exec
}
from
'
child_process
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
stat
}
from
'
vs/base/node/pfs
'
;
import
{
findExecutable
}
from
'
vs/workbench/contrib/terminal/node/terminalEnvironment
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
export
class
TerminalProcess
implements
ITerminalChildProcess
,
IDisposable
{
private
_exitCode
:
number
;
...
...
@@ -25,7 +27,6 @@ export class TerminalProcess implements ITerminalChildProcess, IDisposable {
private
_isDisposed
:
boolean
=
false
;
private
_titleInterval
:
NodeJS
.
Timer
|
null
=
null
;
private
_initialCwd
:
string
;
private
_foundExecutableInPath
:
boolean
=
false
;
private
readonly
_onProcessData
=
new
Emitter
<
string
>
();
public
get
onProcessData
():
Event
<
string
>
{
return
this
.
_onProcessData
.
event
;
}
...
...
@@ -69,54 +70,25 @@ export class TerminalProcess implements ITerminalChildProcess, IDisposable {
stat
(
shellLaunchConfig
.
executable
!
).
then
(
stat
=>
{
if
(
!
stat
.
isFile
()
&&
!
stat
.
isSymbolicLink
())
{
this
.
_exitCode
=
stat
.
isDirectory
()
?
SHELL_PATH_DIRECTORY_EXIT_CODE
:
SHELL_PATH_INVALID_EXIT_CODE
;
this
.
_queueProcessExit
();
this
.
_processStartupComplete
=
Promise
.
resolve
(
undefined
);
return
;
return
this
.
_launchFailed
(
stat
.
isDirectory
()
?
SHELL_PATH_DIRECTORY_EXIT_CODE
:
SHELL_PATH_INVALID_EXIT_CODE
);
}
this
.
setupPtyProcess
(
shellLaunchConfig
,
options
);
},
(
err
)
=>
{
if
(
err
&&
err
.
code
===
'
ENOENT
'
&&
!
this
.
checkIfExistsInPath
(
shellLaunchConfig
.
executable
!
))
{
this
.
_exitCode
=
SHELL_PATH_INVALID_EXIT_CODE
;
this
.
_queueProcessExit
();
this
.
_processStartupComplete
=
Promise
.
resolve
(
undefined
);
return
;
},
async
(
err
)
=>
{
if
(
err
&&
err
.
code
===
'
ENOENT
'
)
{
let
cwd
=
shellLaunchConfig
.
cwd
instanceof
URI
?
shellLaunchConfig
.
cwd
.
path
:
shellLaunchConfig
.
cwd
!
;
const
executable
=
await
findExecutable
(
shellLaunchConfig
.
executable
!
,
cwd
);
if
(
!
executable
)
{
return
this
.
_launchFailed
(
SHELL_PATH_INVALID_EXIT_CODE
);
}
}
this
.
setupPtyProcess
(
shellLaunchConfig
,
options
);
});
}
private
checkInsideDirRecursively
(
execPath
:
string
,
executable
:
string
):
void
{
try
{
fs
.
readdirSync
(
execPath
).
forEach
((
file
)
=>
{
const
pathToFile
=
path
.
join
(
execPath
,
file
);
const
isDirectory
=
fs
.
statSync
(
pathToFile
).
isDirectory
();
if
(
!
isDirectory
)
{
if
(
executable
===
file
)
{
this
.
_foundExecutableInPath
=
true
;
}
}
else
{
this
.
checkInsideDirRecursively
(
execPath
,
executable
);
}
});
}
catch
(
err
)
{
if
(
err
.
code
!==
'
ENOENT
'
)
{
throw
err
;
}
}
}
private
checkIfExistsInPath
(
executable
:
string
):
boolean
{
if
(
process
.
env
.
PATH
)
{
const
envPath
=
process
.
env
.
PATH
.
split
(
path
.
delimiter
);
envPath
.
forEach
(
eachPath
=>
{
if
(
!
path
.
isAbsolute
(
eachPath
))
{
this
.
checkInsideDirRecursively
(
eachPath
,
executable
);
}
});
}
return
this
.
_foundExecutableInPath
;
private
_launchFailed
(
exitCode
:
number
):
void
{
this
.
_exitCode
=
exitCode
;
this
.
_queueProcessExit
();
this
.
_processStartupComplete
=
Promise
.
resolve
(
undefined
);
}
private
setupPtyProcess
(
shellLaunchConfig
:
IShellLaunchConfig
,
options
:
pty
.
IPtyForkOptions
):
void
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录