【问题标题】:调试带有注释的 json
【发布时间】:2022-01-23 05:07:47
【问题描述】:

我正在创建一个 VScode 主题,我有一个像这样的长 json 文件:

{
    "name": "mytheme",
    "type": "dark",
    "colors": {
        //////////////////////////////
        // CONTRAST COLOR 
    // The contrast colors are typically only set for high contrast themes. 
    // If set, they add an additional border around items across the UI to increase the contrast.
    //////////////////////////////
        // An extra border around active elements to separate them from others for greater contrast.
        // "contrastActiveBorder": "#FFFFFF00",
        // An extra border around elements to separate them from others for greater contrast.
        // "contrastBorder": "#FFFFFF00",

    //////////////////////////////
    // BASE COLORS 
    //////////////////////////////
    // Overall border color for focused elements. This color is only used if not overridden by a component.
    "focusBorder": "#aa6DFF66",
    // Overall foreground color. This color is only used if not overridden by a component.
    "foreground": "#aaE0E8",
    // Shadow color of widgets such as Find/Replace inside the editor.
    "widget.shadow": "#112330",
    // Background color of text selections in the workbench (for input fields or text areas, does not apply to selections within the editor and the terminal).
    "selection.background": "#9B6DFF99",
    // Foreground color for description text providing additional information, for example for a label.
    "descriptionForeground": "#808182",
    // Overall foreground color for error messages (this color is only used if not overridden by a component).
    "errorForeground": "#9B6DFF",
    // The default color for icons in the workbench.
    "icon.foreground": "#D9E0E8",
    ...

我想尝试一下,所以我关注了这个official article。它说按 f5 打开 Extension Development Host 窗口。 如果我按 f5,我会得到这个弹出窗口

You don't have an extension for debugging 'JSON with Comments'. Should we find a 'JSON with Comments' extension in the Marketplace?

如果我按查找或取消,我无法打开扩展开发主机窗口。

当我打开 package.json 文件(没有 cmets)时,我尝试按下 f5,但它是一样的。 如何使用 cmets 调试 json 文件。

删除 cmets 不是一个选项,它是一个非常长的文件,cmets 使其易于阅读和理解。

【问题讨论】:

  • JSON 默认不支持 cmets,我怀疑 VSCode 是否能够读取带有 cmets 的 json 文件。请参阅stackoverflow.com/questions/244777/can-comments-be-used-in-json 了解更多信息。
  • 你必须为扩展定义一个启动配置,并在调试栏中选择这个配置然后按F5
  • @rioV8 你是什么意思?我在哪里可以找到按照你说的做的指南?
  • 一个主题只是一个常规的扩展,阅读Hello World扩展的开发
  • JSON 只是静态数据。您希望对其进行哪些调试?

标签: json visual-studio-code vscode-extensions vscode-debugger


【解决方案1】:

解决了在.vscode 文件夹中创建此launch.json 文件:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "extensionHost",
      "request": "launch",
      "name": "Launch Extension",
      "runtimeExecutable": "${execPath}",
      "args": [
        "--extensionDevelopmentPath=${workspaceFolder}"
      ],
      "outFiles": [
        "${workspaceFolder}/out/**/*.js"
      ],
    },
  ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 1970-01-01
    • 2022-06-28
    • 2019-09-16
    相关资源
    最近更新 更多