Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Adds debug console completion (#772)
Browse files Browse the repository at this point in the history
* Add support for debug console completion

* Add test files

* Adding tests

* Add supportsCompletionsRequest to _requests

* Add test for bad request

* Fix sorting issue in test

* Address comments

* Remove unsupported test for completions

* Add required argument to completions request in tests

* Fix linter issues
  • Loading branch information
karthiknadig authored Aug 29, 2018
1 parent f453ed1 commit df9c8fd
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 18 deletions.
1 change: 1 addition & 0 deletions debugger_protocol/messages/_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class Capabilities(FieldsNamespace):
Field('supportsSetExpression', bool),
Field('supportsModulesRequest', bool),
Field('supportsDebuggerProperties', bool),
Field('supportsCompletionsRequest', bool),
]


Expand Down
45 changes: 45 additions & 0 deletions ptvsd/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@
# print(s)
#ipcjson._TRACE = ipcjson_trace

#completion types.
TYPE_IMPORT = '0'
TYPE_CLASS = '1'
TYPE_FUNCTION = '2'
TYPE_ATTR = '3'
TYPE_BUILTIN = '4'
TYPE_PARAM = '5'
TYPE_LOOK_UP = {
TYPE_IMPORT: 'module',
TYPE_CLASS: 'class',
TYPE_FUNCTION: 'function',
TYPE_ATTR: 'field',
TYPE_BUILTIN: 'keyword',
TYPE_PARAM: 'variable',
}


def NOOP(*args, **kwargs):
pass
Expand Down Expand Up @@ -952,6 +968,7 @@ def _stop_event_loop(self):


INITIALIZE_RESPONSE = dict(
supportsCompletionsRequest=True,
supportsConditionalBreakpoints=True,
supportsConfigurationDoneRequest=True,
supportsDebuggerProperties=True,
Expand Down Expand Up @@ -2222,6 +2239,34 @@ def on_exceptionInfo(self, request, args):
'source': source},
)

@async_handler
def on_completions(self, request, args):
text = args['text']
vsc_fid = args.get('frameId', None)

try:
pyd_tid, pyd_fid = self.frame_map.to_pydevd(vsc_fid)
except KeyError:
self.send_error_response(request)

cmd_args = '{}\t{}\t{}\t{}'.format(pyd_tid, pyd_fid, 'LOCAL', text)
_, _, resp_args = yield self.pydevd_request(
pydevd_comm.CMD_GET_COMPLETIONS,
cmd_args)

xml = self.parse_xml_response(resp_args)
targets = []
for item in list(xml.comp):
target = {}
target['label'] = unquote(item['p0'])
try:
target['type'] = TYPE_LOOK_UP[item['p3']]
except KeyError:
pass
targets.append(target)

self.send_response(request, targets=targets)

# Custom ptvsd message
def on_ptvsd_systemInfo(self, request, args):
try:
Expand Down
18 changes: 0 additions & 18 deletions tests/highlevel/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2299,24 +2299,6 @@ def test_unsupported(self):
self.assert_received(self.debugger, [])


class CompletionsTests(NormalRequestTest, unittest.TestCase):

COMMAND = 'completions'

def test_unsupported(self):
with self.launched():
self.send_request(
text='spa',
column=3,
)
received = self.vsc.received

self.assert_vsc_received(received, [
self.expected_failure('Unknown command'),
])
self.assert_received(self.debugger, [])


##################################
# VSC events

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys
import ptvsd

ptvsd.enable_attach((sys.argv[1], sys.argv[2]))
ptvsd.wait_for_attach()


class SomeClass():
def __init__(self, someVar):
self.some_var = someVar

def do_someting(self):
someVariable = self.some_var
return someVariable


def someFunction(someVar):
someVariable = someVar
return SomeClass(someVariable).do_someting()


someFunction('value')
print('done')
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class SomeClass():
def __init__(self, someVar):
self.some_var = someVar

def do_someting(self):
someVariable = self.some_var
return someVariable


def someFunction(someVar):
someVariable = someVar
return SomeClass(someVariable).do_someting()


someFunction('value')
print('done')
Loading

0 comments on commit df9c8fd

Please sign in to comment.