Wis*_*ish 3 jsonschema visual-studio-code vscode-extensions
我已经为 Web 应用程序配置构建了项目。它包括(从 TypeScript)生成的 JSONSchema。为了简化 - 用户可以配置诸如表单之类的内容 - 字段顺序(字符串[])、隐藏字段(字符串[])等。JSON Schmeas 对于不太熟悉配置的用户非常有帮助,并且它会验证一些错误,这可能是由于配置错误引起的。
但它们无法在每种情况下提供帮助 - 在那些字符串数组中 - 用户可以放置任何字符串,并且模式将有效。
我想要做的是一些动态验证,当用户打开[字段顺序时,他必须从字段列表中进行选择,这将从 API 中获取。
有些东西,比如当您输入packageName: "" package.json 依赖项时 - 它会获取给定包的版本。
我想,我必须为此做一些 VSCode 扩展 - 但我不知道 - 从哪里开始。有人可以给我指出方向吗 - 一个有人使用实时 JSON 模式验证的例子将不胜感激。
Found an answer by digging through vscode source code. Searched all files, that contains package.json and dependencies (regex search (package.json[\s\S\n]*dependencies)|(dependencies[\s\S\n]*package.json)) and found a class PackageJSONContribution and this was exactly what I was looking for.
Then I made a simple extension using yo code (as from the example of Your first extension).
Some interfaces and classes I was unable to import from vscode, I just made a local copies for my extension. Made my own class FooJSONContribution with the only difference -
it's getDocumentSelector() function changed to
public getDocumentSelector(): vscode.DocumentSelector {
return [{ language: 'json', scheme: '*', pattern: '**/foo.json' }];
}
Run Code Online (Sandbox Code Playgroud)
Adjusted extensions package.json activationEvents and added "onLanguage:json" (this could be optimised).
Adjusted activate event of the extension by adding
const contribution = new FooJSONContribution(xhr, true);
const disposableCompletionItemProvider = vscode.languages.registerCompletionItemProvider(
contribution.getDocumentSelector(),
new JSONCompletionItemProvider(contribution),
'"',
':'
);
context.subscriptions.push(disposableCompletionItemProvider);
Run Code Online (Sandbox Code Playgroud)
And that's it. All of the foo.json files now work like package.json files -
Things I need to do now - adjust the code of FooJSONContribution.ts to work for my own needs, for my own API's, for my own files.
我在这里上传了这个示例https://github.com/leqwasd/VsCodeAsyncJsonAutocomplete
| 归档时间: |
|
| 查看次数: |
2004 次 |
| 最近记录: |