from nbstata.config import launch_stata
from nbstata.stata_more import run_sfi
completions
Autocomplete functionality
Adapted from the stata_kernel version.
CompletionsManager
CompletionsManager (stata_session:nbstata.stata_session.StataSession)
CompletionsManager.get_globals
CompletionsManager.get_globals ()
CompletionsManager.get_file_paths
CompletionsManager.get_file_paths (chunk)
Get file paths based on chunk Args: chunk (str): chunk of text after last space. Doesn’t include string punctuation characters Returns: (List[str]): folders and files at that location
=False)
launch_stata(splash= StataSession()
test_stata = CompletionsManager(test_stata)
test_instance "0") test_instance.get_file_paths(
['00_misc_utils.ipynb',
'01_config.ipynb',
'02_stata.ipynb',
'03_stata_more.ipynb',
'04_code_utils.ipynb',
'05_noecho.ipynb',
'06_pandas.ipynb',
'07_browse.ipynb',
'08_stata_session.ipynb',
'09_magics.ipynb']
'global in_path "../nbstata"')
run_sfi(
test_instance.stata_session.refresh_suggestions()"$in_path/com") test_instance.get_file_paths(
['$in_path/completion_env.py', '$in_path/completions.py']
CompletionsManager.get
CompletionsManager.get (starts, env, rcomp)
Return environment-aware completions list.
CompletionsManager.do
CompletionsManager.do (code, cursor_pos)
from fastcore.test import test_eq
def completions_test_setup(code):
global test_instance
"clear all")
run_sfi(
run_sfi(code)
test_instance.stata_session.clear_suggestions()
def _complete(code, cursor_pos):
= test_instance.do(code, cursor_pos)
_, _, matches return matches
"gen var1 = 1")
completions_test_setup(= "list va"
code = 7
cursor_pos
test_eq(
test_instance.env_helper.get_env(+ 2)],
code[:cursor_pos], code[cursor_pos:(cursor_pos False),
0, 5, 'va', ''),
(
)
test_eq(
_complete(code, cursor_pos),'var1'],
[ )
'local test_local "test value"')
completions_test_setup(
test_eq("list `t", 7),
_complete("test_local'"],
[
)'local test_local ""') run_sfi(
'global test_global "test value"')
completions_test_setup(
test_eq("list ${tes}", 10),
_complete('test_global'],
[ )