Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徽霖
Vscode
提交
5785cf46
V
Vscode
项目概览
徽霖
/
Vscode
通知
9
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,发现更多精彩内容 >>
提交
5785cf46
编写于
1月 28, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixes #2365: [json] JSON could complete identifier with quotes
上级
706413e5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
50 deletion
+60
-50
extensions/json/server/src/jsonCompletion.ts
extensions/json/server/src/jsonCompletion.ts
+60
-50
未找到文件。
extensions/json/server/src/jsonCompletion.ts
浏览文件 @
5785cf46
...
...
@@ -107,10 +107,10 @@ export class JSONCompletion {
let
isLast
=
properties
.
length
===
0
||
offset
>=
properties
[
properties
.
length
-
1
].
start
;
if
(
schema
)
{
// property proposals with schema
this
.
getPropertySuggestions
(
schema
,
doc
,
node
,
currentKey
,
addValue
,
isLast
,
collector
);
}
else
if
(
node
.
parent
)
{
this
.
getPropertySuggestions
(
schema
,
doc
,
node
,
addValue
,
isLast
,
collector
);
}
else
{
// property proposals without schema
this
.
getSchemaLessPropertySuggestions
(
doc
,
node
,
collector
);
this
.
getSchemaLessPropertySuggestions
(
doc
,
node
,
c
urrentKey
,
currentWord
,
isLast
,
c
ollector
);
}
let
location
=
node
.
getNodeLocation
();
...
...
@@ -134,7 +134,8 @@ export class JSONCompletion {
}
else
{
// value proposals without schema
this
.
getSchemaLessValueSuggestions
(
doc
,
node
,
offset
,
document
,
collector
);
}
}
if
(
!
node
)
{
this
.
contributions
.
forEach
((
contribution
)
=>
{
let
collectPromise
=
contribution
.
collectDefaultSuggestions
(
textDocumentPosition
.
uri
,
collector
);
...
...
@@ -162,7 +163,7 @@ export class JSONCompletion {
});
}
private
getPropertySuggestions
(
schema
:
SchemaService
.
ResolvedSchema
,
doc
:
Parser
.
JSONDocument
,
node
:
Parser
.
ASTNode
,
currentWord
:
string
,
addValue
:
boolean
,
isLast
:
boolean
,
collector
:
ISuggestionsCollector
):
void
{
private
getPropertySuggestions
(
schema
:
SchemaService
.
ResolvedSchema
,
doc
:
Parser
.
JSONDocument
,
node
:
Parser
.
ASTNode
,
addValue
:
boolean
,
isLast
:
boolean
,
collector
:
ISuggestionsCollector
):
void
{
let
matchingSchemas
:
Parser
.
IApplicableSchema
[]
=
[];
doc
.
validate
(
schema
.
schema
,
matchingSchemas
,
node
.
start
);
...
...
@@ -179,29 +180,34 @@ export class JSONCompletion {
});
}
private
getSchemaLessPropertySuggestions
(
doc
:
Parser
.
JSONDocument
,
node
:
Parser
.
ASTNode
,
collector
:
ISuggestionsCollector
):
void
{
private
getSchemaLessPropertySuggestions
(
doc
:
Parser
.
JSONDocument
,
node
:
Parser
.
ASTNode
,
c
urrentKey
:
string
,
currentWord
:
string
,
isLast
:
boolean
,
c
ollector
:
ISuggestionsCollector
):
void
{
let
collectSuggestionsForSimilarObject
=
(
obj
:
Parser
.
ObjectASTNode
)
=>
{
obj
.
properties
.
forEach
((
p
)
=>
{
let
key
=
p
.
key
.
value
;
collector
.
add
({
kind
:
CompletionItemKind
.
Property
,
label
:
key
,
insertText
:
this
.
getSnippetForSimilarProperty
(
key
,
p
.
value
),
documentation
:
''
});
});
};
if
(
node
.
parent
.
type
===
'
property
'
)
{
// if the object is a property value, check the tree for other objects that hang under a property of the same name
let
parentKey
=
(
<
Parser
.
PropertyASTNode
>
node
.
parent
).
key
.
value
;
doc
.
visit
((
n
)
=>
{
if
(
n
.
type
===
'
property
'
&&
(
<
Parser
.
PropertyASTNode
>
n
).
key
.
value
===
parentKey
&&
(
<
Parser
.
PropertyASTNode
>
n
).
value
&&
(
<
Parser
.
PropertyASTNode
>
n
).
value
.
type
===
'
object
'
)
{
collectSuggestionsForSimilarObject
(
<
Parser
.
ObjectASTNode
>
(
<
Parser
.
PropertyASTNode
>
n
).
value
);
}
return
true
;
});
}
else
if
(
node
.
parent
.
type
===
'
array
'
)
{
// if the object is in an array, use all other array elements as similar objects
(
<
Parser
.
ArrayASTNode
>
node
.
parent
).
items
.
forEach
((
n
)
=>
{
if
(
n
.
type
===
'
object
'
&&
n
!==
node
)
{
collectSuggestionsForSimilarObject
(
<
Parser
.
ObjectASTNode
>
n
);
}
});
if
(
node
.
parent
)
{
if
(
node
.
parent
.
type
===
'
property
'
)
{
// if the object is a property value, check the tree for other objects that hang under a property of the same name
let
parentKey
=
(
<
Parser
.
PropertyASTNode
>
node
.
parent
).
key
.
value
;
doc
.
visit
((
n
)
=>
{
if
(
n
.
type
===
'
property
'
&&
(
<
Parser
.
PropertyASTNode
>
n
).
key
.
value
===
parentKey
&&
(
<
Parser
.
PropertyASTNode
>
n
).
value
&&
(
<
Parser
.
PropertyASTNode
>
n
).
value
.
type
===
'
object
'
)
{
collectSuggestionsForSimilarObject
(
<
Parser
.
ObjectASTNode
>
(
<
Parser
.
PropertyASTNode
>
n
).
value
);
}
return
true
;
});
}
else
if
(
node
.
parent
.
type
===
'
array
'
)
{
// if the object is in an array, use all other array elements as similar objects
(
<
Parser
.
ArrayASTNode
>
node
.
parent
).
items
.
forEach
((
n
)
=>
{
if
(
n
.
type
===
'
object
'
&&
n
!==
node
)
{
collectSuggestionsForSimilarObject
(
<
Parser
.
ObjectASTNode
>
n
);
}
});
}
}
if
(
!
currentKey
&&
currentWord
.
length
>
0
)
{
collector
.
add
({
kind
:
CompletionItemKind
.
Property
,
label
:
JSON
.
stringify
(
currentWord
),
insertText
:
this
.
getSnippetForProperty
(
currentWord
,
null
,
true
,
isLast
),
documentation
:
''
});
}
}
...
...
@@ -403,35 +409,39 @@ export class JSONCompletion {
return
result
;
}
result
+=
'
:
'
;
let
defaultVal
=
propertySchema
.
default
;
if
(
typeof
defaultVal
!==
'
undefined
'
)
{
result
=
result
+
this
.
getSnippetForValue
(
defaultVal
);
}
else
if
(
propertySchema
.
enum
&&
propertySchema
.
enum
.
length
>
0
)
{
result
=
result
+
this
.
getSnippetForValue
(
propertySchema
.
enum
[
0
]);
}
else
{
switch
(
propertySchema
.
type
)
{
case
'
boolean
'
:
result
+=
'
{{false}}
'
;
break
;
case
'
string
'
:
result
+=
'
"{{}}"
'
;
break
;
case
'
object
'
:
result
+=
'
{
\n\t
{{}}
\n
}
'
;
break
;
case
'
array
'
:
result
+=
'
[
\n\t
{{}}
\n
]
'
;
break
;
case
'
number
'
:
result
+=
'
{{0}}
'
;
break
;
case
'
null
'
:
result
+=
'
{{null}}
'
;
break
;
default
:
return
result
;
if
(
propertySchema
)
{
let
defaultVal
=
propertySchema
.
default
;
if
(
typeof
defaultVal
!==
'
undefined
'
)
{
result
=
result
+
this
.
getSnippetForValue
(
defaultVal
);
}
else
if
(
propertySchema
.
enum
&&
propertySchema
.
enum
.
length
>
0
)
{
result
=
result
+
this
.
getSnippetForValue
(
propertySchema
.
enum
[
0
]);
}
else
{
switch
(
propertySchema
.
type
)
{
case
'
boolean
'
:
result
+=
'
{{false}}
'
;
break
;
case
'
string
'
:
result
+=
'
"{{}}"
'
;
break
;
case
'
object
'
:
result
+=
'
{
\n\t
{{}}
\n
}
'
;
break
;
case
'
array
'
:
result
+=
'
[
\n\t
{{}}
\n
]
'
;
break
;
case
'
number
'
:
result
+=
'
{{0}}
'
;
break
;
case
'
null
'
:
result
+=
'
{{null}}
'
;
break
;
default
:
return
result
;
}
}
}
else
{
result
+=
'
{{0}}
'
;
}
if
(
!
isLast
)
{
result
+=
'
,
'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录