Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
5505935f
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,发现更多精彩内容 >>
提交
5505935f
编写于
7月 28, 2018
作者:
E
Erich Gamma
提交者:
Martin Aeschlimann
7月 30, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added command to Run the selected npm script
上级
50dba370
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
88 addition
and
4 deletion
+88
-4
extensions/npm/README.md
extensions/npm/README.md
+2
-1
extensions/npm/package.json
extensions/npm/package.json
+4
-0
extensions/npm/package.nls.json
extensions/npm/package.nls.json
+2
-1
extensions/npm/src/commands.ts
extensions/npm/src/commands.ts
+32
-0
extensions/npm/src/main.ts
extensions/npm/src/main.ts
+2
-1
extensions/npm/src/tasks.ts
extensions/npm/src/tasks.ts
+46
-1
未找到文件。
extensions/npm/README.md
浏览文件 @
5505935f
...
...
@@ -19,7 +19,8 @@ The Npm Script Explorer shows the npm scripts found in your workspace. The explo
### Run Scripts from the Editor
The extension provides code lense actions to run or debug a script from the editor.
The extension supports to run the selected script as a task when editing the
`package.json`
file. You can either run a script from
the hover shown on a script or using the command
`Run Selected Npm Script`
.
### Others
...
...
extensions/npm/package.json
浏览文件 @
5505935f
...
...
@@ -82,6 +82,10 @@
"light"
:
"resources/light/refresh.svg"
,
"dark"
:
"resources/dark/refresh.svg"
}
},
{
"command"
:
"npm.runSelectedScript"
,
"title"
:
"%command.runSelectedScript%"
}
],
"menus"
:
{
...
...
extensions/npm/package.nls.json
浏览文件 @
5505935f
...
...
@@ -16,5 +16,6 @@
"command.run"
:
"Run"
,
"command.debug"
:
"Debug"
,
"command.openScript"
:
"Open"
,
"command.runInstall"
:
"Run Install"
"command.runInstall"
:
"Run Install"
,
"command.runSelectedScript"
:
"Run Selected Npm Script"
}
extensions/npm/src/commands.ts
0 → 100644
浏览文件 @
5505935f
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
runScript
,
findScriptAtPosition
}
from
'
./tasks
'
;
import
*
as
nls
from
'
vscode-nls
'
;
const
localize
=
nls
.
loadMessageBundle
();
export
function
runSelectedScript
()
{
let
editor
=
vscode
.
window
.
activeTextEditor
;
if
(
!
editor
)
{
return
;
}
let
document
=
editor
.
document
;
let
contents
=
document
.
getText
();
let
selection
=
editor
.
selection
;
let
offset
=
document
.
offsetAt
(
selection
.
anchor
);
let
script
=
findScriptAtPosition
(
contents
,
offset
);
if
(
script
)
{
runScript
(
script
,
document
);
}
else
{
let
message
=
localize
(
'
noScriptFound
'
,
'
Could not find an npm script at the selection.
'
);
vscode
.
window
.
showErrorMessage
(
message
);
}
}
\ No newline at end of file
extensions/npm/src/main.ts
浏览文件 @
5505935f
...
...
@@ -10,6 +10,7 @@ import { addJSONProviders } from './features/jsonContributions';
import
{
NpmScriptsTreeDataProvider
}
from
'
./npmView
'
;
import
{
invalidateTasksCache
,
NpmTaskProvider
}
from
'
./tasks
'
;
import
{
invalidateHoverScriptsCache
,
NpmScriptHoverProvider
}
from
'
./scriptHover
'
;
import
{
runSelectedScript
}
from
'
./commands
'
;
export
async
function
activate
(
context
:
vscode
.
ExtensionContext
):
Promise
<
void
>
{
const
taskProvider
=
registerTaskProvider
(
context
);
...
...
@@ -37,7 +38,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
invalidateHoverScriptsCache
(
e
.
document
);
});
context
.
subscriptions
.
push
(
d
);
context
.
subscriptions
.
push
(
vscode
.
commands
.
registerCommand
(
'
npm.runSelectedScript
'
,
runSelectedScript
));
context
.
subscriptions
.
push
(
addJSONProviders
(
httpRequest
.
xhr
));
}
...
...
extensions/npm/src/tasks.ts
浏览文件 @
5505935f
...
...
@@ -6,7 +6,7 @@
import
{
TaskDefinition
,
Task
,
TaskGroup
,
WorkspaceFolder
,
RelativePattern
,
ShellExecution
,
Uri
,
workspace
,
DebugConfiguration
,
debug
,
TaskProvider
,
ExtensionContext
DebugConfiguration
,
debug
,
TaskProvider
,
ExtensionContext
,
TextDocument
,
tasks
}
from
'
vscode
'
;
import
*
as
path
from
'
path
'
;
import
*
as
fs
from
'
fs
'
;
...
...
@@ -288,6 +288,15 @@ async function readFile(file: string): Promise<string> {
});
}
export
function
runScript
(
script
:
string
,
document
:
TextDocument
)
{
let
uri
=
document
.
uri
;
let
folder
=
workspace
.
getWorkspaceFolder
(
uri
);
if
(
folder
)
{
let
task
=
createTask
(
script
,
`run
${
script
}
`
,
folder
,
uri
);
tasks
.
executeTask
(
task
);
}
}
export
function
extractDebugArgFromScript
(
scriptValue
:
string
):
[
string
,
number
]
|
undefined
{
// matches --debug, --debug=1234, --debug-brk, debug-brk=1234, --inspect,
// --inspect=1234, --inspect-brk, --inspect-brk=1234,
...
...
@@ -405,6 +414,42 @@ export function findAllScriptRanges(buffer: string): Map<string, [number, number
return
scripts
;
}
export
function
findScriptAtPosition
(
buffer
:
string
,
offset
:
number
):
string
|
undefined
{
let
script
:
string
|
undefined
=
undefined
;
let
inScripts
=
false
;
let
scriptStart
:
number
|
undefined
;
let
visitor
:
JSONVisitor
=
{
onError
(
_error
:
ParseErrorCode
,
_offset
:
number
,
_length
:
number
)
{
},
onObjectEnd
()
{
if
(
inScripts
)
{
inScripts
=
false
;
scriptStart
=
undefined
;
}
},
onLiteralValue
(
value
:
any
,
nodeOffset
:
number
,
nodeLength
:
number
)
{
if
(
inScripts
&&
scriptStart
)
{
if
(
offset
>=
scriptStart
&&
offset
<
nodeOffset
+
nodeLength
)
{
// found the script
inScripts
=
false
;
}
else
{
script
=
undefined
;
}
}
},
onObjectProperty
(
property
:
string
,
nodeOffset
:
number
,
nodeLength
:
number
)
{
if
(
property
===
'
scripts
'
)
{
inScripts
=
true
;
}
else
if
(
inScripts
)
{
scriptStart
=
nodeOffset
;
script
=
property
;
}
}
};
visit
(
buffer
,
visitor
);
return
script
;
}
export
async
function
getScripts
(
packageJsonUri
:
Uri
):
Promise
<
StringMap
|
undefined
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录