Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
351b1e45
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,发现更多精彩内容 >>
提交
351b1e45
编写于
11月 27, 2015
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[json] Don't propose keys that are already existing #662
上级
74acc249
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
13 deletion
+15
-13
src/vs/languages/json/common/jsonIntellisense.ts
src/vs/languages/json/common/jsonIntellisense.ts
+9
-1
src/vs/languages/json/test/common/jsonworker.test.ts
src/vs/languages/json/test/common/jsonworker.test.ts
+6
-12
未找到文件。
src/vs/languages/json/common/jsonIntellisense.ts
浏览文件 @
351b1e45
...
...
@@ -67,6 +67,7 @@ export class JSONIntellisense {
var
node
=
doc
.
getNodeFromOffsetEndInclusive
(
offset
);
var
addValue
=
true
;
var
currentKey
=
currentWord
;
var
currentProperty
:
Parser
.
PropertyASTNode
=
null
;
if
(
node
)
{
if
(
node
.
type
===
'
string
'
)
{
...
...
@@ -76,6 +77,7 @@ export class JSONIntellisense {
result
.
overwriteBefore
=
position
.
column
-
nodeRange
.
startColumn
;
result
.
overwriteAfter
=
nodeRange
.
endColumn
-
position
.
column
;
addValue
=
!
(
node
.
parent
&&
((
<
Parser
.
PropertyASTNode
>
node
.
parent
).
value
));
currentProperty
=
node
.
parent
?
<
Parser
.
PropertyASTNode
>
node
.
parent
:
null
;
currentKey
=
modelMirror
.
getValueInRange
({
startColumn
:
nodeRange
.
startColumn
+
1
,
startLineNumber
:
nodeRange
.
startLineNumber
,
endColumn
:
position
.
column
,
endLineNumber
:
position
.
lineNumber
});
if
(
node
.
parent
)
{
node
=
node
.
parent
.
parent
;
...
...
@@ -91,10 +93,16 @@ export class JSONIntellisense {
if
(
node
.
start
===
offset
)
{
return
result
;
}
// don't suggest properties that are already present
var
properties
=
(
<
Parser
.
ObjectASTNode
>
node
).
properties
;
properties
.
forEach
(
p
=>
{
if
(
!
currentProperty
||
currentProperty
!==
p
)
{
proposed
[
p
.
key
.
value
]
=
true
;
}
});
if
(
schema
)
{
// property proposals with schema
var
properties
=
(
<
Parser
.
ObjectASTNode
>
node
).
properties
;
var
isLast
=
properties
.
length
===
0
||
offset
>=
properties
[
properties
.
length
-
1
].
start
;
collectionPromises
.
push
(
this
.
getPropertySuggestions
(
schema
,
doc
,
node
,
currentKey
,
addValue
,
isLast
,
collector
));
...
...
src/vs/languages/json/test/common/jsonworker.test.ts
浏览文件 @
351b1e45
...
...
@@ -179,9 +179,8 @@ suite('JSON - Worker', () => {
assertSuggestion
(
result
,
'
name
'
);
}),
testSuggestionsFor
(
'
[ { "name": "John", "address": { "street" : "MH Road", "number" : 5 } }, { "name": "Jack", "address": { "street" : "100 Feet Road", /**/ }
'
,
'
/**/
'
).
then
((
result
)
=>
{
assert
.
strictEqual
(
result
.
suggestions
.
length
,
2
);
assert
.
strictEqual
(
result
.
suggestions
.
length
,
1
);
assertSuggestion
(
result
,
'
number
'
);
assertSuggestion
(
result
,
'
street
'
);
})
]).
done
(()
=>
testDone
(),
(
errors
:
any
[])
=>
{
testDone
(
errors
.
reduce
((
e1
,
e2
)
=>
e1
||
e2
));
...
...
@@ -216,8 +215,7 @@ suite('JSON - Worker', () => {
assertSuggestion
(
result
,
'
"xoo"
'
);
}),
testSuggestionsFor
(
'
[ { "data": "foo" }, { "data": "bar" }, { "data": "xoo" /**/ } ]
'
,
'
/**/
'
).
then
((
result
)
=>
{
assert
.
strictEqual
(
result
.
suggestions
.
length
,
1
);
assertSuggestion
(
result
,
'
data
'
);
assert
.
strictEqual
(
result
.
suggestions
.
length
,
0
);
})
]).
done
(()
=>
testDone
(),
(
errors
:
any
[])
=>
{
testDone
(
errors
.
reduce
((
e1
,
e2
)
=>
e1
||
e2
));
...
...
@@ -260,8 +258,7 @@ suite('JSON - Worker', () => {
assertSuggestion
(
result
,
'
a
'
,
'
A
'
);
}),
testSuggestionsFor
(
'
{ "a" = 1;/**/}
'
,
'
/**/
'
,
schema
).
then
((
result
)
=>
{
assert
.
strictEqual
(
result
.
suggestions
.
length
,
3
);
assertSuggestion
(
result
,
'
a
'
,
'
A
'
);
assert
.
strictEqual
(
result
.
suggestions
.
length
,
2
);
assertSuggestion
(
result
,
'
b
'
,
'
B
'
);
assertSuggestion
(
result
,
'
c
'
,
'
C
'
);
})
...
...
@@ -375,8 +372,7 @@ suite('JSON - Worker', () => {
assertSuggestion
(
result
,
'
d
'
,
'
D
'
);
}),
testSuggestionsFor
(
'
{ "a": "", /**/}
'
,
'
/**/
'
,
schema
).
then
((
result
)
=>
{
assert
.
strictEqual
(
result
.
suggestions
.
length
,
2
);
assertSuggestion
(
result
,
'
a
'
,
'
A
'
);
assert
.
strictEqual
(
result
.
suggestions
.
length
,
1
);
assertSuggestion
(
result
,
'
b
'
,
'
B
'
);
})
]).
done
(()
=>
testDone
(),
(
errors
:
any
[])
=>
{
...
...
@@ -417,8 +413,7 @@ suite('JSON - Worker', () => {
assertSuggestion
(
result
,
'
c
'
);
}),
testSuggestionsFor
(
'
{ "type": "appartment", /**/}
'
,
'
/**/
'
,
schema
).
then
((
result
)
=>
{
assert
.
strictEqual
(
result
.
suggestions
.
length
,
2
);
assertSuggestion
(
result
,
'
type
'
);
assert
.
strictEqual
(
result
.
suggestions
.
length
,
1
);
assertSuggestion
(
result
,
'
c
'
);
})
]).
done
(()
=>
testDone
(),
(
errors
:
any
[])
=>
{
...
...
@@ -480,9 +475,8 @@ suite('JSON - Worker', () => {
assertSuggestion
(
result
,
'
d
'
,
'
D
'
);
}),
testSuggestionsFor
(
'
{ "b1": "", /**/}
'
,
'
/**/
'
,
schema
).
then
((
result
)
=>
{
assert
.
strictEqual
(
result
.
suggestions
.
length
,
3
);
assert
.
strictEqual
(
result
.
suggestions
.
length
,
2
);
assertSuggestion
(
result
,
'
a
'
,
'
A
'
);
assertSuggestion
(
result
,
'
b1
'
,
'
B1
'
);
assertSuggestion
(
result
,
'
b2
'
,
'
B2
'
);
})
]).
done
(()
=>
testDone
(),
(
errors
:
any
[])
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录