-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API for extending the connections pane
- Loading branch information
Showing
11 changed files
with
336 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/vs/workbench/api/browser/positron/mainThreadConnections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2023-2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
|
||
import { extHostNamedCustomer, IExtHostContext } from '../../../services/extensions/common/extHostCustomers'; | ||
import { IDriver, IDriverMetadata, Input } from '../../../services/positronConnections/browser/interfaces/positronConnectionsDriver'; | ||
import { IPositronConnectionsService } from '../../../services/positronConnections/browser/interfaces/positronConnectionsService'; | ||
import { ExtHostConnectionsShape, ExtHostPositronContext, MainPositronContext, MainThreadConnectionsShape } from '../../common/positron/extHost.positron.protocol'; | ||
|
||
@extHostNamedCustomer(MainPositronContext.MainThreadConnections) | ||
export class MainThreadConnections implements MainThreadConnectionsShape { | ||
private readonly _proxy: ExtHostConnectionsShape; | ||
constructor( | ||
extHostContext: IExtHostContext, | ||
@IPositronConnectionsService private readonly _connectionsService: IPositronConnectionsService | ||
) { | ||
this._proxy = extHostContext.getProxy(ExtHostPositronContext.ExtHostConnections); | ||
} | ||
|
||
$registerConnectionDriver(driverId: string, metadata: IDriverMetadata, availableMethods: IAvailableDriverMethods): void { | ||
this._connectionsService.driverManager.registerDriver(new MainThreadDriverAdapter( | ||
driverId, metadata, availableMethods, this._proxy | ||
)); | ||
} | ||
|
||
$removeConnectionDriver(driverId: string): void { | ||
this._connectionsService.driverManager.removeDriver(driverId); | ||
} | ||
|
||
dispose(): void { | ||
|
||
} | ||
} | ||
|
||
export interface IAvailableDriverMethods { | ||
generateCode: boolean, | ||
connect: boolean, | ||
checkDependencies: boolean, | ||
installDependencies: boolean | ||
} | ||
|
||
class MainThreadDriverAdapter implements IDriver { | ||
constructor( | ||
readonly driverId: string, | ||
readonly metadata: IDriverMetadata, | ||
private readonly availableMethods: IAvailableDriverMethods, | ||
private readonly _proxy: ExtHostConnectionsShape | ||
) { } | ||
get generateCode() { | ||
if (!this.availableMethods.generateCode) { | ||
return undefined; | ||
} | ||
return (inputs: Input[]) => this._proxy.$driverGenerateCode(this.driverId, inputs); | ||
} | ||
get connect() { | ||
if (!this.availableMethods.connect) { | ||
return undefined; | ||
} | ||
} | ||
get checkDependencies() { | ||
if (!this.availableMethods.checkDependencies) { | ||
return undefined; | ||
} | ||
} | ||
get installDependencies() { | ||
if (!this.availableMethods.installDependencies) { | ||
return undefined; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/vs/workbench/api/common/positron/extHostConnections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Disposable } from 'vscode'; | ||
import * as positron from 'positron'; | ||
import * as extHostProtocol from './extHost.positron.protocol.js'; | ||
import { Input, InputType } from '../../../services/positronConnections/browser/interfaces/positronConnectionsDriver.js'; | ||
|
||
export class ExtHostConnections implements extHostProtocol.ExtHostConnectionsShape { | ||
|
||
private readonly _proxy: extHostProtocol.MainThreadConnectionsShape; | ||
private _drivers: positron.ConnectionsDriver[] = []; | ||
|
||
constructor( | ||
mainContext: extHostProtocol.IMainPositronContext, | ||
) { | ||
// Trigger creation of the proxy | ||
this._proxy = mainContext.getProxy(extHostProtocol.MainPositronContext.MainThreadConnections); | ||
} | ||
|
||
public registerConnectionDriver(driver: positron.ConnectionsDriver): Disposable { | ||
// Check if the driver is already registered, and if not push, otherwise replace | ||
const existingDriverIndex = this._drivers.findIndex(d => d.driverId === driver.driverId); | ||
if (existingDriverIndex !== -1) { | ||
this._drivers[existingDriverIndex] = driver; | ||
} else { | ||
this._drivers.push(driver); | ||
} | ||
|
||
const metadata = { | ||
...driver.metadata, | ||
inputs: driver.metadata.inputs.map(i => extHost2MainThreadInput(i)) | ||
} | ||
|
||
this._proxy.$registerConnectionDriver( | ||
driver.driverId, | ||
metadata, | ||
{ | ||
generateCode: driver.generateCode ? true : false, | ||
connect: driver.connect ? true : false, | ||
checkDependencies: driver.checkDependencies ? true : false, | ||
installDependencies: driver.installDependencies ? true : false | ||
} | ||
); | ||
return new Disposable(() => { }); | ||
} | ||
|
||
public async $driverGenerateCode(driverId: string, inputs: Input[]) { | ||
const driver = this._drivers.find(d => d.driverId === driverId); | ||
if (!driver || !driver.generateCode) { | ||
throw new Error(`Driver ${driverId} does not support code generation`); | ||
} | ||
return driver.generateCode(inputs.map( | ||
i => ({ ...i, type: i.type as string as positron.ConnectionsInputType }) | ||
)); | ||
} | ||
|
||
public $driverConnect(driverId: string, code: string): Promise<void> { | ||
const driver = this._drivers.find(d => d.driverId === driverId); | ||
if (!driver || !driver.connect) { | ||
throw new Error(`Driver ${driverId} does not support connecting`); | ||
} | ||
return driver.connect(code); | ||
} | ||
|
||
public $driverCheckDependencies(driverId: string): Promise<boolean> { | ||
const driver = this._drivers.find(d => d.driverId === driverId); | ||
if (!driver || !driver.checkDependencies) { | ||
throw new Error(`Driver ${driverId} does not support checking dependencies`); | ||
} | ||
return driver.checkDependencies(); | ||
} | ||
|
||
public $driverInstallDependencies(driverId: string): Promise<boolean> { | ||
const driver = this._drivers.find(d => d.driverId === driverId); | ||
if (!driver || !driver.installDependencies) { | ||
throw new Error(`Driver ${driverId} does not support installing dependencies`); | ||
} | ||
return driver.installDependencies(); | ||
} | ||
} | ||
|
||
function extHost2MainThreadInput(input: positron.ConnectionsInput): Input { | ||
return { | ||
...input, | ||
type: input.type as string as InputType | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.