Skip to content

Instantly share code, notes, and snippets.

View ljmotta's full-sized avatar

Luiz João Motta ljmotta

  • Senior Software Engineer - IBM
  • São Paulo, SP - Brazil
View GitHub Profile
@ljmotta
ljmotta / package.json
Created October 14, 2020 18:08
Package Activation Events
"activationEvents": [
"*"
],
@ljmotta
ljmotta / package.json
Created October 14, 2020 18:08
Package Contributes
"contributes": {
"menus": {
"editor/context": [
{
"command": "kogito-tooling-examples.todo-list-view.add-item"
}
]
},
"commands": [
{
@ljmotta
ljmotta / package.json
Created October 14, 2020 18:07
Package Main
"main": "./dist/extension.js",
@ljmotta
ljmotta / package.json
Created October 14, 2020 18:06
Package Engines
"engines": {
"vscode": "^1.46.0"
},
@ljmotta
ljmotta / package.json
Created October 14, 2020 18:06
Package Json Name
"publisher": "kogito-tooling-examples",
"name": "todo-list-view-vscode-extension",
@ljmotta
ljmotta / TodoListWebview.ts
Last active October 14, 2020 18:05
TodoListWebview subscriptions
public open(pageId: string, opts: { onClose: () => void }) {
// ...
this.context.subscriptions.push(
webviewPanel.webview.onDidReceiveMessage(
(msg) => envelopeServer.receive(msg, this.api),
webviewPanel.webview,
this.context.subscriptions
)
);
@ljmotta
ljmotta / TodoListWebview.tsx
Last active October 14, 2020 18:04
TodoListWebview HTML
public open(pageId: string, opts: { onClose: () => void }) {
// ...
const scriptSrc = webviewPanel.webview
.asWebviewUri(Uri.file(this.context.asAbsolutePath(this.envelopeLocator.envelopePath)))
.toString();
webviewPanel.webview.html = `<!DOCTYPE html>
<html lang="en">
<head>
@ljmotta
ljmotta / TodoListWebview.ts
Created October 14, 2020 17:59
TodoListWebview Envelope Server
public open(pageId: string, opts: { onClose: () => void }) {
// ...
const envelopeServer: EnvelopeServer<TodoListChannelApi, TodoListEnvelopeApi> = new EnvelopeServer(
{ postMessage: (message) => webviewPanel.webview.postMessage(message) },
this.envelopeLocator.targetOrigin,
() =>
envelopeServer.manager.clientApi.requests.todoList__init(
{ origin: envelopeServer.origin, envelopeServerId: envelopeServer.id },
{ user: "Tiago" }
@ljmotta
ljmotta / TodoListWebview.ts
Created October 14, 2020 17:57
TodoListWebview Webview Panel
public open(pageId: string, opts: { onClose: () => void }) {
const webviewPanel = vscode.window.createWebviewPanel(pageId, this.envelopeLocator.title, ViewColumn.Beside, {
retainContextWhenHidden: true,
enableCommandUris: true,
enableScripts: true,
localResourceRoots: [vscode.Uri.file(this.context.extensionPath)],
});
// ...
}
@ljmotta
ljmotta / TodoListWebview.ts
Created October 14, 2020 17:55
TodoListWebview Constructor
import * as vscode from "vscode";
import { TodoListChannelApi } from "../api";
export class TodoListWebview {
constructor(
private readonly context: vscode.ExtensionContext,
private readonly envelopeLocator: {
targetOrigin: string;
title: string;
envelopePath: string;