Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
b7e6e6fa
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,发现更多精彩内容 >>
提交
b7e6e6fa
编写于
2月 10, 2016
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[json] better support for null, and array of types
上级
0f6a10b4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
10 deletion
+55
-10
extensions/json/server/src/jsonCompletion.ts
extensions/json/server/src/jsonCompletion.ts
+25
-8
extensions/json/server/src/jsonParser.ts
extensions/json/server/src/jsonParser.ts
+1
-1
extensions/json/server/src/test/completion.test.ts
extensions/json/server/src/test/completion.test.ts
+29
-1
未找到文件。
extensions/json/server/src/jsonCompletion.ts
浏览文件 @
b7e6e6fa
...
...
@@ -73,7 +73,7 @@ export class JSONCompletion {
let
addValue
=
true
;
let
currentKey
=
''
;
let
currentProperty
:
Parser
.
PropertyASTNode
=
null
;
if
(
node
)
{
...
...
@@ -134,8 +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
);
...
...
@@ -305,12 +305,21 @@ export class JSONCompletion {
collector
.
add
({
kind
:
this
.
getSuggestionKind
(
'
boolean
'
),
label
:
value
?
'
true
'
:
'
false
'
,
insertText
:
this
.
getTextForValue
(
value
),
documentation
:
''
});
}
private
addNullSuggestion
(
collector
:
ISuggestionsCollector
):
void
{
collector
.
add
({
kind
:
this
.
getSuggestionKind
(
'
null
'
),
label
:
'
null
'
,
insertText
:
'
null
'
,
documentation
:
''
});
}
private
addEnumSuggestion
(
schema
:
JsonSchema
.
IJSONSchema
,
collector
:
ISuggestionsCollector
):
void
{
if
(
Array
.
isArray
(
schema
.
enum
))
{
schema
.
enum
.
forEach
((
enm
)
=>
collector
.
add
({
kind
:
this
.
getSuggestionKind
(
schema
.
type
),
label
:
this
.
getLabelForValue
(
enm
),
insertText
:
this
.
getTextForValue
(
enm
),
documentation
:
''
}));
}
else
if
(
schema
.
type
===
'
boolean
'
)
{
this
.
addBooleanSuggestion
(
true
,
collector
);
this
.
addBooleanSuggestion
(
false
,
collector
);
}
else
{
if
(
this
.
isType
(
schema
,
'
boolean
'
))
{
this
.
addBooleanSuggestion
(
true
,
collector
);
this
.
addBooleanSuggestion
(
false
,
collector
);
}
if
(
this
.
isType
(
schema
,
'
null
'
))
{
this
.
addNullSuggestion
(
collector
);
}
}
if
(
Array
.
isArray
(
schema
.
allOf
))
{
schema
.
allOf
.
forEach
((
s
)
=>
this
.
addEnumSuggestion
(
s
,
collector
));
...
...
@@ -323,6 +332,13 @@ export class JSONCompletion {
}
}
private
isType
(
schema
:
JsonSchema
.
IJSONSchema
,
type
:
string
)
{
if
(
Array
.
isArray
(
schema
.
type
))
{
return
schema
.
type
.
indexOf
(
type
)
!==
-
1
;
}
return
schema
.
type
===
type
;
}
private
addDefaultSuggestion
(
schema
:
JsonSchema
.
IJSONSchema
,
collector
:
ISuggestionsCollector
):
void
{
if
(
schema
.
default
)
{
collector
.
add
({
...
...
@@ -409,7 +425,7 @@ export class JSONCompletion {
return
result
;
}
result
+=
'
:
'
;
if
(
propertySchema
)
{
let
defaultVal
=
propertySchema
.
default
;
if
(
typeof
defaultVal
!==
'
undefined
'
)
{
...
...
@@ -417,7 +433,8 @@ export class JSONCompletion {
}
else
if
(
propertySchema
.
enum
&&
propertySchema
.
enum
.
length
>
0
)
{
result
=
result
+
this
.
getSnippetForValue
(
propertySchema
.
enum
[
0
]);
}
else
{
switch
(
propertySchema
.
type
)
{
var
type
=
Array
.
isArray
(
propertySchema
.
type
)
?
propertySchema
.
type
[
0
]
:
propertySchema
.
type
;
switch
(
type
)
{
case
'
boolean
'
:
result
+=
'
{{false}}
'
;
break
;
...
...
extensions/json/server/src/jsonParser.ts
浏览文件 @
b7e6e6fa
...
...
@@ -104,7 +104,7 @@ export class ASTNode {
if
((
<
string
[]
>
schema
.
type
).
indexOf
(
this
.
type
)
===
-
1
)
{
validationResult
.
warnings
.
push
({
location
:
{
start
:
this
.
start
,
end
:
this
.
end
},
message
:
nls
.
localize
(
'
typeArrayMismatchWarning
'
,
'
Incorrect type. Expected one of {0}
'
,
schema
.
type
.
join
())
message
:
nls
.
localize
(
'
typeArrayMismatchWarning
'
,
'
Incorrect type. Expected one of {0}
'
,
schema
.
type
.
join
(
'
,
'
))
});
}
}
...
...
extensions/json/server/src/test/completion.test.ts
浏览文件 @
b7e6e6fa
...
...
@@ -29,7 +29,7 @@ suite('JSON Completion', () => {
assert
.
equal
(
applyEdits
(
document
,
[
matches
[
0
].
textEdit
]),
resultText
);
}
};
var
testSuggestionsFor
=
function
(
value
:
string
,
stringAfter
:
string
,
schema
:
JsonSchema
.
IJSONSchema
,
test
:
(
items
:
CompletionItem
[],
document
:
ITextDocument
)
=>
void
)
:
Thenable
<
void
>
{
var
uri
=
'
test://test.json
'
;
...
...
@@ -191,6 +191,34 @@ suite('JSON Completion', () => {
]).
then
(()
=>
testDone
(),
(
error
)
=>
testDone
(
error
));
});
test
(
'
Complete value with schema: booleans, null
'
,
function
(
testDone
)
{
var
schema
:
JsonSchema
.
IJSONSchema
=
{
type
:
'
object
'
,
properties
:
{
'
a
'
:
{
type
:
'
boolean
'
},
'
b
'
:
{
type
:
[
'
boolean
'
,
'
null
'
]
},
}
};
Promise
.
all
([
testSuggestionsFor
(
'
{ "a": /**/ }
'
,
'
/**/
'
,
schema
,
result
=>
{
assert
.
strictEqual
(
result
.
length
,
2
);
assertSuggestion
(
result
,
'
true
'
);
assertSuggestion
(
result
,
'
false
'
);
}),
testSuggestionsFor
(
'
{ "b": "/**/ }
'
,
'
/**/
'
,
schema
,
result
=>
{
assert
.
strictEqual
(
result
.
length
,
3
);
assertSuggestion
(
result
,
'
true
'
);
assertSuggestion
(
result
,
'
false
'
);
assertSuggestion
(
result
,
'
null
'
);
})
]).
then
(()
=>
testDone
(),
(
error
)
=>
testDone
(
error
));
});
test
(
'
Complete with nested schema
'
,
function
(
testDone
)
{
var
content
=
'
{/**/}
'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录