Support language selector and passing selection to share providers (#184196)

* Allow selecting share provider by language

* Pass selections to extension providers
This commit is contained in:
Joyce Er 2023-06-02 11:19:32 -07:00 committed by GitHub
parent ccc5e48e92
commit 0876c19e0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 13 deletions

View file

@ -90,7 +90,7 @@ export class VscodeDevShareProvider implements vscode.ShareProvider, vscode.Disp
const blobSegment = repository?.state.HEAD?.name ? encodeURIComponentExceptSlashes(repository.state.HEAD?.name) : repository?.state.HEAD?.commit;
const filepathSegment = encodeURIComponentExceptSlashes(item.resourceUri.path.substring(repository?.rootUri.path.length));
const rangeSegment = getRangeSegment(item);
return vscode.Uri.parse(`${this.getVscodeDevHost()}/${repo.owner}/${repo.repo}/blob/${blobSegment}${filepathSegment}${rangeSegment}${rangeSegment}`);
return vscode.Uri.parse(`${this.getVscodeDevHost()}/${repo.owner}/${repo.repo}/blob/${blobSegment}${filepathSegment}${rangeSegment}`);
}

View file

@ -364,7 +364,7 @@ export interface IDocumentFilterDto {
export interface IShareableItemDto {
resourceUri: UriComponents;
range?: IRange;
selection?: IRange;
}
export interface ISignatureHelpProviderMetadataDto {

View file

@ -25,7 +25,7 @@ export class ExtHostShare implements ExtHostShareShape {
async $provideShare(handle: number, shareableItem: IShareableItemDto, token: CancellationToken): Promise<UriComponents | undefined> {
const provider = this.providers.get(handle);
const result = await provider?.provideShare({ selection: Range.to(shareableItem.range), resourceUri: URI.revive(shareableItem.resourceUri) }, token);
const result = await provider?.provideShare({ selection: Range.to(shareableItem.selection), resourceUri: URI.revive(shareableItem.resourceUri) }, token);
return result ?? undefined;
}

View file

@ -29,6 +29,7 @@ import { IShareService } from 'vs/workbench/contrib/share/common/share';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
const targetMenus = [
MenuId.EditorContextShare,
@ -83,15 +84,16 @@ class ShareWorkbenchContribution {
const dialogService = accessor.get(IDialogService);
const urlService = accessor.get(IOpenerService);
const progressService = accessor.get(IProgressService);
const selection = accessor.get(ICodeEditorService).getActiveCodeEditor()?.getSelection() ?? undefined;
const uri = await progressService.withProgress({
location: ProgressLocation.Window,
detail: localize('generating link', 'Generating link...')
}, async () => shareService.provideShare({ resourceUri, selection }, new CancellationTokenSource().token));
const uri = await shareService.provideShare({ resourceUri }, new CancellationTokenSource().token);
if (uri) {
const uriText = uri.toString();
await progressService.withProgress({
location: ProgressLocation.Window,
detail: localize('generating link', 'Generating link...')
}, () => clipboardService.writeText(uriText));
await clipboardService.writeText(uriText);
dialogService.prompt(
{

View file

@ -6,6 +6,7 @@
import { CancellationToken } from 'vs/base/common/cancellation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { score } from 'vs/editor/common/languageSelector';
import { localize } from 'vs/nls';
import { ISubmenuItem } from 'vs/platform/actions/common/actions';
@ -25,7 +26,8 @@ export class ShareService implements IShareService {
constructor(
@IContextKeyService private contextKeyService: IContextKeyService,
@ILabelService private readonly labelService: ILabelService,
@IQuickInputService private quickInputService: IQuickInputService
@IQuickInputService private quickInputService: IQuickInputService,
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
) {
this.providerCount = ShareProviderCountContext.bindTo(this.contextKeyService);
}
@ -47,8 +49,9 @@ export class ShareService implements IShareService {
}
async provideShare(item: IShareableItem, token: CancellationToken): Promise<URI | undefined> {
const language = this.codeEditorService.getActiveCodeEditor()?.getModel()?.getLanguageId() ?? '';
const providers = [...this._providers.values()]
.filter((p) => score(p.selector, item.resourceUri, '', true, undefined, undefined) > 0)
.filter((p) => score(p.selector, item.resourceUri, language, true, undefined, undefined) > 0)
.sort((a, b) => a.priority - b.priority);
if (providers.length === 0) {

View file

@ -5,15 +5,15 @@
import { CancellationToken } from 'vs/base/common/cancellation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IRange } from 'vs/base/common/range';
import { URI } from 'vs/base/common/uri';
import { Selection } from 'vs/editor/common/core/selection';
import { LanguageSelector } from 'vs/editor/common/languageSelector';
import { ISubmenuItem } from 'vs/platform/actions/common/actions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export interface IShareableItem {
resourceUri: URI;
location?: IRange;
selection?: Selection;
}
export interface IShareProvider {