Skip to content

Commit 0876c19

Browse files
authored
Support language selector and passing selection to share providers (microsoft#184196)
* Allow selecting share provider by language * Pass selections to extension providers
1 parent ccc5e48 commit 0876c19

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

extensions/github/src/shareProviders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class VscodeDevShareProvider implements vscode.ShareProvider, vscode.Disp
9090
const blobSegment = repository?.state.HEAD?.name ? encodeURIComponentExceptSlashes(repository.state.HEAD?.name) : repository?.state.HEAD?.commit;
9191
const filepathSegment = encodeURIComponentExceptSlashes(item.resourceUri.path.substring(repository?.rootUri.path.length));
9292
const rangeSegment = getRangeSegment(item);
93-
return vscode.Uri.parse(`${this.getVscodeDevHost()}/${repo.owner}/${repo.repo}/blob/${blobSegment}${filepathSegment}${rangeSegment}${rangeSegment}`);
93+
return vscode.Uri.parse(`${this.getVscodeDevHost()}/${repo.owner}/${repo.repo}/blob/${blobSegment}${filepathSegment}${rangeSegment}`);
9494

9595
}
9696

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export interface IDocumentFilterDto {
364364

365365
export interface IShareableItemDto {
366366
resourceUri: UriComponents;
367-
range?: IRange;
367+
selection?: IRange;
368368
}
369369

370370
export interface ISignatureHelpProviderMetadataDto {

src/vs/workbench/api/common/extHostShare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ExtHostShare implements ExtHostShareShape {
2525

2626
async $provideShare(handle: number, shareableItem: IShareableItemDto, token: CancellationToken): Promise<UriComponents | undefined> {
2727
const provider = this.providers.get(handle);
28-
const result = await provider?.provideShare({ selection: Range.to(shareableItem.range), resourceUri: URI.revive(shareableItem.resourceUri) }, token);
28+
const result = await provider?.provideShare({ selection: Range.to(shareableItem.selection), resourceUri: URI.revive(shareableItem.resourceUri) }, token);
2929
return result ?? undefined;
3030
}
3131

src/vs/workbench/contrib/share/browser/share.contribution.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { IShareService } from 'vs/workbench/contrib/share/common/share';
2929
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
3030
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3131
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
32+
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
3233

3334
const targetMenus = [
3435
MenuId.EditorContextShare,
@@ -83,15 +84,16 @@ class ShareWorkbenchContribution {
8384
const dialogService = accessor.get(IDialogService);
8485
const urlService = accessor.get(IOpenerService);
8586
const progressService = accessor.get(IProgressService);
87+
const selection = accessor.get(ICodeEditorService).getActiveCodeEditor()?.getSelection() ?? undefined;
88+
89+
const uri = await progressService.withProgress({
90+
location: ProgressLocation.Window,
91+
detail: localize('generating link', 'Generating link...')
92+
}, async () => shareService.provideShare({ resourceUri, selection }, new CancellationTokenSource().token));
8693

87-
const uri = await shareService.provideShare({ resourceUri }, new CancellationTokenSource().token);
8894
if (uri) {
8995
const uriText = uri.toString();
90-
91-
await progressService.withProgress({
92-
location: ProgressLocation.Window,
93-
detail: localize('generating link', 'Generating link...')
94-
}, () => clipboardService.writeText(uriText));
96+
await clipboardService.writeText(uriText);
9597

9698
dialogService.prompt(
9799
{

src/vs/workbench/contrib/share/browser/shareService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { CancellationToken } from 'vs/base/common/cancellation';
77
import { IDisposable } from 'vs/base/common/lifecycle';
88
import { URI } from 'vs/base/common/uri';
9+
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
910
import { score } from 'vs/editor/common/languageSelector';
1011
import { localize } from 'vs/nls';
1112
import { ISubmenuItem } from 'vs/platform/actions/common/actions';
@@ -25,7 +26,8 @@ export class ShareService implements IShareService {
2526
constructor(
2627
@IContextKeyService private contextKeyService: IContextKeyService,
2728
@ILabelService private readonly labelService: ILabelService,
28-
@IQuickInputService private quickInputService: IQuickInputService
29+
@IQuickInputService private quickInputService: IQuickInputService,
30+
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
2931
) {
3032
this.providerCount = ShareProviderCountContext.bindTo(this.contextKeyService);
3133
}
@@ -47,8 +49,9 @@ export class ShareService implements IShareService {
4749
}
4850

4951
async provideShare(item: IShareableItem, token: CancellationToken): Promise<URI | undefined> {
52+
const language = this.codeEditorService.getActiveCodeEditor()?.getModel()?.getLanguageId() ?? '';
5053
const providers = [...this._providers.values()]
51-
.filter((p) => score(p.selector, item.resourceUri, '', true, undefined, undefined) > 0)
54+
.filter((p) => score(p.selector, item.resourceUri, language, true, undefined, undefined) > 0)
5255
.sort((a, b) => a.priority - b.priority);
5356

5457
if (providers.length === 0) {

src/vs/workbench/contrib/share/common/share.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import { CancellationToken } from 'vs/base/common/cancellation';
77
import { IDisposable } from 'vs/base/common/lifecycle';
8-
import { IRange } from 'vs/base/common/range';
98
import { URI } from 'vs/base/common/uri';
9+
import { Selection } from 'vs/editor/common/core/selection';
1010
import { LanguageSelector } from 'vs/editor/common/languageSelector';
1111
import { ISubmenuItem } from 'vs/platform/actions/common/actions';
1212
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1313

1414
export interface IShareableItem {
1515
resourceUri: URI;
16-
location?: IRange;
16+
selection?: Selection;
1717
}
1818

1919
export interface IShareProvider {

0 commit comments

Comments
 (0)