diff --git a/progress-sample/.gitignore b/progress-sample/.gitignore new file mode 100644 index 00000000..8e5962ee --- /dev/null +++ b/progress-sample/.gitignore @@ -0,0 +1,2 @@ +out +node_modules \ No newline at end of file diff --git a/progress-sample/.vscode/launch.json b/progress-sample/.vscode/launch.json new file mode 100644 index 00000000..c776d21e --- /dev/null +++ b/progress-sample/.vscode/launch.json @@ -0,0 +1,28 @@ +// A launch configuration that compiles the extension and then opens it inside a new window +{ + "version": "0.1.0", + "configurations": [ + { + "name": "Launch Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": ["--extensionDevelopmentPath=${workspaceRoot}" ], + "stopOnEntry": false, + "sourceMaps": true, + "outFiles": ["${workspaceRoot}/out/src/**/*.js"], + "preLaunchTask": "npm" + }, + { + "name": "Launch Tests", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ], + "stopOnEntry": false, + "sourceMaps": true, + "outFiles": ["${workspaceRoot}/out/test/**/*.js"], + "preLaunchTask": "npm" + } + ] +} diff --git a/progress-sample/.vscode/settings.json b/progress-sample/.vscode/settings.json new file mode 100644 index 00000000..3f5aa9cf --- /dev/null +++ b/progress-sample/.vscode/settings.json @@ -0,0 +1,10 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.exclude": { + "out": false // set this to true to hide the "out" folder with the compiled JS files + }, + "search.exclude": { + "out": true // set this to false to include "out" folder in search results + }, + "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version +} \ No newline at end of file diff --git a/progress-sample/.vscode/tasks.json b/progress-sample/.vscode/tasks.json new file mode 100644 index 00000000..1992757d --- /dev/null +++ b/progress-sample/.vscode/tasks.json @@ -0,0 +1,30 @@ +// Available variables which can be used inside of strings. +// ${workspaceRoot}: the root folder of the team +// ${file}: the current opened file +// ${fileBasename}: the current opened file's basename +// ${fileDirname}: the current opened file's dirname +// ${fileExtname}: the current opened file's extension +// ${cwd}: the current working directory of the spawned process + +// A task runner that calls a custom npm script that compiles the extension. +{ + "version": "0.1.0", + + // we want to run npm + "command": "npm", + + // the command is a shell script + "isShellCommand": true, + + // show the output window only if unrecognized errors occur. + "showOutput": "silent", + + // we run the custom script "compile" as defined in package.json + "args": ["run", "compile", "--loglevel", "silent"], + + // The tsc compiler is started in watching mode + "isWatching": true, + + // use the standard tsc in watch mode problem matcher to find compile problems in the output. + "problemMatcher": "$tsc-watch" +} \ No newline at end of file diff --git a/progress-sample/.vscodeignore b/progress-sample/.vscodeignore new file mode 100644 index 00000000..795e7143 --- /dev/null +++ b/progress-sample/.vscodeignore @@ -0,0 +1,9 @@ +.vscode/** +typings/** +out/test/** +test/** +src/** +**/*.map +.gitignore +tsconfig.json +vsc-extension-quickstart.md diff --git a/progress-sample/README.md b/progress-sample/README.md new file mode 100644 index 00000000..dd78d223 --- /dev/null +++ b/progress-sample/README.md @@ -0,0 +1,21 @@ +# Progress Sample + +This is a sample extension that shows a running progress in the notification area with support for cancellation. + +It is not intended as a product quality extension. + +- Open the command palette +- Run "Show Progress" +- Observe the running task in the notification area + +![Show progress in notification area](https://raw.githubusercontent.com/Microsoft/vscode-extension-samples/master/progress-sample/preview.gif) + +# How it works, what it shows? + +- The extension uses the [`withProgress`](https://code.visualstudio.com/docs/extensionAPI/vscode-api#ProgressOptions) API to show the task in the notification area. +- Registers a command via `package.json` that will trigger the task + +# How to run locally + +* `npm run compile` to start the compiler in watch mode +* open this folder in VS Code and press `F5` \ No newline at end of file diff --git a/progress-sample/package.json b/progress-sample/package.json new file mode 100644 index 00000000..94992573 --- /dev/null +++ b/progress-sample/package.json @@ -0,0 +1,44 @@ +{ + "name": "progress-ts", + "displayName": "Notification Progress", + "description": "Show a long running operation in the notification area", + "version": "0.0.1", + "publisher": "bpasero", + "repository": { + "type": "git", + "url": "https://github.com/Microsoft/vscode-extension-samples" + }, + "bugs": { + "url": "https://github.com/Microsoft/vscode-extension-samples/issues" + }, + "engines": { + "vscode": "^1.22.0" + }, + "categories": [ + "Other" + ], + "activationEvents": [ + "*" + ], + "contributes": { + "commands": [ + { + "command": "extension.startTask", + "title": "Show Progress" + } + ] + }, + "main": "./out/extension", + "scripts": { + "vscode:prepublish": "tsc -p ./", + "compile": "tsc -watch -p ./", + "postinstall": "node ./node_modules/vscode/bin/install", + "test": "node ./node_modules/vscode/bin/test" + }, + "devDependencies": { + "typescript": "^2.1.4", + "vscode": "^1.0.0", + "mocha": "^2.3.3", + "@types/node": "^6.0.40" + } +} diff --git a/progress-sample/preview.gif b/progress-sample/preview.gif new file mode 100644 index 00000000..9cb1e1c9 Binary files /dev/null and b/progress-sample/preview.gif differ diff --git a/progress-sample/src/extension.ts b/progress-sample/src/extension.ts new file mode 100644 index 00000000..69dd6df3 --- /dev/null +++ b/progress-sample/src/extension.ts @@ -0,0 +1,41 @@ +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ + +'use strict'; + +import { ExtensionContext, StatusBarAlignment, window, StatusBarItem, Selection, workspace, TextEditor, commands, ProgressLocation } from 'vscode'; + +export function activate(context: ExtensionContext) { + context.subscriptions.push(commands.registerCommand('extension.startTask', () => { + window.withProgress({ + location: ProgressLocation.Notification, + title: "I am long running!", + cancellable: true + }, (progress, token) => { + token.onCancellationRequested(() => { + console.log("User canceled the long running operation") + }); + + setTimeout(() => { + progress.report({ percentage: 10, message: "I am long running! - still going..." }); + }, 1000); + + setTimeout(() => { + progress.report({ percentage: 50, message: "I am long running! - still going even more..." }); + }, 2000); + + setTimeout(() => { + progress.report({ percentage: 90, message: "I am long running! - almost there..." }); + }, 3000); + + var p = new Promise(resolve => { + setTimeout(() => { + resolve(); + }, 5000); + }); + + return p; + }); + })); +} \ No newline at end of file diff --git a/progress-sample/tsconfig.json b/progress-sample/tsconfig.json new file mode 100644 index 00000000..c79b0fa0 --- /dev/null +++ b/progress-sample/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "outDir": "out", + "lib": [ + "es6" + ], + "sourceMap": true, + "rootDir": "src" + }, + "exclude": [ + "node_modules" + ] +}