typescript VSCode中的自定义视图持续加载

5n0oy7gb  于 2023-01-03  发布在  TypeScript
关注(0)|答案(1)|浏览(157)

下面是package.json中的contributes对象

"contributes": {
    "viewsWelcome": [
      {
        "view": "notesView",
        "contents": "No node dependencies found [learn more](https://www.npmjs.com/).\n[Add Dependency](command:notesView.addNote)",
        "when": "notesView.notesLen == 0"
      }
    ],
    "viewsContainers": {
      "activitybar": [
        {
          "id": "side-notes",
          "title": "Side Notes",
          "icon": "media/notesIcon.svg"
        }
      ]
    },
    "views": {
      "side-notes": [
        {
          "id": "notesView",
          "name": "Notes",
          "type": "webview"
        }
      ]
    },
    "menus": {
    "view/title": [
        {
            "command": "notesView.addNote",
            "group": "navigation",
            "when": "view == notesView && notesView.notesLen == 0"
        }
    ]
    },
    "commands": [
      {
        "command": "notesView.addNote",
        "title": "Add Side Note",
        "icon": "$(add)"
      }
    ]

这是extension.js

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    vscode.commands.executeCommand('setContext', 'notesView.notesLen', 0);

    context.subscriptions.push(
        vscode.commands.registerCommand('notesView.addNote', async () => {
            vscode.window.showInformationMessage('Hello World!');
        }));

}

预期行为是显示欢迎内容。
但是,视图会一直加载下去。

k5ifujac

k5ifujac1#

输入package.json
视图类型设置为webview,需要HTML内容。这将导致视图永远加载。
类型应为tree

"views": {
      "side-notes": [
        {
          "id": "notesView",
          "name": "Notes",
          "type": "tree"
        }
      ]
    },

相关问题