Skip to content
This repository was archived by the owner on Jan 10, 2019. It is now read-only.

Commit 5c898dd

Browse files
committed
improved execution of scripts
1 parent 65fda0d commit 5c898dd

File tree

4 files changed

+250
-234
lines changed

4 files changed

+250
-234
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log (vs-script-commands)
22

3+
## 2.0.0 (April 11th, 2017; improved execution of scripts)
4+
5+
* the behavior of executing scripts has been improved ... if you come from version 1.x, have a look at the [wiki](https://github.com/mkloubert/vs-script-commands/wiki#since-version-2x-) first
6+
* if you have problems, you can open an [issue](https://github.com/mkloubert/vs-script-commands/issues) and/or download a version 1.x branch from [here](https://github.com/mkloubert/vs-script-commands/releases)
7+
38
## 1.12.0 (April 10th, 2017; REST API)
49

510
* added `startApi()` and `stopApi()` methods to [ScriptCommandExecutorArguments](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html) interface, which make use of commands provided by extensions like [vs-rest-api](https://github.com/mkloubert/vs-rest-api)

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Adds additional commands to [Visual Studio Code](https://code.visualstudio.com/)
1212

1313
1. [Install](#install-)
1414
2. [How to use](#how-to-use-)
15+
* [Changes](#changes-)
1516
* [Settings](#settings-)
1617
* [Commands](#commands-)
1718
* [Key bindinds](#key-bindinds-)
@@ -33,6 +34,10 @@ Or search for things like `vs-script-commands` in your editor:
3334

3435
## How to use [[↑](#table-of-contents)]
3536

37+
### Changes [[↑](#how-to-use-)]
38+
39+
* if you come from version 1.x, you should take a look at the [wiki](https://github.com/mkloubert/vs-script-commands/wiki#since-version-2x-) first ... if you have problems, you can open an [issue](https://github.com/mkloubert/vs-script-commands/issues) and/or download a version 1.x branch from [here](https://github.com/mkloubert/vs-script-commands/releases)
40+
3641
### Settings [[↑](#how-to-use-)]
3742

3843
Open (or create) your `settings.json` in your `.vscode` subfolder of your workspace.
@@ -55,7 +60,7 @@ Add a `script.commands` section:
5560

5661
#### Commands [[↑](#settings-)]
5762

58-
Define one or more command, by defining its `id` and the script file (relative to your workspace) which should be executed:
63+
Define one or more command, by defining its `id` and the script file, which should be executed:
5964

6065
```json
6166
{
@@ -133,7 +138,7 @@ exports.execute = function (args) {
133138
var scriptFile = path.basename(__filename);
134139

135140
// open HTML document in new tab (for reports e.g.)
136-
args.openHtml('Hello from my extension: ' + scriptFile, 'My HTML document').then(function() {
141+
args.openHtml('<html>Hello from my extension: ' + scriptFile + '</html>', 'My HTML document').then(function() {
137142
// HTML opened
138143
}, function(err) {
139144
// opening HTML document failed
@@ -148,12 +153,27 @@ exports.execute = function (args) {
148153
});
149154

150155
vscode.window.showInformationMessage('Hello from my extension: ' + scriptFile);
156+
157+
// you also can return a Promise
158+
// if your command is executed async
159+
return 666;
151160
}
152161
```
153162

154163
The `args` parameter uses the [ScriptCommandExecutorArguments](https://mkloubert.github.io/vs-script-commands/interfaces/_contracts_.scriptcommandexecutorarguments.html) interface.
155164

156-
You can return a number (sync execution), a [Promise](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) or nothing (default exit code `0`).
165+
You can now execute the command by anything that uses the [Visual Studio Code API](https://code.visualstudio.com/docs/extensionAPI/vscode-api#_commands):
166+
167+
```javascript
168+
var vscode = require('vscode');
169+
170+
vscode.commands.executeCommand('mkloubert.mycommand').then(function(result) {
171+
// if we look at the upper example:
172+
// this should be: 666
173+
}, function(err) {
174+
// handle an error
175+
});
176+
```
157177

158178
A command entry provides the following properties:
159179

@@ -179,7 +199,7 @@ A command entry provides the following properties:
179199
| `onSaved` | Is invoked when a file has been saved. Default `(false)` |
180200
| `onStartup` | Executes the command on startup or not. Default `(false)` |
181201
| `options` | Additional data for the execution. |
182-
| `script` | The path to the script to exeute. |
202+
| `script` | The path to the script to execute. IF YOU USE A RELATIVE PATH: The path is relative to your workspace. |
183203
| `sortOrder` | The sort order (for the GUI). Default `0` |
184204
| `suppressArguments` | Supress own arguments of the extension or not. Default `(false)` |
185205

src/contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export type ScriptCommandExecutor = (args: ScriptCommandExecutorArguments) => Sc
311311
/**
312312
* Possible results of a script executor.
313313
*/
314-
export type ScriptCommandExecutorResult = Promise<number> | void | number;
314+
export type ScriptCommandExecutorResult = any;
315315

316316
/**
317317
* Arguments for a script executor.

0 commit comments

Comments
 (0)