Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate codicons with webviews #136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"start:openvscode-server": "cd test-resources/openvscode-server-v1.77.3-linux-x64/bin/; ./openvscode-server ${0}"
},
"devDependencies": {
"copy-webpack-plugin": "^11.0.0",
"lerna": "^3.20.2"
},
"workspaces": [
Expand Down
1 change: 1 addition & 0 deletions vscode-trace-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"@fortawesome/fontawesome-svg-core": "^1.2.17",
"@fortawesome/free-solid-svg-icons": "^5.8.1",
"@fortawesome/react-fontawesome": "^0.1.4",
"@vscode/codicons": "^0.0.33",
"ag-grid-community": "^28.2.0",
"ag-grid-react": "^28.2.0",
"chart.js": "^2.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewPr
enableScripts: true,

localResourceRoots: [
vscode.Uri.joinPath(this._extensionUri, 'pack')
vscode.Uri.joinPath(this._extensionUri, 'pack'),
vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons')
]
};

Expand Down Expand Up @@ -109,6 +110,7 @@ export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewPr
private _getHtmlForWebview(webview: vscode.Webview) {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'pack', 'analysisPanel.js'));
const codiconsUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons', 'codicon.css'));

// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();
Expand All @@ -120,7 +122,14 @@ export class TraceExplorerAvailableViewsProvider implements vscode.WebviewViewPr
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'unsafe-eval';style-src vscode-resource: 'unsafe-inline' http: https: data:;connect-src ${getTraceServerUrl()};">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none';
img-src vscode-resource: https:;
script-src 'nonce-${nonce}' 'unsafe-eval';
style-src ${webview.cspSource} vscode-resource: 'unsafe-inline' http: https: data:;
connect-src ${getTraceServerUrl()};
font-src ${webview.cspSource}">
<link href="${codiconsUri}" rel="stylesheet" />
<base href="${vscode.Uri.joinPath(this._extensionUri, 'pack').with({ scheme: 'vscode-resource' })}/">
</head>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewView
enableScripts: true,

localResourceRoots: [
vscode.Uri.joinPath(this._extensionUri, 'pack')
vscode.Uri.joinPath(this._extensionUri, 'pack'),
vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons')
]
};

Expand Down Expand Up @@ -137,6 +138,7 @@ export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewView
private _getHtmlForWebview(webview: vscode.Webview) {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'pack', 'openedTracesPanel.js'));
const codiconsUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons', 'codicon.css'));

// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();
Expand All @@ -148,7 +150,14 @@ export class TraceExplorerOpenedTracesViewProvider implements vscode.WebviewView
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'unsafe-eval';style-src vscode-resource: 'unsafe-inline' http: https: data:;connect-src ${getTraceServerUrl()};">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none';
img-src vscode-resource: https:;
script-src 'nonce-${nonce}' 'unsafe-eval';
style-src ${webview.cspSource} vscode-resource: 'unsafe-inline' http: https: data:;
connect-src ${getTraceServerUrl()};
font-src ${webview.cspSource}">
<link href="${codiconsUri}" rel="stylesheet" />
<base href="${vscode.Uri.joinPath(this._extensionUri, 'pack').with({ scheme: 'vscode-resource' })}/">
</head>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class TraceExplorerItemPropertiesProvider implements vscode.WebviewViewPr
webviewView.webview.options = {
// Allow scripts in the webview
enableScripts: true,
localResourceRoots: [vscode.Uri.joinPath(this._extensionUri, 'pack')],
localResourceRoots: [
vscode.Uri.joinPath(this._extensionUri, 'pack'),
vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons')
]
};
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
}
Expand All @@ -35,6 +38,7 @@ export class TraceExplorerItemPropertiesProvider implements vscode.WebviewViewPr
private _getHtmlForWebview(webview: vscode.Webview) {
// Get the local path to main script run in the webview, then convert it to a uri we can use in the webview.
const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'pack', 'propertiesPanel.js'));
const codiconsUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons', 'codicon.css'));

// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();
Expand All @@ -46,8 +50,15 @@ export class TraceExplorerItemPropertiesProvider implements vscode.WebviewViewPr
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'unsafe-eval';style-src vscode-resource: 'unsafe-inline' http: https: data:;connect-src ${getTraceServerUrl()};">
<base href="${vscode.Uri.joinPath(this._extensionUri, 'pack').with({ scheme: 'vscode-resource' })}/">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none';
img-src vscode-resource: https:;
script-src 'nonce-${nonce}' 'unsafe-eval';
style-src ${webview.cspSource} vscode-resource: 'unsafe-inline' http: https: data:;
connect-src ${getTraceServerUrl()};
font-src ${webview.cspSource}">
<link href="${codiconsUri}" rel="stylesheet" />
<base href="${vscode.Uri.joinPath(this._extensionUri, 'pack').with({ scheme: 'vscode-resource' })}/">
</head>

<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export class TraceViewerPanel {

// And restrict the webview to only loading content from our extension's `media` directory.
localResourceRoots: [
vscode.Uri.joinPath(this._extensionUri, 'pack')
vscode.Uri.joinPath(this._extensionUri, 'pack'),
vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons'),
]
});

Expand Down Expand Up @@ -241,6 +242,10 @@ export class TraceViewerPanel {
}

private _getHtmlForWebview() {
const webview = this._panel.webview;
const codiconsUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons', 'codicon.css'));
const nonce = getNonce();

try {
return this._getReactHtmlForWebview();
} catch (e) {
Expand All @@ -251,6 +256,14 @@ export class TraceViewerPanel {
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<meta http-equiv="Content-Security-Policy"
content="default-src 'none';
img-src vscode-resource: https:;
script-src 'nonce-${nonce}' 'unsafe-eval';
style-src ${webview.cspSource} vscode-resource: 'unsafe-inline' http: https: data:;
connect-src ${getTraceServerUrl()};
font-src ${webview.cspSource}">
<link href="${codiconsUri}" rel="stylesheet" />
<base href="${vscode.Uri.joinPath(this._extensionUri, 'pack').with({ scheme: 'vscode-resource' })}/">
</head>

Expand All @@ -270,6 +283,10 @@ export class TraceViewerPanel {
// const stylePathOnDisk = vscode.Uri.file(path.join(this._extensionPath, 'build', mainStyle));
// const styleUri = stylePathOnDisk.with({ scheme: 'vscode-resource' });

// Fetching codicons styles
const webview = this._panel.webview;
const codiconsUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, 'lib', 'codicons', 'codicon.css'));

// Use a nonce to whitelist which scripts can be run
const nonce = getNonce();

Expand All @@ -280,7 +297,14 @@ export class TraceViewerPanel {
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>React App</title>
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}' 'unsafe-eval';style-src vscode-resource: 'unsafe-inline' http: https: data:;connect-src ${getTraceServerUrl()};">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none';
img-src vscode-resource: https:;
script-src 'nonce-${nonce}' 'unsafe-eval';
style-src ${webview.cspSource} vscode-resource: 'unsafe-inline' http: https: data:;
connect-src ${getTraceServerUrl()};
font-src ${webview.cspSource}">
<link href="${codiconsUri}" rel="stylesheet" />
<base href="${vscode.Uri.joinPath(this._extensionUri, 'pack').with({ scheme: 'vscode-resource' })}/">
</head>

Expand Down
15 changes: 15 additions & 0 deletions vscode-trace-extension/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
'use strict';

const path = require('path');
const CopyPlugin = require("copy-webpack-plugin");

/**
* Path to Codicons css and ttf files.
*/
const codiconsCssPath = path.resolve(__dirname, '..', 'node_modules', '@vscode', 'codicons', 'dist', 'codicon.css');
const codiconsFontPath = path.resolve(__dirname, '..', 'node_modules', '@vscode', 'codicons', 'dist', 'codicon.ttf');

/**@type {import('webpack').Configuration}*/
const config = {
Expand Down Expand Up @@ -65,6 +72,14 @@ const config = {
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{ from: codiconsCssPath, to: "./codicons" }, // Copy codicons css and font files to lib/codicons so that they are packaged with the extension
{ from: codiconsFontPath, to: "./codicons" }
],
}),
]
}

module.exports = config;
Loading