Skip to content

Commit 0ae016d

Browse files
rohanjrhurryabit
authored andcommitted
Display release notes using webview (#3321)
* Display release notes using webview * Use const and fix string * Check for version upgrade before showing release notes * Changelog entry * Use node-fetch instead of web-request * Remove spurious state update
1 parent 64f1b3a commit 0ae016d

File tree

4 files changed

+78
-17
lines changed

4 files changed

+78
-17
lines changed

compiler/daml-extension/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,20 @@
135135
"build": "node ./node_modules/typescript/bin/tsc -p ./"
136136
},
137137
"dependencies": {
138-
"vscode-languageclient": "6.0.0-next.1",
139-
"which": "1.3.1",
140-
"tmp": "0.0.29",
138+
"@types/node-fetch": "^2.5.3",
141139
"@types/tmp": "0.0.29",
142-
"@types/which": "1.3.1"
140+
"@types/which": "1.3.1",
141+
"fp-ts": "^2.1.1",
142+
"node-fetch": "^2.6.0",
143+
"tmp": "0.0.29",
144+
"vscode-languageclient": "6.0.0-next.1",
145+
"which": "1.3.1"
143146
},
144147
"devDependencies": {
145148
"@bazel/hide-bazel-files": "0.32.2",
146-
"typescript": "3.6.3",
147149
"@types/node": "12.7.11",
148150
"@types/vscode": "1.33",
151+
"typescript": "3.6.3",
149152
"vsce": "1.66.0"
150153
}
151154
}

compiler/daml-extension/src/extension.ts

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import * as os from 'os';
1111
import * as cp from 'child_process';
1212
import * as tmp from 'tmp';
1313
import { LanguageClient, LanguageClientOptions, RequestType, NotificationType, TextDocumentIdentifier, TextDocument, ExecuteCommandRequest } from 'vscode-languageclient';
14-
import { Uri, Event, TextDocumentContentProvider, ViewColumn, EventEmitter, window, QuickPickOptions, ExtensionContext, env, WorkspaceConfiguration } from 'vscode'
14+
import { Uri, Event, TextDocumentContentProvider, ViewColumn, EventEmitter, window, QuickPickOptions, ExtensionContext, env, WorkspaceConfiguration } from 'vscode';
1515
import * as which from 'which';
1616
import * as util from 'util';
17-
17+
import fetch, { Response } from 'node-fetch';
18+
import { getOrd } from 'fp-ts/lib/Array';
19+
import { ordNumber } from 'fp-ts/lib/Ord';
1820

1921
let damlRoot: string = path.join(os.homedir(), '.daml');
2022

21-
let versionContextKey = 'version'
23+
const versionContextKey = 'version'
2224

