npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sprotty-vscode

v1.0.0

Published

Glue code to integrate Sprotty diagrams in VSCode extensions (extension part)

Downloads

2,609

Readme

VS Code Integration for Sprotty

This library contains glue code for Sprotty diagrams in VS Code. The diagrams can optionally be backed by a language server.

A complete example with a Langium language server is available here.

Getting Started

As first step, you need to implement a webview that renders your diagrams using sprotty-vscode-webview. The webview package should bundle its code into a single JavaScript file (e.g. with Webpack) and put it into your VS Code extension package. The default implementation assumes that the webview code is available at the path pack/webview.js relative to the extension folder.

Then you can instantiate a WebviewPanelManager in the activate hook of your extension:

export function activate(context: vscode.ExtensionContext) {
    const webviewPanelManager = new WebviewPanelManager({
        extensionUri: context.extensionUri,
        defaultDiagramType: 'mydiagram',
        supportedFileExtensions: ['.mydiagram']
    });
}

This service manages webviews created as webview panels in the main editor area of VS Code. Alternatively, you can use SprottyEditorProvider to get a custom editor provider that can be directly associated with a file type, or SprottyViewProvider to get a webview view provider that can render diagrams in the view areas of VS Code, i.e. the bottom or side panels.

In case you are backing your diagrams with a language server, you should use LspWebviewPanelManager as superclass, or respectively LspSprottyEditorProvider or LspSprottyViewProvider. In this case you need to provide a language client configured to communicate with your language server.

Adding Commands

This library registers a few default commands that you can either execute programmatically or expose in the user interface with package.json entries as shown below. The registration happens by calling this function:

registerDefaultCommands(webviewPanelManager, context, { extensionPrefix: 'example' });

The first segment of each command id corresponds to the extensionPrefix option. The when clauses ending with -focused start with the Sprotty diagram type, which is usually determined by the defaultDiagramType option for WebviewPanelManager or the viewType option for SprottyEditorProvider and SprottyViewProvider.

{
  "contributes": {
    "commands": [
      {
        "command": "example.diagram.open",
        "title": "Open in Diagram",
        "category": "Example Diagram"
      },
      {
        "command": "example.diagram.fit",
        "title": "Fit to Screen",
        "category": "Example Diagram"
      },
      {
        "command": "example.diagram.center",
        "title": "Center selection",
        "category": "Example Diagram"
      },
      {
        "command": "example.diagram.export",
        "title": "Export diagram to SVG",
        "category": "Example Diagram"
      }
    ],
    "menus": {
      "commandPalette": [
        {
          "command": "example.diagram.open",
          "when": "editorLangId == 'example'"
        },
        {
          "command": "example.diagram.fit",
          "when": "example-diagram-focused"
        },
        {
          "command": "example.diagram.center",
          "when": "example-diagram-focused"
        },
        {
          "command": "example.diagram.export",
          "when": "example-diagram-focused"
        }
      ]
    }
  }
}

In addition to these command palette items, you can expose the commands in menus and keybindings.