Skip to content

Commit

Permalink
Show current directory in open file placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
millerdev committed Jan 12, 2021
1 parent 3129b9a commit df5ff0e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Add support for custom keybindings with arguments.
- Limit `ag` result item length to 150 as well as the maximum number of results
to 200.
- Show current directory in open file placeholder
- Log errors to PyXT output channel in VS Code.


Expand Down
4 changes: 3 additions & 1 deletion pyxt/cmd/tests/test_openfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ async def test(cmdstr, expect):
eq(result["type"], "success", result)
eq(normalize_path(result["value"], base), expect)
else:
if "placeholder" in result:
result["placeholder"] = result["placeholder"].replace(base, "/base")
normalize_paths(result["items"], base)
eq(result, expect)

Expand All @@ -28,7 +30,7 @@ async def test(cmdstr, expect):
yield test, "open ", result([
{"label": "dir/", "offset": 5},
{"label": "file.txt", "filepath": "/file.txt", "offset": 5},
], value="open ", no_history=True)
], value="open ", placeholder="open /base", no_history=True)
yield test, "open dir", result([
{"label": "dir/", "offset": 5},
], value="open dir", no_history=True)
Expand Down
12 changes: 8 additions & 4 deletions pyxt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,14 @@ def match(n):
return CompletionsList(names, title=user_path(root))

async def get_placeholder(self, arg):
if not arg and isinstance(self.default, str):
if arg.defaulted:
return user_path(self.default), ""
return "", user_path(self.default)
if not arg:
if isinstance(self.default, str):
if arg.defaulted:
return user_path(self.default), ""
return "", user_path(self.default)
path = await self.path
if path:
return "", user_path(path)
return await super().get_placeholder(arg)

async def arg_string(self, value):
Expand Down
4 changes: 4 additions & 0 deletions pyxt/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ async def _get_completions(command, parser, input_value, argstr):
"description": hint,
"offset": 0,
})
elif not argstr:
args, hint = await parser.get_placeholder(argstr)
if hint:
options["placeholder"] = input_value + hint
if not command.has_history:
options["no_history"] = True
return result(items, input_value, **options)
Expand Down
4 changes: 2 additions & 2 deletions pyxt/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ async def test(input_value, expected_result):
eq(res, expected_result)

yield test, "cm", result([item("cmd ", 0, is_completion=True)], "cm")
yield test, "cmd", result([item("a", 4), item("b", 4)], "cmd ")
yield test, "cmd ", result([item("a", 4), item("b", 4)], "cmd ")
yield test, "cmd", result([item("a", 4), item("b", 4)], "cmd ", placeholder="cmd a")
yield test, "cmd ", result([item("a", 4), item("b", 4)], "cmd ", placeholder="cmd a")
yield test, "cmd a", result([item("a", 4)], "cmd a")


Expand Down

0 comments on commit df5ff0e

Please sign in to comment.