Skip to content

Commit

Permalink
completion bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Jan 27, 2018
1 parent 4ebe5cb commit f612489
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ci_tests:
BELTEST='Travis' py.test -rs --cov=./bel -c tests/pytest.ini --color=yes --durations=10 --flakes --pep8 tests

# Local virtualenv test runner with BEL.bio test environment
# add --pdb to get dropped into a debugging env
tests: clean_pyc
BELTEST='Local' py.test -x -rs --cov=./bel --cov-report html --cov-config .coveragerc -c tests/pytest.ini --color=yes --durations=10 --flakes --pep8 tests

Expand Down
9 changes: 5 additions & 4 deletions bel/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ def main():
main()

else:
if not os.getenv('READTHEDOCS', False):
config = load_configuration()
else:
log.info('READTHEDOCS environment')
# If building documents in readthedocs - provide empty config
if os.getenv('READTHEDOCS', False):
config = {}
log.info('READTHEDOCS environment')
else:
config = load_configuration()


# Ideas for providing hierarchical settings
Expand Down
24 changes: 17 additions & 7 deletions bel/lang/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def cursor(belstr: str, ast: AST, cursor_loc: int, result: Mapping[str, Any] = N
}

elif in_span(cursor_loc, arg['span']):
log.debug('In argument span {arg["span"]} Cursor_loc: {cursor_loc}')
log.debug(f'In argument span {arg["span"]} Cursor_loc: {cursor_loc}')
if arg['type'] == 'Function':
if in_span(cursor_loc, arg['function']['name_span']):
log.debug('Found replace_span in args: Function type')
Expand Down Expand Up @@ -142,7 +142,7 @@ def cursor(belstr: str, ast: AST, cursor_loc: int, result: Mapping[str, Any] = N
return result
elif arg['type'] == 'StrArg': # in case this is a default namespace StrArg
if arg['span'][0] == arg['span'][1]: # handle case like p() cursor=2
completion_text = ''
completion_text = belstr[arg['span'][0]:arg['span'][1] + 1]
else:
completion_text = belstr[arg['span'][0]:cursor_loc + 1]

Expand Down Expand Up @@ -232,7 +232,6 @@ def relation_completions(completion_text: str, bel_spec: BELSpec, bel_fmt: str,

matches = []
for r in relation_list:
print('R', r, 'C', completion_text)
if re.match(completion_text, r):
matches.append(r)

Expand Down Expand Up @@ -392,12 +391,23 @@ def add_completions(replace_list: list, belstr: str, replace_span: Span, complet
completions = []

for r in replace_list:
if '(' not in belstr:
replacement = f'{r["replacement"]}()'
cursor_loc = len(replacement) - 1 # inside parenthesis
elif r['type'] == 'Function' and replace_span[1] == len(belstr):

# if '(' not in belstr:
# replacement = f'{r["replacement"]}()'
# cursor_loc = len(replacement) - 1 # inside parenthesis
# elif r['type'] == 'Function' and replace_span[1] == len(belstr) - 1:

if len(belstr) > 0:
belstr_end = len(belstr) - 1
else:
belstr_end = 0

log.debug(f'Replace list {r} Replace_span {replace_span} BELstr: {belstr} Len: {belstr_end} Test1 {r["type"] == "Function"} Test2 {replace_span[1] + 1 == len(belstr)}')

if r['type'] == 'Function' and replace_span[1] >= belstr_end:
replacement = belstr[0:replace_span[0]] + f"{r['replacement']}()"
cursor_loc = len(replacement) - 1 # inside parenthesis
log.debug(f'Replacement: {replacement}')
else:
replacement = belstr[0:replace_span[0]] + r['replacement'] + belstr[replace_span[1] + 1:]
cursor_loc = len(belstr[0:replace_span[0]] + r['replacement']) # move cursor just past replacement
Expand Down
2 changes: 1 addition & 1 deletion bel/lang/partialparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def parse_args(bels: list, char_locs: CharLocs, parsed: Parsed, errors: Errors)
continue
sp, ep = parsed[span]['parens_span']
if ep == -1: # supports bel completion
function_end = len(bels) + 1
function_end = len(bels)
else:
function_end = ep

Expand Down
4 changes: 4 additions & 0 deletions tests/lang/test_canonicalize.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import bel.lang.belobj

from bel.Config import config
import bel.Config

print(bel.Config.get_belbio_conf_files())

print('Config', config)
bo = bel.lang.belobj.BEL(config['bel']['lang']['default_bel_version'], config['bel_api']['servers']['api_url'])

# TODO Add test for specified canonical_targets - need to make sure BEL.bio API endpoint is updated to handle this querystring arg
Expand Down

0 comments on commit f612489

Please sign in to comment.