@@ -19,13 +19,14 @@ import { HistoryNavigator } from 'vs/base/common/history';
1919import { KeyCode , KeyMod } from 'vs/base/common/keyCodes' ;
2020import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
2121import { removeAnsiEscapeCodes } from 'vs/base/common/strings' ;
22+ import { ThemeIcon } from 'vs/base/common/themables' ;
2223import { URI as uri } from 'vs/base/common/uri' ;
2324import 'vs/css!./media/repl' ;
2425import { ICodeEditor , isCodeEditor } from 'vs/editor/browser/editorBrowser' ;
2526import { EditorAction , registerEditorAction } from 'vs/editor/browser/editorExtensions' ;
2627import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
2728import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget' ;
28- import { EditorOption , EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions' ;
29+ import { EDITOR_FONT_DEFAULTS , EditorOption } from 'vs/editor/common/config/editorOptions' ;
2930import { Position } from 'vs/editor/common/core/position' ;
3031import { Range } from 'vs/editor/common/core/range' ;
3132import { IDecorationOptions } from 'vs/editor/common/editorCommon' ;
@@ -55,18 +56,17 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
5556import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
5657import { editorForeground , resolveColorValue } from 'vs/platform/theme/common/colorRegistry' ;
5758import { IThemeService } from 'vs/platform/theme/common/themeService' ;
58- import { ThemeIcon } from 'vs/base/common/themables' ;
5959import { FilterViewPane , IViewPaneOptions , ViewAction } from 'vs/workbench/browser/parts/views/viewPane' ;
6060import { IViewDescriptorService , IViewsService } from 'vs/workbench/common/views' ;
6161import { getSimpleCodeEditorWidgetOptions , getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions' ;
6262import { FocusSessionActionViewItem } from 'vs/workbench/contrib/debug/browser/debugActionViewItems' ;
6363import { debugConsoleClearAll , debugConsoleEvaluationPrompt } from 'vs/workbench/contrib/debug/browser/debugIcons' ;
6464import { LinkDetector } from 'vs/workbench/contrib/debug/browser/linkDetector' ;
6565import { ReplFilter } from 'vs/workbench/contrib/debug/browser/replFilter' ;
66- import { ReplAccessibilityProvider , ReplDataSource , ReplDelegate , ReplEvaluationInputsRenderer , ReplEvaluationResultsRenderer , ReplGroupRenderer , ReplRawObjectsRenderer , ReplOutputElementRenderer , ReplVariablesRenderer } from 'vs/workbench/contrib/debug/browser/replViewer' ;
67- import { CONTEXT_DEBUG_STATE , CONTEXT_IN_DEBUG_REPL , CONTEXT_MULTI_SESSION_REPL , DEBUG_SCHEME , getStateLabel , IDebugConfiguration , IDebugService , IDebugSession , IReplConfiguration , IReplElement , IReplOptions , REPL_VIEW_ID , State } from 'vs/workbench/contrib/debug/common/debug' ;
66+ import { ReplAccessibilityProvider , ReplDataSource , ReplDelegate , ReplEvaluationInputsRenderer , ReplEvaluationResultsRenderer , ReplGroupRenderer , ReplOutputElementRenderer , ReplRawObjectsRenderer , ReplVariablesRenderer } from 'vs/workbench/contrib/debug/browser/replViewer' ;
67+ import { CONTEXT_DEBUG_STATE , CONTEXT_IN_DEBUG_REPL , CONTEXT_MULTI_SESSION_REPL , DEBUG_SCHEME , IDebugConfiguration , IDebugService , IDebugSession , IReplConfiguration , IReplElement , IReplOptions , REPL_VIEW_ID , State , getStateLabel } from 'vs/workbench/contrib/debug/common/debug' ;
6868import { Variable } from 'vs/workbench/contrib/debug/common/debugModel' ;
69- import { ReplGroup } from 'vs/workbench/contrib/debug/common/replModel' ;
69+ import { ReplEvaluationResult , ReplGroup } from 'vs/workbench/contrib/debug/common/replModel' ;
7070import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
7171
7272const $ = dom . $ ;
@@ -1045,12 +1045,33 @@ registerAction2(class extends Action2 {
10451045
10461046 async run ( accessor : ServicesAccessor , element : IReplElement ) : Promise < void > {
10471047 const clipboardService = accessor . get ( IClipboardService ) ;
1048+ const debugService = accessor . get ( IDebugService ) ;
10481049 const nativeSelection = window . getSelection ( ) ;
10491050 const selectedText = nativeSelection ?. toString ( ) ;
10501051 if ( selectedText && selectedText . length > 0 ) {
1051- await clipboardService . writeText ( selectedText ) ;
1052+ return clipboardService . writeText ( selectedText ) ;
10521053 } else if ( element ) {
1053- await clipboardService . writeText ( element . toString ( ) ) ;
1054+ return clipboardService . writeText ( await this . tryEvaluateAndCopy ( debugService , element ) || element . toString ( ) ) ;
1055+ }
1056+ }
1057+
1058+ private async tryEvaluateAndCopy ( debugService : IDebugService , element : IReplElement ) : Promise < string | undefined > {
1059+ // todo: we should expand DAP to allow copying more types here (#187784)
1060+ if ( ! ( element instanceof ReplEvaluationResult ) ) {
1061+ return ;
1062+ }
1063+
1064+ const stackFrame = debugService . getViewModel ( ) . focusedStackFrame ;
1065+ const session = debugService . getViewModel ( ) . focusedSession ;
1066+ if ( ! stackFrame || ! session || ! session . capabilities . supportsClipboardContext ) {
1067+ return ;
1068+ }
1069+
1070+ try {
1071+ const evaluation = await session . evaluate ( element . originalExpression , stackFrame . frameId , 'clipboard' ) ;
1072+ return evaluation ?. body . result ;
1073+ } catch ( e ) {
1074+ return ;
10541075 }
10551076 }
10561077} ) ;
0 commit comments