Reputation: 191
I want to have the 3D drawing program Sketchup send a command to the VSCode editor to Save All. I am familiar with Sketchup's extension development, and can write pretty much any C++ communication code for a Sketchup extension. Its even easier programing extensions using Sketchup's version of Ruby language, which includes TCPsocket and HTTP request objects.
One solution would be to have the sending APP find and obtain the handle to VSCode executable, and and then send the keyboard shortcut for a desired menu option. That isn't the cleanest method, and different code would be needed for the Mac OS.
On the VSCode side of things, I'm not familiar with VSCode configuration and extensions. It appears that VSCode provides a JavaScript API, including "Activation Events":
https://code.visualstudio.com/api/references/activation-events
I don't see anything that meets my needs. The EXTENSION GUIDES sub-option Webview comes closest:
https://code.visualstudio.com/api/extension-guides/webview
Within the URL above, the subsection "Passing messages from a webview to an extension" allows handling a message from a webview, but it appears to need a reference to a WebView dialog box from createWebviewPanel.
I don't know how to proceed further. Please note, I'm not asking how to use VS Code to edit and develop a Sketchup extension, but how to create a VS Code extension or task handler that VS Code executes.
Upvotes: 3
Views: 677
Reputation: 2473
A vscode.workspace.createFileSystemWatcher
file watcher running in a vscode extension would work. You can only watch files within the workspace of the project. Sketchup would write to a file in the workspace of the project. The vscode extension would then execute the workbench.action.files.saveAll
command.
export async function register_fileWatcher( )
{
if ( vscode.workspace.workspaceFolders )
{
const wsFolder = vscode.workspace.workspaceFolders[0].uri.fsPath;
let pattern = path.join( wsFolder, '*.txt');
let watcher = vscode.workspace.createFileSystemWatcher(
pattern, false, false, false);
watcher.onDidChange(_watcherChangeApplied);
watcher.onDidCreate(_watcherChangeApplied);
watcher.onDidDelete(_watcherChangeApplied);
}
}
// ----------------------------- _watcherChangeApplied -----------------------------
function _watcherChangeApplied(e: vscode.Uri)
{
vscode.commands.executeCommand('workbench.action.files.saveAll');
}
// ----------------------------------- activate -----------------------------------
export function activate(context: vscode.ExtensionContext)
{
register_fileWatcher(context) ;
}
Upvotes: 2