Skip to content

Commit

Permalink
Provide full string when evaluating clipboard. Fixes microsoft#110
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Dec 11, 2020
1 parent f9b54cd commit 7635085
Show file tree
Hide file tree
Showing 7 changed files with 2,454 additions and 631 deletions.

Large diffs are not rendered by default.

2,473 changes: 1,943 additions & 530 deletions src/debugpy/_vendored/pydevd/_pydevd_bundle/_debug_adapter/pydevd_schema.py

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,13 @@ def __create_frame():
return

variable = frame_tracker.obtain_as_variable(expression, eval_result, frame=frame)
var_data = variable.get_var_data(fmt=fmt)
if context == 'clipboard':
# Note: requires 'supportsClipboardContext=True' in the capabilities.
if not fmt:
fmt = {'rawString': True}
else:
fmt['rawString'] = True
var_data = variable.get_var_data(fmt=fmt, maxstring_outer=2**64, maxstring_inner=2**64)

body = pydevd_schema.EvaluateResponseBody(
result=var_data['value'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def on_initialize_request(self, py_db, request):
supportsLogPoints=True,
supportsSetExpression=True,
supportsTerminateRequest=True,
supportsClipboardContext=True,

exceptionBreakpointFilters=[
{'filter': 'raised', 'label': 'Raised Exceptions', 'default': False},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_value(self):
def get_variable_reference(self):
return id(self.value)

def get_var_data(self, fmt=None):
def get_var_data(self, fmt=None, **safe_repr_custom_attrs):
'''
:param dict fmt:
Format expected by the DAP (keys: 'hex': bool, 'rawString': bool)
Expand All @@ -44,6 +44,8 @@ def get_var_data(self, fmt=None):
if fmt is not None:
safe_repr.convert_to_hex = fmt.get('hex', False)
safe_repr.raw_value = fmt.get('rawString', False)
for key, val in safe_repr_custom_attrs.items():
setattr(safe_repr, key, val)

type_name, _type_qualifier, _is_exception_on_eval, resolver, value = get_variable_details(
self.value, to_string=safe_repr)
Expand Down
61 changes: 61 additions & 0 deletions src/debugpy/_vendored/pydevd/tests_python/test_debugger_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,67 @@ def test_evaluate_block_repl(case_setup):
writer.finished_ok = True


def test_evaluate_block_clipboard(case_setup, pyfile):

@pyfile
def target():
MAX_LIMIT = 65538

class SomeObj(object):

def __str__(self):
return var1

__repr__ = __str__

var1 = 'a' * 80000
var2 = 20000
var3 = SomeObj()

print('TEST SUCEEDED') # Break here

def verify(evaluate_response):
# : :type evaluate_response: EvaluateResponse
assert len(evaluate_response.body.result) == 80000
assert '...' not in evaluate_response.body.result
assert set(evaluate_response.body.result) == set(['a'])

with case_setup.test_file(target) as writer:
json_facade = JsonFacade(writer)
json_facade.write_launch(justMyCode=False)
json_facade.write_set_breakpoints(writer.get_line_index_with_content('Break here'))
json_facade.write_make_initial_run()

json_hit = json_facade.wait_for_thread_stopped()
json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id)

evaluate_response = json_facade.evaluate(
'var1',
frameId=json_hit.frame_id,
context='clipboard',
)
verify(evaluate_response)

evaluate_response = json_facade.evaluate(
'var2',
frameId=json_hit.frame_id,
context='clipboard',
fmt={'hex': True}
)
# i.e.: In raw value does not return as hex.
assert evaluate_response.body.result == "20000"

evaluate_response = json_facade.evaluate(
'var3',
frameId=json_hit.frame_id,
context='clipboard',
)
verify(evaluate_response)

json_facade.write_continue()
writer.finished_ok = True


@pytest.mark.skipif(IS_PY26, reason='__dir__ not customizable on Python 2.6')
def test_exception_on_dir(case_setup):
with case_setup.test_file('_debugger_case_dir_exception.py') as writer:
Expand Down
1 change: 1 addition & 0 deletions src/debugpy/adapter/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def initialize_request(self, request):
"supportsValueFormattingOptions": True,
"supportsTerminateDebuggee": True,
"supportsGotoTargetsRequest": True,
"supportsClipboardContext": True,
"exceptionBreakpointFilters": exception_breakpoint_filters,
}

Expand Down

0 comments on commit 7635085

Please sign in to comment.