Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
TBD
==============

Features
--------
* "Eager" completions for the `source` command, limited to `*.sql` files.


Internal
--------
* Remove `align_decimals` preprocessor, which had no effect.
Expand Down
17 changes: 15 additions & 2 deletions mycli/packages/filepaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def list_path(root_dir: str) -> list[str]:
res = []
if os.path.isdir(root_dir):
for name in os.listdir(root_dir):
res.append(name)
if os.path.isdir(name):
res.append(f'{name}/')
# if .sql is too restrictive it can be made configurable with some effort
elif name.lower().endswith('.sql'):
res.append(name)
return res


Expand Down Expand Up @@ -69,7 +73,16 @@ def suggest_path(root_dir: str) -> list[str]:

"""
if not root_dir:
return [os.path.abspath(os.sep), "~", os.curdir, os.pardir]
return [
os.path.abspath(os.sep),
"~",
os.curdir,
os.pardir,
*list_path(os.curdir),
]

if root_dir[0] not in ('/', '~') and root_dir[0:1] != './':
return list_path(os.curdir)

if "~" in root_dir:
root_dir = os.path.expanduser(root_dir)
Expand Down
24 changes: 24 additions & 0 deletions test/test_smart_completion_public_schema_only.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# type: ignore

import os.path
from unittest.mock import patch

from prompt_toolkit.completion import Completion
Expand Down Expand Up @@ -589,3 +590,26 @@ def test_create_table_like_completion(completer, complete_event):
'time_zone_leap_second',
'time_zone_transition_type',
]


def test_source_eager_completion(completer, complete_event):
text = "source sc"
position = len(text)
script_filename = 'script_for_test_suite.sql'
f = open(script_filename, 'w')
f.close()
result = list(completer.get_completions(Document(text=text, cursor_position=position), complete_event))
success = True
error = 'unknown'
try:
assert [x.text for x in result] == [
'screenshots/',
script_filename,
]
except AssertionError as e:
success = False
error = e
if os.path.exists(script_filename):
os.remove(script_filename)
if not success:
raise AssertionError(error)