如何在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了。
源码
阅读更多相关文章推荐
- VScode&Python:如何在控制台进行输入,切换解释器版本
- vscode-settings.json
- vs code如何设置每行的代码长度
- 如何在 VS 2005 里调试 Javascript http://blog.joycode.com/saucer/archive/2006/10/26/85679.aspx
- 在VSCode中如何切换node版本
- 【codevs1425】最小的N个和,如何像煞笔一样地写堆
- 如何用VSCode愉快的写Python
- VScode编辑unity文件的launch.json文件配置
- vscode 如何创建自定义代码片段
- 新版VS-code如何自动换行?
- codevs1068乌龟棋-四维DP,五维如何缩减一维
- 如何在vscode里面调试js和node.js
- 详解如何在vscode里面调试js和node.js的方法步骤
- vscode中启动浏览器的tasks.json
- 【vscode】如何在vscode 中配置:TypeScript开发node环境
- vs-code搭建golang开发环境(如何设置代理)
- 如何在VScode中过滤.pyc文件
- 超炫的HTML5粒子效果进度条 VS 如何规范而优雅地code
- vscode 编写python如何禁止 flake8 提示 line too long
- 如何优雅地使用 VSCode 来编辑 vue 文件?