您的位置:首页 > Web前端 > JavaScript

如何在VSCode中定制JSON的IntelliSense

2018-05-18 16:56 375 查看

VSCode支持IntelliSense,可以方便开发者获得提醒,快速编写代码。JSON常常被用作配置文件。那么如何针对特定的开发环境来定制需要的JSON IntelliSense呢?

JSON Schema

VSCode允许用户配置JSON Schema。JSON schema用于描述和验证JSON数据,本身也是JSON。

这里是一个简单的例子

{
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}

我给Dynamsoft Barcode Reader的模板文件写了一个简单的JSON schema。

{
"title": "JSON schema for DBR configuration files",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A representation of Dynamsoft Barcode Reader template.",
"type": "object",
"required": ["Version", "ImageParameters"],
"properties": {
"Version": {
"description": "The template version number.",
"type": "string",
"enum": [
"1.0"
]
},
"ImageParameters": {
"description": "Parameters for barcode detection",
"type": "object",
"required": [
"Name"
],
"properties": {
"Name": {
"description": "The name of the ImageParameters object",
"type": "string",
"maxLength": 50,
"minLength": 1
},
"Description": {
"description": "The description of the ImageParameters object",
"type": "string"
},
"BarcodeFormatIds": {
"description": "Sets which types of barcode to be read. Barcode types can be combined",
"type": "array",
"items": {
"type": "string",
"enum": [
"All", "OneD", "CODE_39", "CODE_128", "CODE_93", "CODABAR", "ITF", "EAN_13", "EAN_8", "UPC_A", "UPC_E", "INDUSTRIAL_25", "PDF417", "QR_CODE", "DATAMATRIX"
]
}
},
"MaxBarcodesCount": {
"description": "Sets the maximum number of barcodes to read",
"type": "number",
"maximum": 2147483647,
"minimum": 1,
"default": 2147483647
},
"Timeout": {
"description": "Sets the maximum amount of time (in milliseconds) it should spend searching for a barcode per page",
"type": "number",
"maximum": 2147483647,
"minimum": 0,
"default": 2147483647
},
"ScaleDownThreshold": {
"description": <
20000
span class="hljs-string">"Sets the threshold value of the image shrinking",
"type": "number",
"maximum": 2147483647,
"minimum": 512,
"default": 2048
},
"DeblurLevel": {
"description": "The blurriness of the barcode",
"type": "number",
"maximum": 9,
"minimum": 0,
"default": 5
}
}
}
}
}

接下来在VSCode中设置一下。

"json.schemas": [
{
"fileMatch": [
"/tpl_*.json"
],
"url": "./dbr.json"
}]

把这个dbr.json(JSON schema)文件放到工程根目录即可。


有了这个,不用担心不知道用什么key和value了。

源码

https://github.com/dynamsoft-dbr/template-json-schema

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: