Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
923189c7
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
923189c7
编写于
9月 16, 2020
作者:
C
Connor Peet
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'connor4312/auto-attach-js-debug'
上级
1e0080c9
480b18a8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
234 addition
and
241 deletion
+234
-241
extensions/debug-auto-launch/package.json
extensions/debug-auto-launch/package.json
+6
-27
extensions/debug-auto-launch/package.nls.json
extensions/debug-auto-launch/package.nls.json
+0
-7
extensions/debug-auto-launch/src/extension.ts
extensions/debug-auto-launch/src/extension.ts
+228
-207
未找到文件。
extensions/debug-auto-launch/package.json
浏览文件 @
923189c7
...
@@ -17,33 +17,6 @@
...
@@ -17,33 +17,6 @@
"watch"
:
"gulp watch-extension:debug-auto-launch"
"watch"
:
"gulp watch-extension:debug-auto-launch"
},
},
"contributes"
:
{
"contributes"
:
{
"configuration"
:
{
"title"
:
"Node debug"
,
"properties"
:
{
"debug.node.autoAttach"
:
{
"scope"
:
"window"
,
"type"
:
"string"
,
"enum"
:
[
"disabled"
,
"on"
,
"off"
],
"enumDescriptions"
:
[
"%debug.node.autoAttach.disabled.description%"
,
"%debug.node.autoAttach.on.description%"
,
"%debug.node.autoAttach.off.description%"
],
"description"
:
"%debug.node.autoAttach.description%"
,
"default"
:
"disabled"
},
"debug.javascript.usePreviewAutoAttach"
:
{
"scope"
:
"window"
,
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%debug.javascript.usePreviewAutoAttach%"
}
}
},
"commands"
:
[
"commands"
:
[
{
{
"command"
:
"extension.node-debug.toggleAutoAttach"
,
"command"
:
"extension.node-debug.toggleAutoAttach"
,
...
@@ -57,5 +30,11 @@
...
@@ -57,5 +30,11 @@
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@types/node"
:
"^12.11.7"
"@types/node"
:
"^12.11.7"
},
"prettier"
:
{
"printWidth"
:
100
,
"trailingComma"
:
"all"
,
"singleQuote"
:
true
,
"arrowParens"
:
"avoid"
}
}
}
}
extensions/debug-auto-launch/package.nls.json
浏览文件 @
923189c7
{
{
"displayName"
:
"Node Debug Auto-attach"
,
"displayName"
:
"Node Debug Auto-attach"
,
"description"
:
"Helper for auto-attach feature when node-debug extensions are not active."
,
"description"
:
"Helper for auto-attach feature when node-debug extensions are not active."
,
"debug.node.autoAttach.description"
:
"Automatically attach node debugger when node.js was launched in debug mode from integrated terminal."
,
"debug.javascript.usePreviewAutoAttach"
:
"Whether to use the preview debugger's version of auto attach."
,
"debug.node.autoAttach.disabled.description"
:
"Auto attach is disabled and not shown in status bar."
,
"debug.node.autoAttach.on.description"
:
"Auto attach is active."
,
"debug.node.autoAttach.off.description"
:
"Auto attach is inactive."
,
"toggle.auto.attach"
:
"Toggle Auto Attach"
"toggle.auto.attach"
:
"Toggle Auto Attach"
}
}
extensions/debug-auto-launch/src/extension.ts
浏览文件 @
923189c7
...
@@ -8,121 +8,163 @@ import * as vscode from 'vscode';
...
@@ -8,121 +8,163 @@ import * as vscode from 'vscode';
import
*
as
nls
from
'
vscode-nls
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
const
localize
=
nls
.
loadMessageBundle
();
const
ON_TEXT
=
localize
(
'
status.text.auto.attach.on
'
,
'
Auto Attach: On
'
);
const
TEXT_ALWAYS
=
localize
(
'
status.text.auto.attach.always
'
,
'
Auto Attach: Always
'
);
const
OFF_TEXT
=
localize
(
'
status.text.auto.attach.off
'
,
'
Auto Attach: Off
'
);
const
TEXT_SMART
=
localize
(
'
status.text.auto.attach.smart
'
,
'
Auto Attach: Smart
'
);
const
TEXT_WITH_FLAG
=
localize
(
'
status.text.auto.attach.withFlag
'
,
'
Auto Attach: With Flag
'
);
const
TEXT_STATE_LABEL
=
{
[
State
.
Disabled
]:
localize
(
'
debug.javascript.autoAttach.disabled.label
'
,
'
Disabled
'
),
[
State
.
Always
]:
localize
(
'
debug.javascript.autoAttach.always.label
'
,
'
Always
'
),
[
State
.
Smart
]:
localize
(
'
debug.javascript.autoAttach.smart.label
'
,
'
Smart
'
),
[
State
.
OnlyWithFlag
]:
localize
(
'
debug.javascript.autoAttach.onlyWithFlag.label
'
,
'
Only With Flag
'
,
),
};
const
TEXT_STATE_DESCRIPTION
=
{
[
State
.
Disabled
]:
localize
(
'
debug.javascript.autoAttach.disabled.description
'
,
'
Auto attach is disabled and not shown in status bar
'
,
),
[
State
.
Always
]:
localize
(
'
debug.javascript.autoAttach.always.description
'
,
'
Auto attach to every Node.js process launched in the terminal
'
,
),
[
State
.
Smart
]:
localize
(
'
debug.javascript.autoAttach.smart.description
'
,
"
Auto attach when running scripts that aren't in a node_modules folder
"
,
),
[
State
.
OnlyWithFlag
]:
localize
(
'
debug.javascript.autoAttach.onlyWithFlag.description
'
,
'
Only auto attach when the `--inspect` flag is given
'
,
),
};
const
TEXT_TOGGLE_WORKSPACE
=
localize
(
'
scope.workspace
'
,
'
Toggle auto attach in this workspace
'
);
const
TEXT_TOGGLE_GLOBAL
=
localize
(
'
scope.global
'
,
'
Toggle auto attach on this machine
'
);
const
TOGGLE_COMMAND
=
'
extension.node-debug.toggleAutoAttach
'
;
const
TOGGLE_COMMAND
=
'
extension.node-debug.toggleAutoAttach
'
;
const
JS_DEBUG_SETTINGS
=
'
debug.javascript
'
;
const
STORAGE_IPC
=
'
jsDebugIpcState
'
;
const
JS_DEBUG_USEPREVIEWAA
=
'
usePreviewAutoAttach
'
;
const
JS_DEBUG_IPC_KEY
=
'
jsDebugIpcState
'
;
const
JS_DEBUG_REFRESH_SETTINGS
=
[
'
autoAttachSmartPattern
'
,
'
autoAttachFilter
'
];
// settings that, when changed, should cause us to refresh js-debug vars
const
NODE_DEBUG_SETTINGS
=
'
debug.node
'
;
const
AUTO_ATTACH_SETTING
=
'
autoAttach
'
;
const
LAST_STATE_STORAGE_KEY
=
'
lastState
'
;
const
SETTING_SECTION
=
'
debug.javascript
'
;
const
SETTING_STATE
=
'
autoAttachFilter
'
;
type
AUTO_ATTACH_VALUES
=
'
disabled
'
|
'
on
'
|
'
off
'
;
/**
* settings that, when changed, should cause us to refresh the state vars
*/
const
SETTINGS_CAUSE_REFRESH
=
new
Set
(
[
'
autoAttachSmartPattern
'
,
SETTING_STATE
].
map
(
s
=>
`
${
SETTING_SECTION
}
.
${
s
}
`
),
);
const
enum
State
{
const
enum
State
{
Disabled
,
Disabled
=
'
disabled
'
,
O
ff
,
O
nlyWithFlag
=
'
onlyWithFlag
'
,
OnWithJsDebug
,
Smart
=
'
smart
'
,
OnWithNodeDebug
,
Always
=
'
always
'
,
}
}
// on activation this feature is always disabled...
let
currentState
:
Promise
<
{
context
:
vscode
.
ExtensionContext
;
state
:
State
|
null
}
>
;
let
currentState
:
Promise
<
{
context
:
vscode
.
ExtensionContext
,
state
:
State
;
transitionData
:
unknown
}
>
;
let
statusItem
:
vscode
.
StatusBarItem
|
undefined
;
// and there is no status bar item
let
statusItem
:
vscode
.
StatusBarItem
|
undefined
;
// and there is no status bar item
let
server
:
Promise
<
Server
|
undefined
>
|
undefined
;
// auto attach server
export
function
activate
(
context
:
vscode
.
ExtensionContext
):
void
{
export
function
activate
(
context
:
vscode
.
ExtensionContext
):
void
{
const
previousState
=
context
.
workspaceState
.
get
<
State
>
(
LAST_STATE_STORAGE_KEY
,
State
.
Disabled
);
currentState
=
Promise
.
resolve
({
context
,
state
:
null
});
currentState
=
Promise
.
resolve
(
transitions
[
previousState
].
onActivate
?.(
context
,
readCurrentState
()))
.
then
(()
=>
({
context
,
state
:
State
.
Disabled
,
transitionData
:
null
}));
context
.
subscriptions
.
push
(
vscode
.
commands
.
registerCommand
(
TOGGLE_COMMAND
,
toggleAutoAttachSetting
));
// settings that can result in the "state" being changed--on/off/disable or useV3 toggles
context
.
subscriptions
.
push
(
const
effectualConfigurationSettings
=
[
vscode
.
commands
.
registerCommand
(
TOGGLE_COMMAND
,
toggleAutoAttachSetting
),
`
${
NODE_DEBUG_SETTINGS
}
.
${
AUTO_ATTACH_SETTING
}
`
,
);
`
${
JS_DEBUG_SETTINGS
}
.
${
JS_DEBUG_USEPREVIEWAA
}
`
,
];
const
refreshConfigurationSettings
=
JS_DEBUG_REFRESH_SETTINGS
.
map
(
s
=>
`
${
JS_DEBUG_SETTINGS
}
.
${
s
}
`
);
context
.
subscriptions
.
push
(
context
.
subscriptions
.
push
(
vscode
.
workspace
.
onDidChangeConfiguration
((
e
)
=>
{
vscode
.
workspace
.
onDidChangeConfiguration
(
e
=>
{
if
(
effectualConfigurationSettings
.
some
(
setting
=>
e
.
affectsConfiguration
(
setting
)))
{
// Whenever a setting is changed, disable auto attach, and re-enable
updateAutoAttach
();
// it (if necessary) to refresh variables.
}
else
if
(
refreshConfigurationSettings
.
some
(
setting
=>
e
.
affectsConfiguration
(
setting
)))
{
if
(
currentState
=
currentState
.
then
(
async
s
=>
{
e
.
affectsConfiguration
(
`
${
SETTING_SECTION
}
.
${
SETTING_STATE
}
`
)
||
if
(
s
.
state
!==
State
.
OnWithJsDebug
)
{
[...
SETTINGS_CAUSE_REFRESH
].
some
(
setting
=>
e
.
affectsConfiguration
(
setting
))
return
s
;
)
{
}
updateAutoAttach
(
State
.
Disabled
);
updateAutoAttach
(
readCurrentState
());
await
transitions
[
State
.
OnWithJsDebug
].
exit
?.(
context
,
s
.
transitionData
);
await
clearJsDebugAttachState
(
context
);
const
transitionData
=
await
transitions
[
State
.
OnWithJsDebug
].
enter
?.(
context
);
return
{
context
,
state
:
State
.
OnWithJsDebug
,
transitionData
};
});
}
}
})
})
,
);
);
updateAutoAttach
();
updateAutoAttach
(
readCurrentState
()
);
}
}
export
async
function
deactivate
():
Promise
<
void
>
{
export
async
function
deactivate
():
Promise
<
void
>
{
const
{
context
,
state
,
transitionData
}
=
await
currentState
;
await
destroyAttachServer
();
await
transitions
[
state
].
exit
?.(
context
,
transitionData
);
}
}
function
toggleAutoAttachSetting
()
{
function
getDefaultScope
(
info
:
ReturnType
<
vscode
.
WorkspaceConfiguration
[
'
inspect
'
]
>
)
{
const
conf
=
vscode
.
workspace
.
getConfiguration
(
NODE_DEBUG_SETTINGS
);
if
(
!
info
)
{
if
(
conf
)
{
return
vscode
.
ConfigurationTarget
.
Global
;
let
value
=
<
AUTO_ATTACH_VALUES
>
conf
.
get
(
AUTO_ATTACH_SETTING
);
}
else
if
(
info
.
workspaceFolderValue
)
{
if
(
value
===
'
on
'
)
{
return
vscode
.
ConfigurationTarget
.
WorkspaceFolder
;
value
=
'
off
'
;
}
else
if
(
info
.
workspaceValue
)
{
}
else
{
return
vscode
.
ConfigurationTarget
.
Workspace
;
value
=
'
on
'
;
}
else
if
(
info
.
globalValue
)
{
}
return
vscode
.
ConfigurationTarget
.
Global
;
const
info
=
conf
.
inspect
(
AUTO_ATTACH_SETTING
);
let
target
:
vscode
.
ConfigurationTarget
=
vscode
.
ConfigurationTarget
.
Global
;
if
(
info
)
{
if
(
info
.
workspaceFolderValue
)
{
target
=
vscode
.
ConfigurationTarget
.
WorkspaceFolder
;
}
else
if
(
info
.
workspaceValue
)
{
target
=
vscode
.
ConfigurationTarget
.
Workspace
;
}
else
if
(
info
.
globalValue
)
{
target
=
vscode
.
ConfigurationTarget
.
Global
;
}
else
if
(
info
.
defaultValue
)
{
// setting not yet used: store setting in workspace
if
(
vscode
.
workspace
.
workspaceFolders
)
{
target
=
vscode
.
ConfigurationTarget
.
Workspace
;
}
}
}
conf
.
update
(
AUTO_ATTACH_SETTING
,
value
,
target
);
}
}
return
vscode
.
ConfigurationTarget
.
Global
;
}
}
function
autoAttachWithJsDebug
()
{
type
PickResult
=
{
state
:
State
}
|
{
scope
:
vscode
.
ConfigurationTarget
}
|
undefined
;
const
jsDebugConfig
=
vscode
.
workspace
.
getConfiguration
(
JS_DEBUG_SETTINGS
);
return
jsDebugConfig
.
get
(
JS_DEBUG_USEPREVIEWAA
,
true
);
async
function
toggleAutoAttachSetting
(
scope
?:
vscode
.
ConfigurationTarget
):
Promise
<
void
>
{
const
section
=
vscode
.
workspace
.
getConfiguration
(
SETTING_SECTION
);
scope
=
scope
||
getDefaultScope
(
section
.
inspect
(
SETTING_STATE
));
const
isGlobalScope
=
scope
===
vscode
.
ConfigurationTarget
.
Global
;
const
quickPick
=
vscode
.
window
.
createQuickPick
<
vscode
.
QuickPickItem
&
{
state
:
State
}
>
();
const
current
=
readCurrentState
();
quickPick
.
items
=
[
State
.
Always
,
State
.
Smart
,
State
.
OnlyWithFlag
,
State
.
Disabled
].
map
(
state
=>
({
state
,
label
:
TEXT_STATE_LABEL
[
state
],
description
:
TEXT_STATE_DESCRIPTION
[
state
],
alwaysShow
:
true
,
}));
quickPick
.
activeItems
=
quickPick
.
items
.
filter
(
i
=>
i
.
state
===
current
);
quickPick
.
title
=
isGlobalScope
?
TEXT_TOGGLE_GLOBAL
:
TEXT_TOGGLE_WORKSPACE
;
quickPick
.
buttons
=
[
{
iconPath
:
new
vscode
.
ThemeIcon
(
isGlobalScope
?
'
folder
'
:
'
globe
'
),
tooltip
:
isGlobalScope
?
TEXT_TOGGLE_WORKSPACE
:
TEXT_TOGGLE_GLOBAL
,
},
];
quickPick
.
show
();
const
result
=
await
new
Promise
<
PickResult
>
(
resolve
=>
{
quickPick
.
onDidAccept
(()
=>
resolve
(
quickPick
.
selectedItems
[
0
]));
quickPick
.
onDidHide
(()
=>
resolve
());
quickPick
.
onDidTriggerButton
(()
=>
{
resolve
({
scope
:
isGlobalScope
?
vscode
.
ConfigurationTarget
.
Workspace
:
vscode
.
ConfigurationTarget
.
Global
,
});
});
});
quickPick
.
dispose
();
if
(
!
result
)
{
return
;
}
if
(
'
scope
'
in
result
)
{
return
await
toggleAutoAttachSetting
(
result
.
scope
);
}
if
(
'
state
'
in
result
)
{
section
.
update
(
SETTING_STATE
,
result
.
state
,
scope
);
}
}
}
function
readCurrentState
():
State
{
function
readCurrentState
():
State
{
const
nodeConfig
=
vscode
.
workspace
.
getConfiguration
(
NODE_DEBUG_SETTINGS
);
const
section
=
vscode
.
workspace
.
getConfiguration
(
SETTING_SECTION
);
const
autoAttachState
=
<
AUTO_ATTACH_VALUES
>
nodeConfig
.
get
(
AUTO_ATTACH_SETTING
);
return
section
.
get
<
State
>
(
SETTING_STATE
)
??
State
.
Disabled
;
switch
(
autoAttachState
)
{
case
'
off
'
:
return
State
.
Off
;
case
'
on
'
:
return
autoAttachWithJsDebug
()
?
State
.
OnWithJsDebug
:
State
.
OnWithNodeDebug
;
case
'
disabled
'
:
default
:
return
State
.
Disabled
;
}
}
}
/**
/**
...
@@ -134,7 +176,7 @@ function ensureStatusBarExists(context: vscode.ExtensionContext) {
...
@@ -134,7 +176,7 @@ function ensureStatusBarExists(context: vscode.ExtensionContext) {
statusItem
.
command
=
TOGGLE_COMMAND
;
statusItem
.
command
=
TOGGLE_COMMAND
;
statusItem
.
tooltip
=
localize
(
statusItem
.
tooltip
=
localize
(
'
status.tooltip.auto.attach
'
,
'
status.tooltip.auto.attach
'
,
'
Automatically attach to node.js processes in debug mode
'
'
Automatically attach to node.js processes in debug mode
'
,
);
);
statusItem
.
show
();
statusItem
.
show
();
context
.
subscriptions
.
push
(
statusItem
);
context
.
subscriptions
.
push
(
statusItem
);
...
@@ -146,8 +188,63 @@ function ensureStatusBarExists(context: vscode.ExtensionContext) {
...
@@ -146,8 +188,63 @@ function ensureStatusBarExists(context: vscode.ExtensionContext) {
}
}
async
function
clearJsDebugAttachState
(
context
:
vscode
.
ExtensionContext
)
{
async
function
clearJsDebugAttachState
(
context
:
vscode
.
ExtensionContext
)
{
await
context
.
workspaceState
.
update
(
JS_DEBUG_IPC_KEY
,
undefined
);
await
context
.
workspaceState
.
update
(
STORAGE_IPC
,
undefined
);
await
vscode
.
commands
.
executeCommand
(
'
extension.js-debug.clearAutoAttachVariables
'
);
await
vscode
.
commands
.
executeCommand
(
'
extension.js-debug.clearAutoAttachVariables
'
);
await
destroyAttachServer
();
}
/**
* Turns auto attach on, and returns the server auto attach is listening on
* if it's successful.
*/
async
function
createAttachServer
(
context
:
vscode
.
ExtensionContext
)
{
const
ipcAddress
=
await
getIpcAddress
(
context
);
if
(
!
ipcAddress
)
{
return
undefined
;
}
server
=
new
Promise
<
Server
>
((
resolve
,
reject
)
=>
{
const
s
=
createServer
(
socket
=>
{
let
data
:
Buffer
[]
=
[];
socket
.
on
(
'
data
'
,
async
chunk
=>
{
if
(
chunk
[
chunk
.
length
-
1
]
!==
0
)
{
// terminated with NUL byte
data
.
push
(
chunk
);
return
;
}
data
.
push
(
chunk
.
slice
(
0
,
-
1
));
try
{
await
vscode
.
commands
.
executeCommand
(
'
extension.js-debug.autoAttachToProcess
'
,
JSON
.
parse
(
Buffer
.
concat
(
data
).
toString
()),
);
socket
.
write
(
Buffer
.
from
([
0
]));
}
catch
(
err
)
{
socket
.
write
(
Buffer
.
from
([
1
]));
console
.
error
(
err
);
}
});
})
.
on
(
'
error
'
,
reject
)
.
listen
(
ipcAddress
,
()
=>
resolve
(
s
));
}).
catch
(
err
=>
{
console
.
error
(
err
);
return
undefined
;
});
return
await
server
;
}
/**
* Destroys the auto-attach server, if it's running.
*/
async
function
destroyAttachServer
()
{
const
instance
=
await
server
;
if
(
instance
)
{
await
new
Promise
(
r
=>
instance
.
close
(
r
));
}
}
}
interface
CachedIpcState
{
interface
CachedIpcState
{
...
@@ -156,124 +253,46 @@ interface CachedIpcState {
...
@@ -156,124 +253,46 @@ interface CachedIpcState {
settingsValue
:
string
;
settingsValue
:
string
;
}
}
interface
StateTransition
<
StateData
>
{
onActivate
?(
context
:
vscode
.
ExtensionContext
,
currentState
:
State
):
Promise
<
void
>
;
exit
?(
context
:
vscode
.
ExtensionContext
,
stateData
:
StateData
):
Promise
<
void
>
|
void
;
enter
?(
context
:
vscode
.
ExtensionContext
):
Promise
<
StateData
>
|
StateData
;
}
const
makeTransition
=
<
T
>
(
tsn
:
StateTransition
<
T
>
)
=>
tsn
;
// helper to apply generic type
/**
/**
* Map of logic that happens when auto attach states are entered and exited.
* Map of logic that happens when auto attach states are entered and exited.
* All state transitions are queued and run in order; promises are awaited.
* All state transitions are queued and run in order; promises are awaited.
*/
*/
const
transitions
:
{
[
S
in
State
]:
StateTransition
<
unknown
>
}
=
{
const
transitions
:
{
[
S
in
State
]:
(
context
:
vscode
.
ExtensionContext
)
=>
Promise
<
void
>
}
=
{
[
State
.
Disabled
]:
makeTransition
({
async
[
State
.
Disabled
](
context
)
{
async
enter
(
context
)
{
await
clearJsDebugAttachState
(
context
);
statusItem
?.
hide
();
statusItem
?.
hide
();
await
clearJsDebugAttachState
(
context
);
},
},
}),
async
[
State
.
OnlyWithFlag
](
context
)
{
await
createAttachServer
(
context
);
[
State
.
Off
]:
makeTransition
({
const
statusItem
=
ensureStatusBarExists
(
context
);
enter
(
context
)
{
statusItem
.
text
=
TEXT_WITH_FLAG
;
const
statusItem
=
ensureStatusBarExists
(
context
);
},
statusItem
.
text
=
OFF_TEXT
;
},
async
[
State
.
Smart
](
context
)
{
}),
await
createAttachServer
(
context
);
const
statusItem
=
ensureStatusBarExists
(
context
);
[
State
.
OnWithNodeDebug
]:
makeTransition
({
statusItem
.
text
=
TEXT_SMART
;
async
enter
(
context
)
{
},
const
statusItem
=
ensureStatusBarExists
(
context
);
const
vscode_pid
=
process
.
env
[
'
VSCODE_PID
'
];
async
[
State
.
Always
](
context
)
{
const
rootPid
=
vscode_pid
?
parseInt
(
vscode_pid
)
:
0
;
await
createAttachServer
(
context
);
await
vscode
.
commands
.
executeCommand
(
'
extension.node-debug.startAutoAttach
'
,
rootPid
);
const
statusItem
=
ensureStatusBarExists
(
context
);
statusItem
.
text
=
ON_TEXT
;
statusItem
.
text
=
TEXT_ALWAYS
;
},
},
async
exit
()
{
await
vscode
.
commands
.
executeCommand
(
'
extension.node-debug.stopAutoAttach
'
);
},
}),
[
State
.
OnWithJsDebug
]:
makeTransition
<
Server
|
null
>
({
async
enter
(
context
)
{
const
ipcAddress
=
await
getIpcAddress
(
context
);
if
(
!
ipcAddress
)
{
return
null
;
}
const
server
=
await
new
Promise
<
Server
>
((
resolve
,
reject
)
=>
{
const
s
=
createServer
((
socket
)
=>
{
let
data
:
Buffer
[]
=
[];
socket
.
on
(
'
data
'
,
async
(
chunk
)
=>
{
if
(
chunk
[
chunk
.
length
-
1
]
!==
0
)
{
// terminated with NUL byte
data
.
push
(
chunk
);
return
;
}
data
.
push
(
chunk
.
slice
(
0
,
-
1
));
try
{
await
vscode
.
commands
.
executeCommand
(
'
extension.js-debug.autoAttachToProcess
'
,
JSON
.
parse
(
Buffer
.
concat
(
data
).
toString
())
);
socket
.
write
(
Buffer
.
from
([
0
]));
}
catch
(
err
)
{
socket
.
write
(
Buffer
.
from
([
1
]));
console
.
error
(
err
);
}
});
})
.
on
(
'
error
'
,
reject
)
.
listen
(
ipcAddress
,
()
=>
resolve
(
s
));
}).
catch
(
console
.
error
);
const
statusItem
=
ensureStatusBarExists
(
context
);
statusItem
.
text
=
ON_TEXT
;
return
server
||
null
;
},
async
exit
(
context
,
server
)
{
// we don't need to clear the environment variables--the bootloader will
// no-op if the debug server is closed. This prevents having to reload
// terminals if users want to turn it back on.
if
(
server
)
{
await
new
Promise
((
resolve
)
=>
server
.
close
(
resolve
));
}
// but if they toggled auto attach use js-debug off, go ahead and do so
if
(
!
autoAttachWithJsDebug
())
{
await
clearJsDebugAttachState
(
context
);
}
},
async
onActivate
(
context
,
currentState
)
{
if
(
currentState
===
State
.
OnWithNodeDebug
||
currentState
===
State
.
Disabled
)
{
await
clearJsDebugAttachState
(
context
);
}
}
}),
};
};
/**
/**
* Updates the auto attach feature based on the user or workspace setting
* Updates the auto attach feature based on the user or workspace setting
*/
*/
function
updateAutoAttach
()
{
function
updateAutoAttach
(
newState
:
State
)
{
const
newState
=
readCurrentState
();
currentState
=
currentState
.
then
(
async
({
context
,
state
:
oldState
})
=>
{
currentState
=
currentState
.
then
(
async
({
context
,
state
:
oldState
,
transitionData
})
=>
{
if
(
newState
===
oldState
)
{
if
(
newState
===
oldState
)
{
return
{
context
,
state
:
oldState
,
transitionData
};
return
{
context
,
state
:
oldState
};
}
}
await
transitions
[
oldState
].
exit
?.(
context
,
transitionData
);
await
transitions
[
newState
](
context
);
const
newData
=
await
transitions
[
newState
].
enter
?.(
context
);
return
{
context
,
state
:
newState
};
await
context
.
workspaceState
.
update
(
LAST_STATE_STORAGE_KEY
,
newState
);
return
{
context
,
state
:
newState
,
transitionData
:
newData
};
});
});
}
}
...
@@ -285,41 +304,43 @@ async function getIpcAddress(context: vscode.ExtensionContext) {
...
@@ -285,41 +304,43 @@ async function getIpcAddress(context: vscode.ExtensionContext) {
// Iff the `cachedData` is present, the js-debug registered environment
// Iff the `cachedData` is present, the js-debug registered environment
// variables for this workspace--cachedData is set after successfully
// variables for this workspace--cachedData is set after successfully
// invoking the attachment command.
// invoking the attachment command.
const
cachedIpc
=
context
.
workspaceState
.
get
<
CachedIpcState
>
(
JS_DEBUG_IPC_KEY
);
const
cachedIpc
=
context
.
workspaceState
.
get
<
CachedIpcState
>
(
STORAGE_IPC
);
// We invalidate the IPC data if the js-debug path changes, since that
// We invalidate the IPC data if the js-debug path changes, since that
// indicates the extension was updated or reinstalled and the
// indicates the extension was updated or reinstalled and the
// environment variables will have been lost.
// environment variables will have been lost.
// todo: make a way in the API to read environment data directly without activating js-debug?
// todo: make a way in the API to read environment data directly without activating js-debug?
const
jsDebugPath
=
vscode
.
extensions
.
getExtension
(
'
ms-vscode.js-debug-nightly
'
)?.
extensionPath
const
jsDebugPath
=
||
vscode
.
extensions
.
getExtension
(
'
ms-vscode.js-debug
'
)?.
extensionPath
;
vscode
.
extensions
.
getExtension
(
'
ms-vscode.js-debug-nightly
'
)?.
extensionPath
||
vscode
.
extensions
.
getExtension
(
'
ms-vscode.js-debug
'
)?.
extensionPath
;
const
settingsValue
=
getJsDebugSettingKey
();
const
settingsValue
=
getJsDebugSettingKey
();
if
(
cachedIpc
&&
cachedIpc
.
jsDebugPath
===
jsDebugPath
&&
cachedIpc
.
settingsValue
===
settingsValue
)
{
if
(
cachedIpc
?.
jsDebugPath
===
jsDebugPath
&&
cachedIpc
?
.
settingsValue
===
settingsValue
)
{
return
cachedIpc
.
ipcAddress
;
return
cachedIpc
.
ipcAddress
;
}
}
const
result
=
await
vscode
.
commands
.
executeCommand
<
{
ipcAddress
:
string
;
}
>
(
const
result
=
await
vscode
.
commands
.
executeCommand
<
{
ipcAddress
:
string
}
>
(
'
extension.js-debug.setAutoAttachVariables
'
,
'
extension.js-debug.setAutoAttachVariables
'
,
cachedIpc
?.
ipcAddress
cachedIpc
?.
ipcAddress
,
);
);
if
(
!
result
)
{
if
(
!
result
)
{
return
;
return
;
}
}
const
ipcAddress
=
result
.
ipcAddress
;
const
ipcAddress
=
result
.
ipcAddress
;
await
context
.
workspaceState
.
update
(
await
context
.
workspaceState
.
update
(
STORAGE_IPC
,
{
JS_DEBUG_IPC_KEY
,
ipcAddress
,
{
ipcAddress
,
jsDebugPath
,
settingsValue
}
as
CachedIpcState
,
jsDebugPath
,
);
settingsValue
,
}
as
CachedIpcState
);
return
ipcAddress
;
return
ipcAddress
;
}
}
function
getJsDebugSettingKey
()
{
function
getJsDebugSettingKey
()
{
let
o
:
{
[
key
:
string
]:
unknown
}
=
{};
let
o
:
{
[
key
:
string
]:
unknown
}
=
{};
const
config
=
vscode
.
workspace
.
getConfiguration
(
JS_DEBUG_SETTINGS
);
const
config
=
vscode
.
workspace
.
getConfiguration
(
SETTING_SECTION
);
for
(
const
setting
of
JS_DEBUG_REFRESH_SETTINGS
)
{
for
(
const
setting
of
SETTINGS_CAUSE_REFRESH
)
{
o
[
setting
]
=
config
.
get
(
setting
);
o
[
setting
]
=
config
.
get
(
setting
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录