Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
terminate(): void {
if (this.isPluginRunning) {
// tslint:disable-next-line:no-any
processTree(this.hostedInstanceProcess.pid, (err: Error, children: Array) => {
// tslint:disable-next-line:no-any
const args = ['-SIGTERM', this.hostedInstanceProcess.pid.toString()].concat(children.map((p: any) => p.PID));
cp.spawn('kill', args);
});
this.hostedPluginSupport.sendLog({ data: 'Hosted instance has been terminated', type: LogType.Info });
} else {
throw new Error('Hosted plugin instance is not running.');
}
}
export const doInitialization: BackendInitializationFn = (rpc: any, pluginMetadata: PluginMetadata) => {
const module = require('module');
const vscodeModuleName = 'vscode';
const vscode = createAPI(rpc);
// register the commands that are in the package.json file
const contributes: any = pluginMetadata.source.contributes;
if (contributes && contributes.commands) {
contributes.commands.forEach((commandItem: any) => {
vscode.commands.registerCommand({ id: commandItem.command, label: commandItem.title });
});
}
// replace command API as it will send only the ID as a string parameter
vscode.commands.registerCommand = function registerCommand(command: any, handler?: (...args: any[]) => T | Thenable): any {
// use of the ID when registering commands
if (typeof command === 'string' && handler) {
return vscode.commands.registerHandler(command, handler);
}
};
protected unregisterWatchScript(path: string): void {
this.watchCompilationRegistry.delete(path);
this.hostedPluginSupport.sendLog({
data: 'Compilation watcher has been stopped in ' + path,
type: LogType.Info
});
}
protected runWatchScript(path: string): Promise {
const watchProcess = cp.spawn('yarn', ['run', 'watch'], { cwd: path });
watchProcess.on('exit', () => this.unregisterWatchScript(path));
this.watchCompilationRegistry.set(path, watchProcess);
this.hostedPluginSupport.sendLog({
data: 'Compilation watcher has been started in ' + path,
type: LogType.Info
});
return Promise.resolve();
}
this.hostedInstanceProcess.stderr.addListener('data', data => {
this.hostedPluginSupport.sendLog({ data: data.toString(), type: LogType.Error });
});
runWatchCompilation(uri: string): Promise {
const pluginRootPath = this.getFsPath(uri);
if (this.watchCompilationRegistry.has(pluginRootPath)) {
throw new Error('Watcher is already running in ' + pluginRootPath);
}
if (!this.checkWatchScript(pluginRootPath)) {
this.hostedPluginSupport.sendLog({
data: 'Plugin in ' + uri + ' doesn\'t have watch script',
type: LogType.Error
});
throw new Error('Watch script doesn\'t exist in ' + pluginRootPath + 'package.json');
}
return this.runWatchScript(pluginRootPath);
}
if (!URI.isUri(resource)) {
throw new Error(`Invalid argument for ${VscodeCommands.OPEN.id} command with URI argument. Found ${resource}`);
}
let options: TextDocumentShowOptions | undefined;
if (typeof columnOrOptions === 'number') {
options = {
viewColumn: fromViewColumn(columnOrOptions)
};
} else if (columnOrOptions) {
options = {
...columnOrOptions,
viewColumn: fromViewColumn(columnOrOptions.viewColumn)
};
}
const editorOptions = DocumentsMainImpl.toEditorOpenerOptions(this.shell, options);
await open(this.openerService, new TheiaURI(resource), editorOptions);
}
});
execute: async (left: URI, right: URI, label?: string, options?: TextDocumentShowOptions) => {
if (!left || !right) {
throw new Error(`${VscodeCommands.DIFF} command requires at least two URI arguments. Found left=${left}, right=${right} as arguments`);
}
if (!URI.isUri(left)) {
throw new Error(`Invalid argument for ${VscodeCommands.DIFF.id} command with left argument. Expecting URI left type but found ${left}`);
}
if (!URI.isUri(right)) {
throw new Error(`Invalid argument for ${VscodeCommands.DIFF.id} command with right argument. Expecting URI right type but found ${right}`);
}
const leftURI = new TheiaURI(left);
const editorOptions = DocumentsMainImpl.toEditorOpenerOptions(this.shell, options);
await this.diffService.openDiffEditor(leftURI, new TheiaURI(right), label, editorOptions);
}
});
if (!resource) {
throw new Error(`${VscodeCommands.OPEN.id} command requires at least URI argument.`);
}
if (!URI.isUri(resource)) {
throw new Error(`Invalid argument for ${VscodeCommands.OPEN.id} command with URI argument. Found ${resource}`);
}
let options: TextDocumentShowOptions | undefined;
if (typeof columnOrOptions === 'number') {
options = {
viewColumn: fromViewColumn(columnOrOptions)
};
} else if (columnOrOptions) {
options = {
...columnOrOptions,
viewColumn: fromViewColumn(columnOrOptions.viewColumn)
};
}
const editorOptions = DocumentsMainImpl.toEditorOpenerOptions(this.shell, options);
await open(this.openerService, new TheiaURI(resource), editorOptions);
}
});
execute: async (resource: URI, columnOrOptions?: ViewColumn | TextDocumentShowOptions) => {
if (!resource) {
throw new Error(`${VscodeCommands.OPEN.id} command requires at least URI argument.`);
}
if (!URI.isUri(resource)) {
throw new Error(`Invalid argument for ${VscodeCommands.OPEN.id} command with URI argument. Found ${resource}`);
}
let options: TextDocumentShowOptions | undefined;
if (typeof columnOrOptions === 'number') {
options = {
viewColumn: fromViewColumn(columnOrOptions)
};
} else if (columnOrOptions) {
options = {
...columnOrOptions,
viewColumn: fromViewColumn(columnOrOptions.viewColumn)
};
}
const editorOptions = DocumentsMainImpl.toEditorOpenerOptions(this.shell, options);
await open(this.openerService, new TheiaURI(resource), editorOptions);
}
});