【问题标题】:VSCode jsonValidation using local schema filesVSCode jsonValidation 使用本地模式文件
【发布时间】:2017-03-14 01:24:46
【问题描述】:

contributes.jsonValidation 的文档说:

url 值可以是扩展中包含的架构文件的本地路径,也可以是远程服务器 URL,例如 json 架构存储。

URL 值按描述工作:

"jsonValidation": [{
    "fileMatch": ".jshintrc",
    "url": "http://json.schemastore.org/jshintrc"
}]

但是,如果我创建一个测试扩展并提供一个指向我的扩展本地文件的路径,它不会:

"jsonValidation": [{
    "fileMatch": "*.testing",
    "url": "/schemas/testing.schema.json"
}]

我的扩展程序根目录有一个文件夹schemas,其中有一个文件testing.schema.json。它只是 jshintrc 架构的副本。

当我启动我的测试扩展并加载一个与模式匹配的文件时,我在第一个左大括号下得到一个绿色的小波浪线。如果我将鼠标悬停在绿色曲线上,我会看到一个熟悉的错误:

无法从 '/schemas/edfoo.schema.json' 加载架构:ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" rel="nofollow" target="_blank">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

IIS 10.0 详细错误 - 404.0 - 未找到

显然,它正在访问服务器,而不是从扩展程序中读取本地文件。但是文档说我可以在扩展中包含一个模式文件。如何让它发挥作用?

【问题讨论】:

    标签: visual-studio-code vscode-extensions


    【解决方案1】:

    想通了:url 缺少一个前导点,如下所示:

    "jsonValidation": [{
        "fileMatch": "*.testing",
        "url": "./schemas/testing.schema.json"
    }]
    

    url 以此./ 模式开头时,它会被自动理解为带有扩展名的文件。如果前面缺少./ 或什至只是.,则会将其视为从服务器获取的URL。

    由于 vscode 是开源的,我可以参考实现这种行为的代码行。

    在这里:jsonMain.ts#L105

    【讨论】:

    • 这似乎在开发/调试时工作,但是一旦我创建并安装了 vsix 扩展,它似乎不再工作 - 我错过了什么吗?
    • 检查以确保模式文件与 visx 一起安装。他们应该在某个地方结束,比如~/.vscode/extensions/{extensionName}/...
    • 原来在卸载/安装过程中有一些时髦的 vsix 缓存,所以我的“工作”代码从未安装 - 现在一切都很好!感谢您的跟进。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    相关资源
    最近更新 更多