Browse Source

Fixes Live Share support

- Fixes paths to keep the `vsls:` scheme
 - Ensures that we can find our request in the args
   - Live Share seems to have added a new arg at the start of the array, so protect ourselves
main
Eric Amodio 1 year ago
parent
commit
38892d9c6b
5 changed files with 29 additions and 13 deletions
  1. +1
    -1
      src/@types/vsls.d.ts
  2. +2
    -1
      src/env/node/git/vslsGitProvider.ts
  3. +10
    -6
      src/vsls/guest.ts
  4. +11
    -3
      src/vsls/host.ts
  5. +5
    -2
      src/vsls/vsls.ts

+ 1
- 1
src/@types/vsls.d.ts View File

@ -74,7 +74,7 @@ export interface SharedServiceProxy {
readonly onDidChangeIsServiceAvailable: Event<boolean>;
onNotify(name: string, handler: NotifyHandler): void;
request(name: string, args: any[], cancellation?: CancellationToken): Promise<any>;
request<T>(name: string, args: any[], cancellation?: CancellationToken): Promise<T>;
notify(name: string, args: object): void;
}

+ 2
- 1
src/env/node/git/vslsGitProvider.ts View File

@ -64,7 +64,8 @@ export class VslsGitProvider extends LocalGitProvider {
override canHandlePathOrUri(scheme: string, pathOrUri: string | Uri): string | undefined {
// TODO@eamodio To support virtual repositories, we need to verify that the path is local here (by converting the shared path to a local path)
return super.canHandlePathOrUri(scheme, pathOrUri);
const path = super.canHandlePathOrUri(scheme, pathOrUri);
return path != null ? `${scheme}:${path}` : undefined;
}
override getAbsoluteUri(pathOrUri: string | Uri, base: string | Uri): Uri {

+ 10
- 6
src/vsls/guest.ts View File

@ -56,8 +56,12 @@ export class VslsGuestService implements Disposable {
}
@log()
async git<TOut extends string | Buffer>(options: GitCommandOptions, ...args: any[]) {
const response = await this.sendRequest(GitCommandRequestType, { options: options, args: args });
async git<TOut extends string | Buffer>(options: GitCommandOptions, ...args: any[]): Promise<TOut> {
const response = await this.sendRequest(GitCommandRequestType, {
__type: 'gitlens',
options: options,
args: args,
});
if (response.isBuffer) {
return Buffer.from(response.data, 'binary') as TOut;
@ -68,6 +72,7 @@ export class VslsGuestService implements Disposable {
@log()
async getRepositoriesForUri(uri: Uri): Promise<RepositoryProxy[]> {
const response = await this.sendRequest(GetRepositoriesForUriRequestType, {
__type: 'gitlens',
folderUri: uri.toString(),
});
@ -77,10 +82,9 @@ export class VslsGuestService implements Disposable {
@debug()
private sendRequest<TRequest, TResponse>(
requestType: RequestType<TRequest, TResponse>,
request: TRequest,
_cancellation?: CancellationToken,
request: TRequest & { __type: string },
cancellation?: CancellationToken,
): Promise<TResponse> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this._service.request(requestType.name, [request]);
return this._service.request<TResponse>(requestType.name, [request], cancellation);
}
}

+ 11
- 3
src/vsls/host.ts View File

@ -90,9 +90,17 @@ export class VslsHostService implements Disposable {
requestType: RequestType<TRequest, TResponse>,
handler: (request: TRequest, cancellation: CancellationToken) => Promise<TResponse>,
) {
this._service.onRequest(requestType.name, (args: any[], cancellation: CancellationToken) =>
handler(args[0], cancellation),
);
// eslint-disable-next-line prefer-arrow-callback
this._service.onRequest(requestType.name, function (args: any[], cancellation: CancellationToken) {
let request;
for (const arg of args) {
if (typeof arg === 'object' && '__type' in arg) {
request = arg;
break;
}
}
return handler(request ?? args[0], cancellation);
});
}
@log()

+ 5
- 2
src/vsls/vsls.ts View File

@ -119,7 +119,9 @@ export class VslsController implements Disposable {
this.setReadonly(false);
void setContext('gitlens:vsls', true);
this._ready = defer<void>();
if (!this._ready.pending) {
this._ready = defer<void>();
}
break;
}
@ -132,8 +134,9 @@ export class VslsController implements Disposable {
const vslsExtension = extension.isActive ? extension.exports : await extension.activate();
return (await vslsExtension.getApi('1.0.4753')) ?? undefined;
}
} catch {
} catch (ex) {
debugger;
Logger.error(ex);
}
return undefined;

Loading…
Cancel
Save