Skip to content

Commit

Permalink
Release 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Darien Pardinas Diaz committed May 13, 2024
1 parent 0355d5e commit a1e7933
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Change Log

## [0.0.3]
- Added some more documentation
- Refactored some code

## [0.0.2]

- Removed option to configure the listening interface for security reasons. Now the extension can only listen on the localhost interface.
- Removed option to configure the listening interface for security reasons. Now the extension can only listen on `localhost` interface.
- Added `custom.showQuickPick` command to run quick pick dialogs in vscode via automation.
- Command `custom.goToFileLineCharacter` can now take a relative path to the workspace.
- Added `custom.showInformationMessage`, `custom.showWarningMessage` and `custom.showErrorMessage` to show messages to the users in vscode.
Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</a>
</p>

This extension allows you to remotely control instances of Visual Studio Code by exposing a REST endpoint that you can use to invoke vscode commands. In the background it launches a HTTP server that listen to requests of commands to execute.
This extension allows you to remotely control instances of Visual Studio Code by exposing a REST endpoint that you can use to invoke vscode commands. In the background it launches a HTTP server that listen on the `localhost` interface for requests of commands to execute.

The demo below shows how we can open a terminal, run some commands in it, then close all terminals, open a file with the cursor in a specified location and finally start a debug session on the same file that is orchestrating it all!

Expand All @@ -30,13 +30,12 @@ The main motivation behind it was that while `Remote Control` uses `websockets`,
The extension has the following settings which you can use to configure it:

- `restRemoteControl.enable`: enable/disable this extension
- `restRemoteControl.host`: the hostname of the HTTP server. Default: `127.0.0.1`.
- `restRemoteControl.port`: set the port number on which the HTTP server will listen
- `restRemoteControl.fallbacks`: an array of port numbers to fallback to if the port is already in use.

## Usage

When you install this extension, it will automatically try to start a HTTP server on port `37100`. This port can be changed on in the VSCode settings. When you are going to use multiple VSCode sessions at the same time, it is best to configure it on workspace level or use the `restRemoteControl.fallbacks` setting to specify fallback ports when the previous one is already in use.
When you install this extension, it will automatically try to start a HTTP server on port `37100`. This port can be changed on in the VSCode settings. When you are going to use multiple VSCode sessions at the same time, it is best to configure it on workspace level or use the `restRemoteControl.fallbacks` setting to specify fallback ports when the previous one is already in use. VSCode terminals opened will have environment variable `REMOTE_CONTROL_PORT` set with the port the server is currently listening to.

![status bar listening message](assets/statusbar-item.png)

Expand Down Expand Up @@ -100,14 +99,14 @@ Some VSCode commands expect VSCode's defined types such as [Range](https://code.
As the extension progresses, I plan to add more _special_ commands (i.e. commands that require some use of the [VSCode API](https://code.visualstudio.com/api/references/vscode-api)). For now, we have defined the following commands:

- `custom.goToFileLineCharacter`: allows you to nagivate to a specific position in a file by passing the file path, line and column number as arguments

- `custom.startDebugSession`: allows you to invoke `vscode.debug.startDebugging()` API by passing the workspace folder and a name or definition of a debug configuration

- `custom.runInTerminal`: allows you to invoke commands the currently active integrated terminal

- `custom.showQuickPick`: show quick pick dialog to collect selection from the user
- `custom.showInformationMessage`, `custom.showWarningMessage` and `custom.showErrorMessage`: show message dialogs to the user and let them click on a button
- `custom.listInstalledExtensions`: get the list of installed extension IDs

- `custom.showInformationMessage`, `custom.showWarningMessage` and `custom.showErrorMessage`: Show message dialogs to the user
## To implement in the near future:
- Add the ability to set a breakpoint at the specified file/line combination


### How do I get the command ID?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "This extension allows you to remotely control Visual Studio Code via a REST endpoint, taking automation to the next level.",
"publisher": "dpar39",
"license": "MIT",
"version": "0.0.2",
"version": "0.0.3",
"engines": {
"vscode": "^1.55.0"
},
Expand Down
20 changes: 17 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@ import { AddressInfo } from "net";
import { ControlRequest } from "./models/controlRequest";
import { processRemoteControlRequest } from "./services/requestProcessor";

export let server: http.Server;
let server: http.Server;
let statusbar: vscode.StatusBarItem;

export const EXTENSION_ID: string = "dpar39.vscode-rest-control";
export function getListeningPort(): number | undefined {
if (!server || !server.listening) {
return;
}
const address = server.address() as any;
return address?.port;
}

const SETTINGS_NAME: string = "restRemoteControl";

function setRemoteControlEnvironmentVariable(context: vscode.ExtensionContext, port: number = 0) {
context.environmentVariableCollection.replace("REMOTE_CONTROL_PORT", port ? `${port}` : '');
}

const startHttpServer = async (
context: vscode.ExtensionContext,
host: string,
Expand Down Expand Up @@ -71,7 +83,7 @@ const startHttpServer = async (

Logger.info(listeningMessage);
// set the remote control port as an environment variable
context.environmentVariableCollection.replace("REMOTE_CONTROL_PORT", `${verifiedPort}`);
setRemoteControlEnvironmentVariable(context, verifiedPort);
statusbar.text = `$(plug) RC Port: ${verifiedPort}`;
statusbar.tooltip = listeningMessage;
});
Expand All @@ -94,6 +106,7 @@ function setupRestControl(context: vscode.ExtensionContext) {
statusbar.tooltip = `REST remote control has been disabled via setting "${SETTINGS_NAME}.enabled": false`;
statusbar.text = "$(debug-disconnect) RC Disabled";
server?.close();
setRemoteControlEnvironmentVariable(context);
Logger.info("VSCode REST Control has been disabled via settings!");
}
}
Expand All @@ -117,6 +130,7 @@ export function activate(context: vscode.ExtensionContext) {
}

// deactivate extension method
export function deactivate() {
export function deactivate(context: vscode.ExtensionContext) {
server?.close();
setRemoteControlEnvironmentVariable(context);
}
5 changes: 2 additions & 3 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from "assert";
import { EXTENSION_ID, server } from "../../extension";
import { EXTENSION_ID, getListeningPort } from "../../extension";

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
Expand All @@ -11,10 +11,9 @@ suite("Extension Test Suite", () => {
suiteTeardown(() => { });

test("check can list extensions", async () => {
const address = server.address() as any;
const extensionIds: string[] = (await makeRequest(
"custom.listInstalledExtensions",
[], address.port
[], getListeningPort()
)) as string[];
assert(extensionIds.includes(EXTENSION_ID));
}).timeout(5000);
Expand Down

0 comments on commit a1e7933

Please sign in to comment.