mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
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:
parent
ccc5e48e92
commit
0876c19e0a
|
@ -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}`);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ export interface IDocumentFilterDto {
|
|||
|
||||
export interface IShareableItemDto {
|
||||
resourceUri: UriComponents;
|
||||
range?: IRange;
|
||||
selection?: IRange;
|
||||
}
|
||||
|
||||
export interface ISignatureHelpProviderMetadataDto {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 shareService.provideShare({ resourceUri }, new CancellationTokenSource().token);
|
||||
if (uri) {
|
||||
const uriText = uri.toString();
|
||||
|
||||
await progressService.withProgress({
|
||||
const uri = await progressService.withProgress({
|
||||
location: ProgressLocation.Window,
|
||||
detail: localize('generating link', 'Generating link...')
|
||||
}, () => clipboardService.writeText(uriText));
|
||||
}, async () => shareService.provideShare({ resourceUri, selection }, new CancellationTokenSource().token));
|
||||
|
||||
if (uri) {
|
||||
const uriText = uri.toString();
|
||||
await clipboardService.writeText(uriText);
|
||||
|
||||
dialogService.prompt(
|
||||
{
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue