add progress-ts

This commit is contained in:
Benjamin Pasero
2018-03-27 11:03:01 +02:00
parent 18a79b21cb
commit f1412527b4
10 changed files with 200 additions and 0 deletions

2
progress-sample/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
out
node_modules

28
progress-sample/.vscode/launch.json vendored Normal file
View File

@ -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"
}
]
}

10
progress-sample/.vscode/settings.json vendored Normal file
View File

@ -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
}

30
progress-sample/.vscode/tasks.json vendored Normal file
View File

@ -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"
}

View File

@ -0,0 +1,9 @@
.vscode/**
typings/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
vsc-extension-quickstart.md

21
progress-sample/README.md Normal file
View File

@ -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`

View File

@ -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"
}
}

BIN
progress-sample/preview.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -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;
});
}));
}

View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "out",
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "src"
},
"exclude": [
"node_modules"
]
}