2325
var damlLanguageClient: LanguageClient;
2426
// Extension activation
@@ -31,8 +33,8 @@ export async function activate(context: vscode.ExtensionContext) {
3133
// Get telemetry consent
3234
const consent = getTelemetryConsent(config, context);
3335

34-
// Check extension version to publish release notes on updates
35-
checkVersion(context);
36+
// Check extension version to display release notes on updates
37+
showReleaseNotesIfNewVersion(context);
3638

3739
damlLanguageClient = createLanguageClient(config, await consent);
3840
damlLanguageClient.registerProposedFeatures();
@@ -97,17 +99,55 @@ export async function activate(context: vscode.ExtensionContext) {
9799
}
98100

99101
// Compare the extension version with the one stored in the global state.
100-
// This will be used to show release notes when the version has changed.
101-
async function checkVersion(context: ExtensionContext) {
102-
let packageFile = path.join(context.extensionPath, 'package.json');
103-
let packageData = await util.promisify(fs.readFile)(packageFile, "utf8");
104-
let extensionVersion = JSON.parse(packageData).version;
105-
let recordedVersion = context.globalState.get(versionContextKey);
106-
if (!recordedVersion || recordedVersion != extensionVersion ) {
102+
// If they are different, we assume the user has updated the extension and
103+
// we display the release notes for the new SDK release in a new tab.
104+
// This should only occur the first time the user uses the extension after
105+
// an update.
106+
async function showReleaseNotesIfNewVersion(context: ExtensionContext) {
107+
const packageFile = path.join(context.extensionPath, 'package.json');
108+
const packageData = await util.promisify(fs.readFile)(packageFile, "utf8");
109+
const extensionVersion = JSON.parse(packageData).version;
110+
const recordedVersion = String(context.globalState.get(versionContextKey));
111+
if (!recordedVersion || checkVersionUpgrade(recordedVersion, extensionVersion)) {
112+
// We have a new version of the extension so show the release notes
113+
// and update the current version so we don't show them again until
114+
// the next update.
115+
showReleaseNotes(extensionVersion);
107116
await context.globalState.update(versionContextKey, extensionVersion);
108117
}
109118
}
110119

120+
// Check that `version2` is an upgrade from `version1`,
121+
// i.e. that the components of the version number have increased
122+
// (checked from major to minor version numbers).
123+
function checkVersionUpgrade(version1: string, version2: string) {
124+
const comps1 = version1.split(".").map(Number);
125+
const comps2 = version2.split(".").map(Number);
126+
const o = getOrd(ordNumber);
127+
return o.compare(comps2, comps1) > 0;
128+
}
129+
130+
// Show the release notes from the DAML Blog.
131+
// We display the HTML in a new editor tab using a "webview":
132+
// https://code.visualstudio.com/api/extension-guides/webview
133+
async function showReleaseNotes(version: string) {
134+
const releaseNotesUrl = 'https://blog.daml.com/release-notes/';
135+
if (version) {
136+
const url = releaseNotesUrl + version;
137+
fetch(url).then(async (result: Response) => {
138+
if (result.ok) {
139+
const panel = vscode.window.createWebviewPanel(
140+
'releaseNotes', // Identifies the type of the webview. Used internally
141+
`Release Notes for DAML SDK ${version}`, // Title of the panel displayed to the user
142+
vscode.ViewColumn.One, // Editor column to show the new webview panel in
143+
{} // No webview options for now
144+
);
145+
panel.webview.html = await result.text();
146+
}
147+
});
148+
}
149+
}
150+
111151
function getViewColumnForShowResource(): ViewColumn {
112152
const active = vscode.window.activeTextEditor;
113153
if (!active || !active.viewColumn) { return ViewColumn.One; }

compiler/daml-extension/yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
resolved "https://registry.yarnpkg.com/@bazel/hide-bazel-files/-/hide-bazel-files-0.32.2.tgz#a482855eafbccb56b1fce0d92ff922c2c6e0a90c"
88
integrity sha512-585XY53mhMZaCjEQJ+aDqkmydWZbuXsKrZsSpoW9YeAVEH0poQY3YhdyCPmMVBo7/l1mkrqpFuOK5BpECfwdtA==
99

10+
"@types/node-fetch@^2.5.3":
11+
version "2.5.3"
12+
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.3.tgz#b84127facd93642b1fb6439bc630ba0612e3ec50"
13+
integrity sha512-X3TNlzZ7SuSwZsMkb5fV7GrPbVKvHc2iwHmslb8bIxRKWg2iqkfm3F/Wd79RhDpOXR7wCtKAwc5Y2JE6n/ibyw==
14+
dependencies:
15+
"@types/node" "*"
16+
1017
"@types/node@*":
1118
version "12.6.2"
1219
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.2.tgz#a5ccec6abb6060d5f20d256fb03ed743e9774999"
@@ -200,6 +207,11 @@ fd-slicer@~1.1.0:
200207
dependencies:
201208
pend "~1.2.0"
202209

210+
fp-ts@^2.1.1:
211+
version "2.1.1"
212+
resolved "https://registry.yarnpkg.com/fp-ts/-/fp-ts-2.1.1.tgz#c910544499d7c959351bb4260ee7c44a544084c1"
213+
integrity sha512-YcWhMdDCFCja0MmaDroTgNu+NWWrrnUEn92nvDgrtVy9Z71YFnhNVIghoHPt8gs82ijoMzFGeWKvArbyICiJgw==
214+
203215
fs.realpath@^1.0.0:
204216
version "1.0.0"
205217
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -297,6 +309,11 @@ mute-stream@~0.0.4:
297309
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
298310
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==
299311

312+
node-fetch@^2.6.0:
313+
version "2.6.0"
314+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
315+
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
316+
300317
nth-check@~1.0.1:
301318
version "1.0.2"
302319
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.2.tgz#b2bd295c37e3dd58a3bf0700376663ba4d9cf05c"

unreleased.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ HEAD — ongoing
3232
match the behavior of corresponding functions without the underscore suffix but ignore the result which can be more convenient and
3333
efficient.
3434
- [DAML Compiler] The compiler now accepts single-constructor enum types. For example ``data A = A`` or ``data Foo = Bar``.
35+
- [DAML SDK] Display release notes in the IDE when the DAML extension is upgraded.

0 commit comments

Comments
 (0)