Home > OS >  Custom View in VSCode keeps loading
Custom View in VSCode keeps loading

Time:01-03

Here is the contributes object from package.json

"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)"
      }
    ]

and here is the 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!');
        }));

}

The expected Behaviour is to display welcome content.

But, the view keeps loading forever.

CodePudding user response:

In package.json

The view type is set as webview which needs the HTML content. It is causing the view to load forever.

Instead type should be tree

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