Skip to content

Commit

Permalink
Also support dragging symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Nov 25, 2024
1 parent bab65a1 commit 1e48f68
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
13 changes: 12 additions & 1 deletion src/vs/workbench/contrib/chat/browser/chatInlineAnchorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { IClipboardService } from '../../../../platform/clipboard/common/clipboa
import { ICommandService } from '../../../../platform/commands/common/commands.js';
import { IContextKey, IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
import { IResourceStat } from '../../../../platform/dnd/browser/dnd.js';
import { CodeDataTransfers, DocumentSymbolTransferData, IResourceStat } from '../../../../platform/dnd/browser/dnd.js';
import { ITextResourceEditorInput } from '../../../../platform/editor/common/editor.js';
import { FileKind, IFileService } from '../../../../platform/files/common/files.js';
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
Expand Down Expand Up @@ -232,6 +232,17 @@ export class InlineAnchorWidget extends Disposable {
};
instantiationService.invokeFunction(accessor => fillEditorsDragData(accessor, [stat], e));

if (this.data.kind === 'symbol') {
const symbolData: DocumentSymbolTransferData = {
name: this.data.symbol.name,
fsPath: this.data.symbol.location.uri.fsPath,
range: this.data.symbol.location.range,
kind: this.data.symbol.kind
};

e.dataTransfer?.setData(CodeDataTransfers.SYMBOLS, JSON.stringify([symbolData]));
}

e.dataTransfer?.setDragImage(element, 0, 0);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class DocumentSymbolsOutline implements IOutline<DocumentSymbolItem> {
: target === OutlineTarget.Breadcrumbs
? instantiationService.createInstance(DocumentSymbolFilter, 'breadcrumbs')
: undefined,
dnd: new DocumentSymbolDragAndDrop(),
dnd: instantiationService.createInstance(DocumentSymbolDragAndDrop),
};

this.config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import './documentSymbolsTree.css';
import '../../../../../editor/contrib/symbolIcons/browser/symbolIcons.js'; // The codicon symbol colors are defined here and must be loaded to get colors
import { IDragAndDropData } from '../../../../../base/browser/dnd.js';
import * as dom from '../../../../../base/browser/dom.js';
import { HighlightedLabel } from '../../../../../base/browser/ui/highlightedlabel/highlightedLabel.js';
import { IconLabel, IIconLabelValueOptions } from '../../../../../base/browser/ui/iconLabel/iconLabel.js';
import { IIdentityProvider, IKeyboardNavigationLabelProvider, IListVirtualDelegate } from '../../../../../base/browser/ui/list/list.js';
import { ITreeNode, ITreeRenderer, ITreeFilter, ITreeDragAndDrop, ITreeDragOverReaction } from '../../../../../base/browser/ui/tree/tree.js';
import { ElementsDragAndDropData } from '../../../../../base/browser/ui/list/listView.js';
import { IListAccessibilityProvider } from '../../../../../base/browser/ui/list/listWidget.js';
import { ITreeDragAndDrop, ITreeDragOverReaction, ITreeFilter, ITreeNode, ITreeRenderer } from '../../../../../base/browser/ui/tree/tree.js';
import { mainWindow } from '../../../../../base/browser/window.js';
import { createMatches, FuzzyScore } from '../../../../../base/common/filters.js';
import { ThemeIcon } from '../../../../../base/common/themables.js';
import { URI } from '../../../../../base/common/uri.js';
import { Range } from '../../../../../editor/common/core/range.js';
import { DocumentSymbol, SymbolKind, SymbolKinds, SymbolTag, getAriaLabelForSymbol, symbolKindNames } from '../../../../../editor/common/languages.js';
import { DocumentSymbol, getAriaLabelForSymbol, SymbolKind, symbolKindNames, SymbolKinds, SymbolTag } from '../../../../../editor/common/languages.js';
import { ITextResourceConfigurationService } from '../../../../../editor/common/services/textResourceConfiguration.js';
import { OutlineElement, OutlineGroup, OutlineModel } from '../../../../../editor/contrib/documentSymbols/browser/outlineModel.js';
import '../../../../../editor/contrib/symbolIcons/browser/symbolIcons.js'; // The codicon symbol colors are defined here and must be loaded to get colors
import { localize } from '../../../../../nls.js';
import { IconLabel, IIconLabelValueOptions } from '../../../../../base/browser/ui/iconLabel/iconLabel.js';
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
import { CodeDataTransfers, DocumentSymbolTransferData, IResourceStat } from '../../../../../platform/dnd/browser/dnd.js';
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
import { MarkerSeverity } from '../../../../../platform/markers/common/markers.js';
import { IThemeService } from '../../../../../platform/theme/common/themeService.js';
import { withSelection } from '../../../../../platform/opener/common/opener.js';
import { listErrorForeground, listWarningForeground } from '../../../../../platform/theme/common/colorRegistry.js';
import { ITextResourceConfigurationService } from '../../../../../editor/common/services/textResourceConfiguration.js';
import { IListAccessibilityProvider } from '../../../../../base/browser/ui/list/listWidget.js';
import { IThemeService } from '../../../../../platform/theme/common/themeService.js';
import { fillEditorsDragData } from '../../../../browser/dnd.js';
import { IOutlineComparator, OutlineConfigKeys, OutlineTarget } from '../../../../services/outline/browser/outline.js';
import { ThemeIcon } from '../../../../../base/common/themables.js';
import { mainWindow } from '../../../../../base/browser/window.js';
import { IDragAndDropData, DataTransfers } from '../../../../../base/browser/dnd.js';
import { ElementsDragAndDropData } from '../../../../../base/browser/ui/list/listView.js';
import { CodeDataTransfers } from '../../../../../platform/dnd/browser/dnd.js';
import { withSelection } from '../../../../../platform/opener/common/opener.js';
import { URI } from '../../../../../base/common/uri.js';
import './documentSymbolsTree.css';

export type DocumentSymbolItem = OutlineGroup | OutlineElement;

Expand Down Expand Up @@ -67,7 +69,9 @@ export class DocumentSymbolIdentityProvider implements IIdentityProvider<Documen

export class DocumentSymbolDragAndDrop implements ITreeDragAndDrop<DocumentSymbolItem> {

constructor() { }
constructor(
@IInstantiationService private readonly _instantiationService: IInstantiationService
) { }

getDragURI(element: DocumentSymbolItem): string | null {
const resource = OutlineModel.get(element)?.uri;
Expand Down Expand Up @@ -106,15 +110,19 @@ export class DocumentSymbolDragAndDrop implements ITreeDragAndDrop<DocumentSymbo
}

const outlineElements = item instanceof OutlineElement ? [item] : Array.from(item.children.values());
const symbolsData = outlineElements.map(oe => ({
const symbolsData = outlineElements.map((oe): DocumentSymbolTransferData => ({
name: oe.symbol.name,
fsPath: resource.fsPath,
range: oe.symbol.range,
kind: oe.symbol.kind
}));

originalEvent.dataTransfer.setData(CodeDataTransfers.SYMBOLS, JSON.stringify(symbolsData));
originalEvent.dataTransfer.setData(DataTransfers.RESOURCES, JSON.stringify(outlineElements.map(oe => symbolRangeUri(resource, oe.symbol).toString())));

this._instantiationService.invokeFunction(accessor => fillEditorsDragData(accessor, outlineElements.map((oe): IResourceStat => ({
resource,
selection: oe.symbol.range,
})), originalEvent));
}

onDragOver(): boolean | ITreeDragOverReaction { return false; }
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/outline/browser/outlinePane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ export class OutlinePane extends ViewPane implements IOutlinePane {

const sorter = new OutlineTreeSorter(newOutline.config.comparator, this._outlineViewState.sortBy);

const tree = <WorkbenchDataTree<IOutline<any> | undefined, any, FuzzyScore>>this._instantiationService.createInstance(
WorkbenchDataTree,
const tree = this._instantiationService.createInstance(
WorkbenchDataTree<IOutline<any> | undefined, any, FuzzyScore>,
'OutlinePane',
this._treeContainer,
newOutline.config.delegate,
Expand Down

0 comments on commit 1e48f68

Please sign in to comment.