You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何消除cmake-kits.json文件中的Schema加载警告?

问题描述
  • 开发一款提供cmake-kits的VS Code扩展,在package.json中配置了jsonValidation,指定cmake-kits.json的校验Schema为自定义的cmake-kits_schema.json
  • 运行扩展后打开该Schema文件时出现警告,禁用CMake Tools扩展后警告消失
  • 警告内容:

Problems loading reference 'schemaservice://combinedschema/cmake-tools-schema:/schemas/kits-schema.json': Unable to load schema from 'schemaservice://combinedschema/cmake-tools-schema:/schemas/kits-schema.json': cannot open schemaservice://combinedschema/cmake-tools-schema%3A/schemas/kits-schema.json. Detail: Unable to resolve resource schemaservice://combinedschema/cmake-tools-schema%3A/schemas/kits-schema.json.

解决方案

1. 检查自定义Schema的引用关系

查看你的cmake-kits_schema.json,确认是否存在对CMake Tools内部schema(即schemaservice://combinedschema/cmake-tools-schema:/schemas/kits-schema.json)的直接/间接引用。如果有,要么移除该引用,要么将引用的内容整合到你的自定义Schema中,避免依赖其他扩展的内部资源。

2. 精准配置jsonValidation优先级

在扩展的package.json的contributes字段中,确保jsonValidation的fileMatch精准匹配cmake-kits.json,并使用相对于扩展根目录的路径指定自定义Schema,强制VS Code优先使用你的配置:

"contributes": {
  "jsonValidation": [
    {
      "fileMatch": "**/cmake-kits.json",
      "schema": "./cmake-kits_schema.json"
    }
  ]
}

3. 本地调试时临时屏蔽CMake Tools的Schema关联

如果你只是在本地调试阶段遇到问题,可以在VS Code的用户设置中添加以下配置,让cmake-kits.json仅关联你的自定义Schema:

"json.schemas": [
  {
    "fileMatch": ["**/cmake-kits.json"],
    "url": "./cmake-kits_schema.json"
  }
]

注意:此配置为用户级设置,无需包含在扩展的发布包中,仅用于本地验证问题根源。

4. 动态注册Schema以覆盖冲突

如果VS Code的Schema服务自动合并了多个扩展的Schema导致冲突,可以在扩展激活时动态注册你的自定义Schema,覆盖默认关联:

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
  // 获取自定义Schema的URI
  const schemaUri = vscode.Uri.joinPath(context.extensionUri, 'cmake-kits_schema.json');
  
  // 注册自定义内容提供者
  const schemaProvider = vscode.workspace.registerTextDocumentContentProvider(
    'custom-cmake-kits-schema',
    {
      provideTextDocumentContent: () => {
        return vscode.workspace.fs.readFile(schemaUri).then(buf => buf.toString());
      }
    }
  );

  // 更新JSON Schema配置,关联到自定义提供者
  vscode.workspace.getConfiguration('json').update(
    'schemas',
    [
      {
        fileMatch: ['**/cmake-kits.json'],
        url: 'custom-cmake-kits-schema://schema'
      }
    ],
    vscode.ConfigurationTarget.Global
  );

  context.subscriptions.push(schemaProvider);
}

内容的提问来源于stack exchange,提问作者Nebuchadnezzar Babylonian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 07:11:27