Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
9bc4699d
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,发现更多精彩内容 >>
提交
9bc4699d
编写于
6月 13, 2019
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
package.json suggestions stopped working - skimdb is being retired. Fixes #75274
上级
56d1a02b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
66 addition
and
67 deletion
+66
-67
extensions/npm/src/features/packageJSONContribution.ts
extensions/npm/src/features/packageJSONContribution.ts
+66
-67
未找到文件。
extensions/npm/src/features/packageJSONContribution.ts
浏览文件 @
9bc4699d
...
...
@@ -74,11 +74,25 @@ export class PackageJSONContribution implements IJSONContribution {
let
queryUrl
:
string
;
if
(
currentWord
.
length
>
0
)
{
if
(
currentWord
[
0
]
===
'
@
'
)
{
return
this
.
collectScopedPackages
(
currentWord
,
addValue
,
isLast
,
collector
);
if
(
currentWord
.
indexOf
(
'
/
'
)
!==
-
1
)
{
return
this
.
collectScopedPackages
(
currentWord
,
addValue
,
isLast
,
collector
);
}
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
);
}
collector
.
setAsIncomplete
();
}
queryUrl
=
'
https://skimdb.npmjs.com/registry/_design/app/_view/browseAll?group_level=2&limit=
'
+
LIMIT
+
'
&start_key=%5B%22
'
+
encodeURIComponent
(
currentWord
)
+
'
%22%5D&end_key=%5B%22
'
+
encodeURIComponent
(
currentWord
+
'
z
'
)
+
'
%22,%7B%7D%5D
'
;
queryUrl
=
`https://api.npms.io/v2/search/suggestions?size=
${
LIMIT
}
&q=
${
encodeURIComponent
(
currentWord
)}
`
;
return
this
.
xhr
({
url
:
queryUrl
,
agent
:
USER_AGENT
...
...
@@ -86,26 +100,10 @@ export class PackageJSONContribution implements IJSONContribution {
if
(
success
.
status
===
200
)
{
try
{
const
obj
=
JSON
.
parse
(
success
.
responseText
);
if
(
obj
&&
Array
.
isArray
(
obj
.
rows
))
{
const
results
=
<
{
key
:
string
[];
}[]
>
obj
.
rows
;
if
(
obj
&&
Array
.
isArray
(
obj
))
{
const
results
=
<
{
package
:
SearchPackageInfo
;
}[]
>
obj
;
for
(
const
result
of
results
)
{
const
keys
=
result
.
key
;
if
(
Array
.
isArray
(
keys
)
&&
keys
.
length
>
0
)
{
const
name
=
keys
[
0
];
const
insertText
=
new
SnippetString
().
appendText
(
JSON
.
stringify
(
name
));
if
(
addValue
)
{
insertText
.
appendText
(
'
: "
'
).
appendTabstop
().
appendText
(
'
"
'
);
if
(
!
isLast
)
{
insertText
.
appendText
(
'
,
'
);
}
}
const
proposal
=
new
CompletionItem
(
name
);
proposal
.
kind
=
CompletionItemKind
.
Property
;
proposal
.
insertText
=
insertText
;
proposal
.
filterText
=
JSON
.
stringify
(
name
);
proposal
.
documentation
=
keys
[
1
];
collector
.
add
(
proposal
);
}
this
.
processPackage
(
result
.
package
,
addValue
,
isLast
,
collector
);
}
if
(
results
.
length
===
LIMIT
)
{
collector
.
setAsIncomplete
();
...
...
@@ -149,20 +147,7 @@ export class PackageJSONContribution implements IJSONContribution {
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
)
{
if
(
segments
.
length
===
2
&&
segments
[
0
].
length
>
1
)
{
let
scope
=
segments
[
0
].
substr
(
1
);
let
name
=
segments
[
1
];
if
(
name
.
length
<
4
)
{
...
...
@@ -177,30 +162,9 @@ export class PackageJSONContribution implements IJSONContribution {
try
{
const
obj
=
JSON
.
parse
(
success
.
responseText
);
if
(
obj
&&
Array
.
isArray
(
obj
.
results
))
{
const
objects
=
<
{
package
:
{
name
:
string
;
version
:
string
,
description
:
string
;
}
}[]
>
obj
.
results
;
const
objects
=
<
{
package
:
SearchPackageInfo
}[]
>
obj
.
results
;
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
);
}
this
.
processPackage
(
object
.
package
,
addValue
,
isLast
,
collector
);
}
if
(
objects
.
length
===
SCOPED_LIMIT
)
{
collector
.
setAsIncomplete
();
...
...
@@ -291,19 +255,23 @@ export class PackageJSONContribution implements IJSONContribution {
});
}
private
npmView
(
pack
:
string
):
Promise
<
PackageInfo
>
{
private
npmView
(
pack
:
string
):
Promise
<
View
PackageInfo
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
command
=
'
npm view --json
'
+
pack
+
'
description dist-tags.latest homepage
'
;
cp
.
exec
(
command
,
(
error
,
stdout
)
=>
{
if
(
error
)
{
return
reject
();
}
const
content
=
JSON
.
parse
(
stdout
);
resolve
({
description
:
content
[
'
description
'
],
distTagsLatest
:
content
[
'
dist-tags.latest
'
],
homepage
:
content
[
'
homepage
'
]
});
try
{
const
content
=
JSON
.
parse
(
stdout
);
resolve
({
description
:
content
[
'
description
'
],
distTagsLatest
:
content
[
'
dist-tags.latest
'
],
homepage
:
content
[
'
homepage
'
]
});
}
catch
(
e
)
{
reject
();
}
});
});
}
...
...
@@ -322,9 +290,40 @@ export class PackageJSONContribution implements IJSONContribution {
}
return
null
;
}
private
processPackage
(
pack
:
SearchPackageInfo
,
addValue
:
boolean
,
isLast
:
boolean
,
collector
:
ISuggestionsCollector
)
{
if
(
pack
&&
pack
.
name
)
{
const
name
=
pack
.
name
;
const
insertText
=
new
SnippetString
().
appendText
(
JSON
.
stringify
(
name
));
if
(
addValue
)
{
insertText
.
appendText
(
'
: "
'
);
if
(
pack
.
version
)
{
insertText
.
appendVariable
(
'
version
'
,
pack
.
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
=
pack
.
description
||
''
;
collector
.
add
(
proposal
);
}
}
}
interface
SearchPackageInfo
{
name
:
string
;
description
?:
string
;
version
?:
string
;
}
interface
PackageInfo
{
interface
View
PackageInfo
{
description
:
string
;
distTagsLatest
?:
string
;
homepage
?:
string
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录