diff --git a/extensions/github/src/shareProviders.ts b/extensions/github/src/shareProviders.ts index 1188a002a3d..78cdb3bd175 100644 --- a/extensions/github/src/shareProviders.ts +++ b/extensions/github/src/shareProviders.ts @@ -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}`); } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index a42f890530d..64cddfd78f5 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -364,7 +364,7 @@ export interface IDocumentFilterDto { export interface IShareableItemDto { resourceUri: UriComponents; - range?: IRange; + selection?: IRange; } export interface ISignatureHelpProviderMetadataDto { diff --git a/src/vs/workbench/api/common/extHostShare.ts b/src/vs/workbench/api/common/extHostShare.ts index 618fe17138f..0e0c2bc8f1b 100644 --- a/src/vs/workbench/api/common/extHostShare.ts +++ b/src/vs/workbench/api/common/extHostShare.ts @@ -25,7 +25,7 @@ export class ExtHostShare implements ExtHostShareShape { async $provideShare(handle: number, shareableItem: IShareableItemDto, token: CancellationToken): Promise { 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; } diff --git a/src/vs/workbench/contrib/share/browser/share.contribution.ts b/src/vs/workbench/contrib/share/browser/share.contribution.ts index 9608f5718a1..0794c8673a3 100644 --- a/src/vs/workbench/contrib/share/browser/share.contribution.ts +++ b/src/vs/workbench/contrib/share/browser/share.contribution.ts @@ -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( { diff --git a/src/vs/workbench/contrib/share/browser/shareService.ts b/src/vs/workbench/contrib/share/browser/shareService.ts index 6fe98f2a5b0..7984c3f00e2 100644 --- a/src/vs/workbench/contrib/share/browser/shareService.ts +++ b/src/vs/workbench/contrib/share/browser/shareService.ts @@ -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 { + 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) { diff --git a/src/vs/workbench/contrib/share/common/share.ts b/src/vs/workbench/contrib/share/common/share.ts index b389d71c38b..f8df3305e66 100644 --- a/src/vs/workbench/contrib/share/common/share.ts +++ b/src/vs/workbench/contrib/share/common/share.ts @@ -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 {