mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
add progress-ts
This commit is contained in:
2
progress-sample/.gitignore
vendored
Normal file
2
progress-sample/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
out
|
||||
node_modules
|
||||
28
progress-sample/.vscode/launch.json
vendored
Normal file
28
progress-sample/.vscode/launch.json
vendored
Normal 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
10
progress-sample/.vscode/settings.json
vendored
Normal 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
30
progress-sample/.vscode/tasks.json
vendored
Normal 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"
|
||||
}
|
||||
9
progress-sample/.vscodeignore
Normal file
9
progress-sample/.vscodeignore
Normal 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
21
progress-sample/README.md
Normal 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
|
||||
|
||||

|
||||
|
||||
# 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`
|
||||
44
progress-sample/package.json
Normal file
44
progress-sample/package.json
Normal 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
BIN
progress-sample/preview.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
41
progress-sample/src/extension.ts
Normal file
41
progress-sample/src/extension.ts
Normal 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;
|
||||
});
|
||||
}));
|
||||
}
|
||||
15
progress-sample/tsconfig.json
Normal file
15
progress-sample/tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user