Skip to content

contribShareMenu proposed menus #176316

Open

Description

@joyceerhl

I'm filing this issue to track the finalization of the contribShareMenu API proposal since I was not able to find a tracking issue, cc Alex Ross (@alexr00).

Current state

The contribShareMenu API proposal tracks the following menu points:

  • file/share
  • editor/context/share

This proposal has been in place for several months without changes, and was previously discussed in #146309 and #157722, but has not yet been finalized. This means it can't yet be used by most extensions, limiting its utility. An example of an extension that IMO would be a great fit for the Share submenus is Live Share (cc jram (@jramsay)):

image

Additional share submenus

As part of #175676 I'm looking at integrating link sharing more deeply into our product surface area, with the goal of making collaboration via links as seamless as possible. Therefore I'm proposing to expand this API proposal to also include

  • editor/title/context/share
  • explorer/context/share

(Note, there is also editor/lineNumber/context via #175945, but I have not added a share submenu for that context menu yet because we are introducing that context menu for the first time all up and it would be odd to only have one item in the menu which is itself a submenu.)

Activity

  1. joyceerhl commented on Mar 7, 2023

    @joyceerhl
    ContributorAuthor

    Feedback from API sync:

    • Could be some opportunity for consolidation across all share menus (and then just inline share actions into all menus)
      • At the same point in time, don't want to show all the same share actions everywhere, and the context object is different
      • e.g. file/share includes export/import profiles which wouldn't be relevant in editor/context/share
    • Unsure whether to include active editor selection if coming via editor/title/context/share or explorer/context/share, waiting for more feedback
  2. mjbvz commented on Mar 14, 2023

    @mjbvz
    Contributor

    Joyce Er (@joyceerhl) One thing I just thought of: how do we support sharing documents from other views, such as the open editors view, or potentially even sharing from custom tree views, such as the Find All References view?

    One option would be to create contribution points for each case. That would let extensions control where their menus show up, but would also require knowing about and adopting a lot of contribution points

    Another option though would be to have a generic shareFile contribution point. This would let VS Code show these contributions in any places where we think a share menu makes sense. It would also let VS Code surface the share commands in other ways, such as a Share... command in the command palette

    I believe we may have considered something similar last week. Were there any concerns about this approach?

  3. joyceerhl commented on Mar 14, 2023

    @joyceerhl
    ContributorAuthor

    The main issue that we discussed last week is that we don't want to show the same share actions everywhere, e.g. file/share has Export/Import Profile... which doesn't make sense in any of the other share submenus.

    how do we support sharing documents from other views, such as the open editors view, or potentially even sharing from custom tree views, such as the Find All References view?

    This is a really good point though. Having a single contribution point would allow us to avoid a continuous adoption cost across extensions anytime we introduce a new area in the product where sharing makes sense.

    It would also let VS Code surface the share commands in other ways, such as a Share... command in the command palette

    Brigit Murtaugh (@bamurtaugh) had a proposal to add a Share button next to the command center if that ever becomes default, and a single share contribution point would also support that scenario.

    If we go with this approach, here is the work that I think should happen:

    • Introduce a shareResource contribution point (I think file might be a little too limiting, e.g. I have wanted to copy links to a specific folder or workspace as well). The contribution point would be responsible for creating share submenus in the following places and ensuring that the right context (both command args and when clauses via overlays) is passed to contributed actions:
      • editor/context
      • editor/title/context
      • editor/lineNumber/context
      • explorer/context
      • file/share
      • editor line number context in diff editors
      • open editors view
      • find all references view
      • SCM view resource state context
    • Keep file/share as a separate menu identifier for now, since at the moment that is the only menu where we want to show actions that wouldn't make sense in all the other cases that we are discussing)
    • Standardize what context gets passed to actions, should be one of:
      1. { uri: vscode.Uri }: indicates generating a link for just the resource but not including range/selection
      2. { uri: vscode.Uri, selections: vscode.Selection }: indicates generating a link for the resource and a specific selection
        -if the start line and end line are the same or if the start and end line are off by 1 and the end column is 0, extensions should generate links for just one line
        • Peng Lyu (@rebornix) we had a related conversation around supporting links for notebooks, I think that maybe we want to support passing NotebookCell ranges as well?
      3. undefined: command palette context
    • Adopt the share contribution in:
      • GitHub Repositories
      • GitHub Pull Requests
      • GitHub
    • Remove previous duplicated link code

    Matt Bierner (@mjbvz) let me know if I missed anything or if you have other suggestions.

  4. joyceerhl commented on Mar 16, 2023

    @joyceerhl
    ContributorAuthor

    Two more places that would be nice to have share menus in:

    • references view
    • search view

    It should be possible to deeplink to a line in a file from the share actions for those views.

  5. joyceerhl commented on Mar 16, 2023

    @joyceerhl
    ContributorAuthor

    Johannes Rieken (@jrieken) and I discussed this and there are a few complications:

    • we need to perform the appropriate renderer <-> ext host type conversions for the arguments that we pass, e.g. an internal ISelection object needs to be properly transformed into a vscode.Selection object if it's being passed to the ext host
    • some of the views where we want to introduce share links in the context menu are actually controlled by extensions rather than core, in which case the context that gets passed is always the data model object of the corresponding extension and is not influenced by core:
      • references view
      • call hierarchy
      • scm view
      • timeline
    • the command/arg approach suffers from the problem that the extension never really knows what args it receives and there is no contract or explicit typing

    In order to be able to provide a consistent context from both core and extension-controlled contexts--without layer breaking--to extensions which want to generate a shareable link, we may be better off with an explicit data provider api. Here is a sketch of how I think this would work:

    • extensions like builtin GitHub, GitHub Pull Requests, Remote Repositories, and Live Share would declare a share contribution in package.json
    • core would inline the contributed command into various menus where it makes sense
    • core and extensions would register SharableDataProviders for various sharable contexts
    • when an extension's share contribution is selected, core would first call a registered ShareableDataProvider capable of providing info about the sharable context
    • the context then gets passed to the extension to generate a link, start a collaboration session, etc

    Currently we're most interested in sharing editor and view context, so here's a sketch of what that api could look like:

    declare module 'vscode' {
    
    	export namespace window {
    		/**
    		 *
    		 * @param viewId The id of the view that the provider can share data about.
    		 * @param provider A provider that can generate {@link ShareableData} for the specified view.
    		 */
    		export function registerShareableTreeDataProvider(viewId: string, provider: ShareableTreeDataProvider): Disposable;
    
    		/**
    		 *
    		 * @param document A selector for editors that the provider can share data about.
    		 * @param provider A provider that can generate {@link ShareableData} for the specified document.
    		 */
    		export function registerShareableDocumentDataProvider(document: DocumentSelector, provider: ShareableDocumentDataProvider): Disposable;
    	}
    
    	interface ShareableTreeDataProvider {
    		provideShareableData(context: TreeItem, token: CancellationToken): ProviderResult<ShareableData>;
    	}
    
    	interface ShareableDocumentDataProvider {
    		provideShareableData(context: DocumentSelector, token: CancellationToken): ProviderResult<ShareableData>;
    	}
    
    	interface ShareableData {
    		readonly uri?: Uri;
    		readonly ranges?: Range[];
    	}
    }

    Another option is to expand the existing TreeDataProvider to include a provideShareableData method:

    	/**
    	 * A data provider that provides tree data
    	 */
    	export interface TreeDataProvider<T> {
    		
    		provideShareableData?(item: TreeItem, token: CancellationToken): ProviderResult<ShareableData>;
    	}
  6. joyceerhl commented on May 15, 2023

    @joyceerhl
    ContributorAuthor

    Some additional limitations of the current implementation, which a central API would be able to address:

    • Each extension is responsible for writing share links to the clipboard, so they step on each other which prevents nice multiselect behavior
    • We have had to introduce multiple share submenus to each context menu that we want to surface Share actions in (to date: explorer/context, editor/context, editor/title/context, editor/lineNumber/context, file). We also want to add Share to more places, and since some of these places are extension-owned tree views and all places have different data object shapes, each extension which contributes a sharing link must deal with parsing different source data types, so the current approach doesn't scale:
      • References view
      • Search view
      • SCM view
      • Open editors view
    • We cannot support a top-level Share action since the actions are surfaced piecemeal by extensions to specific Share submenus

    Basically what we need is API to support the ability to

    1. Get a standard context object from extension-contributed tree views, whose tree item shapes are opaque to core (all other data objects can be handled by core)
    2. Pass that context object to extensions which provide share actions

    I spent some time looking at prior art (copy/paste and drag/drop controllers, which support performing actions relating to data transfer on both tree items and editor context). I learned that we use stringified URIs with line numbers in the fragment, which works well enough for text editors. Unfortunately we already support copying deeplinks to notebook cells, so this approach doesn't suffice for my scenario:

    vscode/src/vscode-dts/vscode.d.ts

    Lines 10567 to 10569 in 06fc826

    * To add a data transfer item that can be dragged into the editor, use the application specific mime type "text/uri-list".
    * The data for "text/uri-list" should be a string with `toString()`ed Uris separated by newlines. To specify a cursor position in the file,
    * set the Uri's fragment to `L3,5`, where 3 is the line number and 5 is the column number.

    Here's my latest API proposal sketch:

    /**
     * 
     * An {@link TreeShareableResourceDataProvider} enables sharing tree items
     * which represent resources from extension-contributed tree views.
     */
    export interface TreeShareableResourceDataProvider<T> {
        /**
         * 
         * @param source A tree item to provide shareable resource data for
         * @returns The underlying shareable resource data represented by the tree item
         */
        provideShareableResourceData(source: T, token: CancellationToken): ProviderResult<ShareableResourceData>;
    }
    
    export interface TreeViewOptions<T> {
        /**
         * 
         * {@link TreeView}s can optionally specify a {@link TreeShareableResourceDataProvider}
         * to ensure that `Share` actions show up in the context menu for the {@link TreeView}. 
         */
        shareableResourceDataProvider?: TreeShareableResourceDataProvider<T>;
    }
    
    /**
     * 
     * To be implemented by:
     * 1. GHPRI
     * 2. RemoteHub
     * 3. Builtin GitHub extension
     * 4. MakeCode
     * 5. Live Share
     */
    export interface ShareProvider {
        readonly id: string;
        readonly label: string;
    
        /**
         * @param resourceData Data representing a shareable resource
         * @returns If applicable, a URI representing the shared resource, to be written to the clipboard
         */
        provideShareResource(resourceData: ShareableResourceData, token: CancellationToken): ProviderResult<Uri>;
    }
    
    /**
     * 
     * Modeled after TabInputText__, TabInputNotebook__, etc.
     */
    export type ShareableResourceData = TextDocumentShareableData | NotebookDocumentShareableData;
    
    export interface TextDocumentShareableData {
        uri: Uri;
        selection: Range;
    }
    
    export interface NotebookDocumentShareableData {
        uri: Uri;
        selection: NotebookRange;
    }
  7. 14 remaining items

  8. alexr00 commented on Jun 27, 2023

    @alexr00
    Member

    Moving to July.

  9. removed their assignment
    on Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiapi-proposalfeature-requeston-testplan

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions