Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9c7a6502
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,发现更多精彩内容 >>
提交
9c7a6502
编写于
11月 21, 2017
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[json] IntelliSense don't work for @angular in package.json. Fixes #24321
上级
f8665216
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
1 deletion
+79
-1
extensions/javascript/src/features/packageJSONContribution.ts
...nsions/javascript/src/features/packageJSONContribution.ts
+79
-1
未找到文件。
extensions/javascript/src/features/packageJSONContribution.ts
浏览文件 @
9c7a6502
...
...
@@ -14,6 +14,9 @@ import * as nls from 'vscode-nls';
const
localize
=
nls
.
loadMessageBundle
();
const
LIMIT
=
40
;
const
SCOPED_LIMIT
=
250
;
const
USER_AGENT
=
'
Visual Studio Code
'
;
export
class
PackageJSONContribution
implements
IJSONContribution
{
...
...
@@ -24,6 +27,8 @@ export class PackageJSONContribution implements IJSONContribution {
'
shelljs
'
,
'
gulp
'
,
'
yargs
'
,
'
browserify
'
,
'
minimatch
'
,
'
react
'
,
'
less
'
,
'
prompt
'
,
'
inquirer
'
,
'
ws
'
,
'
event-stream
'
,
'
inherits
'
,
'
mysql
'
,
'
esprima
'
,
'
jsdom
'
,
'
stylus
'
,
'
when
'
,
'
readable-stream
'
,
'
aws-sdk
'
,
'
concat-stream
'
,
'
chai
'
,
'
Thenable
'
,
'
wrench
'
];
private
knownScopes
=
[
'
@types
'
,
'
@angular
'
];
public
getDocumentSelector
():
DocumentSelector
{
return
[{
language
:
'
json
'
,
pattern
:
'
**/package.json
'
}];
}
...
...
@@ -58,10 +63,15 @@ export class PackageJSONContribution implements IJSONContribution {
if
((
location
.
matches
([
'
dependencies
'
])
||
location
.
matches
([
'
devDependencies
'
])
||
location
.
matches
([
'
optionalDependencies
'
])
||
location
.
matches
([
'
peerDependencies
'
])))
{
let
queryUrl
:
string
;
if
(
currentWord
.
length
>
0
)
{
if
(
currentWord
[
0
]
===
'
@
'
)
{
return
this
.
collectScopedPackages
(
currentWord
,
addValue
,
isLast
,
collector
);
}
queryUrl
=
'
https://skimdb.npmjs.com/registry/_design/app/_view/browseAll?group_level=1&limit=
'
+
LIMIT
+
'
&start_key=%5B%22
'
+
encodeURIComponent
(
currentWord
)
+
'
%22%5D&end_key=%5B%22
'
+
encodeURIComponent
(
currentWord
+
'
z
'
)
+
'
%22,%7B%7D%5D
'
;
return
this
.
xhr
({
url
:
queryUrl
url
:
queryUrl
,
agent
:
USER_AGENT
}).
then
((
success
)
=>
{
if
(
success
.
status
===
200
)
{
try
{
...
...
@@ -119,6 +129,7 @@ export class PackageJSONContribution implements IJSONContribution {
proposal
.
documentation
=
''
;
collector
.
add
(
proposal
);
});
this
.
collectScopedPackages
(
currentWord
,
addValue
,
isLast
,
collector
);
collector
.
setAsIncomplete
();
return
Promise
.
resolve
(
null
);
}
...
...
@@ -126,6 +137,73 @@ export class PackageJSONContribution implements IJSONContribution {
return
null
;
}
private
collectScopedPackages
(
currentWord
:
string
,
addValue
:
boolean
,
isLast
:
boolean
,
collector
:
ISuggestionsCollector
):
Thenable
<
any
>
{
let
segments
=
currentWord
.
split
(
'
/
'
);
if
(
segments
.
length
===
1
)
{
for
(
let
scope
of
this
.
knownScopes
)
{
const
proposal
=
new
CompletionItem
(
scope
);
proposal
.
kind
=
CompletionItemKind
.
Property
;
proposal
.
insertText
=
new
SnippetString
().
appendText
(
`"
${
scope
}
/`
).
appendTabstop
().
appendText
(
'
"
'
);
proposal
.
filterText
=
JSON
.
stringify
(
scope
);
proposal
.
documentation
=
''
;
proposal
.
command
=
{
title
:
''
,
command
:
'
editor.action.triggerSuggest
'
};
collector
.
add
(
proposal
);
}
}
else
if
(
segments
.
length
===
2
&&
segments
[
0
].
length
>
1
)
{
let
scope
=
segments
[
0
].
substr
(
1
);
let
queryUrl
=
`https://registry.npmjs.org/-/v1/search?text=scope:
${
scope
}
%20
${
segments
[
1
]}
&size=
${
SCOPED_LIMIT
}
&popularity=1.0`
;
return
this
.
xhr
({
url
:
queryUrl
,
agent
:
USER_AGENT
}).
then
((
success
)
=>
{
if
(
success
.
status
===
200
)
{
try
{
const
obj
=
JSON
.
parse
(
success
.
responseText
);
if
(
obj
&&
Array
.
isArray
(
obj
.
objects
))
{
const
objects
=
<
{
package
:
{
name
:
string
;
version
:
string
,
description
:
string
;
}
}[]
>
obj
.
objects
;
for
(
let
object
of
objects
)
{
if
(
object
.
package
&&
object
.
package
.
name
)
{
const
name
=
object
.
package
.
name
;
const
insertText
=
new
SnippetString
().
appendText
(
JSON
.
stringify
(
name
));
if
(
addValue
)
{
insertText
.
appendText
(
'
: "
'
);
if
(
object
.
package
.
version
)
{
insertText
.
appendVariable
(
'
version
'
,
object
.
package
.
version
);
}
else
{
insertText
.
appendTabstop
();
}
insertText
.
appendText
(
'
"
'
);
if
(
!
isLast
)
{
insertText
.
appendText
(
'
,
'
);
}
}
const
proposal
=
new
CompletionItem
(
name
);
proposal
.
kind
=
CompletionItemKind
.
Property
;
proposal
.
insertText
=
insertText
;
proposal
.
filterText
=
JSON
.
stringify
(
name
);
proposal
.
documentation
=
object
.
package
.
description
||
''
;
collector
.
add
(
proposal
);
}
}
if
(
objects
.
length
===
SCOPED_LIMIT
)
{
collector
.
setAsIncomplete
();
}
}
}
catch
(
e
)
{
// ignore
}
}
else
{
collector
.
error
(
localize
(
'
json.npm.error.repoaccess
'
,
'
Request to the NPM repository failed: {0}
'
,
success
.
responseText
));
}
return
null
;
});
}
return
Promise
.
resolve
(
null
);
}
public
collectValueSuggestions
(
_fileName
:
string
,
location
:
Location
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录