Skip to content

Commit

Permalink
Added custom.getExtensionInfo to be able to query extension details.
Browse files Browse the repository at this point in the history
  • Loading branch information
Darien Pardinas Diaz committed Jun 18, 2024
1 parent 5e6af1c commit f5cbb1e
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [0.0.6]

- Added `custom.getExtensionInfo` to get specific information about an extension by passing the extension ID as parameter. Use `custom.listInstalledExtensions`to list all installed extensions.

## [0.0.5]

- Added `custom.workspaceFile` and `custom.workspaceFolders` to retrieve the workspace file (if any) and folders currently opened in the workspace (if any)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ 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.goToFileLineCharacter`: allows you to navigate 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 as it would be set in `launch.json`
- `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.getExtensionInfo`: get details of an installed extension by passing the extension ID

## To implement in the near future:
- Add the ability to set a breakpoint at the specified file/line combination
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.5",
"version": "0.0.6",
"engines": {
"vscode": "^1.55.0"
},
Expand Down
11 changes: 10 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ export function getListeningPort(): number | undefined {
const SETTINGS_NAME: string = "restRemoteControl";

function setRemoteControlEnvironmentVariable(context: vscode.ExtensionContext, port: number = 0) {
context.environmentVariableCollection.replace("REMOTE_CONTROL_PORT", port ? `${port}` : '');
const RC_PORT_ENVVAR_NAME = "REMOTE_CONTROL_PORT";
if (port === 0) {
context.environmentVariableCollection.delete(RC_PORT_ENVVAR_NAME);
} else {
context.environmentVariableCollection.replace(RC_PORT_ENVVAR_NAME, port.toString());
}
const terminalUpdateCommand = port === 0 ? `unset ${RC_PORT_ENVVAR_NAME}` : `export ${RC_PORT_ENVVAR_NAME}=${port}`;
vscode.window.terminals.map(terminal => {
terminal.sendText(terminalUpdateCommand);
});
}

const startHttpServer = async (
Expand Down
9 changes: 9 additions & 0 deletions src/services/requestProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ export async function processRemoteControlRequest(requestObject: ControlRequest)
return vscode.extensions.all.map((e) => e.id);
}

if (command === "custom.getExtensionInfo") {
const extensionId = args[0];
const extension = vscode.extensions.all.find((e) => e.id === extensionId);
if (!extension) {
throw new Error(`Extension with id=${extensionId} was not found`);
}
return extension;
}

if (command === "custom.workspaceFile") {
return vscode.workspace.workspaceFile?.toString();
}
Expand Down
14 changes: 13 additions & 1 deletion src/test/workspace1/samples.http
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,19 @@ content-type: application/json

{ "command": "custom.listInstalledExtensions" }

### get current workspace
### get extension details
POST {{endpoint}} HTTP/1.1
content-type: application/json

{ "command": "custom.getExtensionInfo", "args": ["dpar39.vscode-rest-control"] }

### get current workspace file
POST {{endpoint}} HTTP/1.1
content-type: application/json

{ "command": "custom.workspaceFile" }

### get current workspace folders
POST {{endpoint}} HTTP/1.1
content-type: application/json

Expand Down

0 comments on commit f5cbb1e

Please sign in to comment.