Skip to content

Commit

Permalink
🐛 version 1.7.38
Browse files Browse the repository at this point in the history
fix comp session
  • Loading branch information
RF-Tar-Railt committed Nov 23, 2023
1 parent 8b58b9b commit 7da58a3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# 更新日志

## Alconna 1.7.38

### 修复

- 修复 `command_manager.dump`
- 修复 `CompSession` 在执行过程中受到其他命令解析干扰的问题

## Alconna 1.7.37

### 改进
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from .typing import UnpackVar as UnpackVar
from .typing import Up as Up

__version__ = "1.7.37"
__version__ = "1.7.38"

# backward compatibility
Arpamar = Arparma
Expand Down
4 changes: 2 additions & 2 deletions src/arclet/alconna/_internal/_analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def process(self, argv: Argv[TDC]) -> Arparma[TDC]:
else:
exc = ArgumentMissing(lang.require("analyser", "param_missing"))
if comp_ctx.get(None) and isinstance(exc, ArgumentMissing):
raise PauseTriggered(prompt(self, argv), exc)
raise PauseTriggered(prompt(self, argv), exc, argv)
if self.command.meta.raise_exception:
raise exc
return self.export(argv, True, exc)
Expand All @@ -382,7 +382,7 @@ def analyse(self, argv: Argv[TDC]) -> Arparma[TDC] | None:
if comp_ctx.get(None):
if isinstance(e1, InvalidParam):
argv.free(argv.context.separators if argv.context else None)
raise PauseTriggered(prompt(self, argv), e1) from e1
raise PauseTriggered(prompt(self, argv), e1, argv) from e1
if self.command.meta.raise_exception:
raise
return self.export(argv, True, e1)
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/_internal/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def handle_completion(analyser: Analyser, argv: Argv, trigger: str | None = None
"""处理补全选项触发"""
if res := prompt(analyser, argv, trigger):
if comp_ctx.get(None):
raise PauseTriggered(res, trigger)
raise PauseTriggered(res, trigger, argv)
prompt_other = lang.require("completion", "prompt_other")
node = lang.require('completion', 'node')
node = f"{node}\n" if node else ""
Expand Down
20 changes: 16 additions & 4 deletions src/arclet/alconna/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def __init__(self, source: Alconna):
self.trigger = None
self._token = None

self.raw_data = []
self.bak_data = []
self.current_index = 0

@property
def available(self):
"""表示当前补全会话是否可用。"""
Expand Down Expand Up @@ -108,7 +112,9 @@ def enter(self, content: list | None = None) -> EnterResult:
ValueError: 当前没有可用的补全选项, 或者当前补全选项不可用。
"""
argv = command_manager.resolve(self.source.command)
_b, _r, _i, _n = argv.bak_data.copy(), argv.raw_data.copy(), argv.current_index, argv.ndata
argv.raw_data = self.raw_data.copy()
argv.bak_data = self.bak_data.copy()
argv.current_index = self.current_index
if content:
input_ = content
else:
Expand All @@ -122,9 +128,9 @@ def enter(self, content: list | None = None) -> EnterResult:
argv.next(move=True)
input_ = [prompt.text]
if isinstance(self.trigger, InvalidParam):
argv.raw_data = argv.bak_data[: max(_i, 1)]
argv.raw_data = argv.bak_data[: max(self.current_index, 1)]
argv.addon(input_)
argv.raw_data.extend(_r[max(_i, 1) :])
argv.raw_data.extend(self.raw_data[max(self.current_index, 1) :])
else:
argv.raw_data = argv.bak_data.copy()
argv.addon(input_)
Expand All @@ -149,7 +155,6 @@ def enter(self, content: list | None = None) -> EnterResult:
if isinstance(exc, PauseTriggered):
self.fresh(exc)
return EnterResult(exception=self.trigger if isinstance(self.trigger, InvalidParam) else None)
argv.bak_data, argv.raw_data, argv.current_index, argv.ndata = _b, _r, _i, _n
return EnterResult(exception=exc)
self.exit()
return EnterResult(res) # noqa # type: ignore
Expand All @@ -171,6 +176,9 @@ def clear(self):
self.index = 0
self.prompts.clear()
self.source.reset()
self.raw_data = []
self.bak_data = []
self.current_index = 0
return self

def exit(self):
Expand Down Expand Up @@ -214,6 +222,10 @@ def fresh(self, exc: PauseTriggered):
self.clear()
self.push(*exc.args[0])
self.trigger = exc.args[1]
argv = exc.args[2]
self.raw_data = argv.raw_data
self.bak_data = argv.bak_data
self.current_index = argv.current_index
return True


Expand Down
9 changes: 8 additions & 1 deletion src/arclet/alconna/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ def load_cache(self) -> None:

def dump_cache(self) -> None:
"""保存缓存"""
data = {}
for key, short in self.__shortcuts.items():
if isinstance(short, dict):
data[key] = {k: v for k, v in short.items() if k != "wrapper"}
else:
data[key] = short
with shelve.open(self.cache_path) as db:
db["shortcuts"] = self.__shortcuts
db["shortcuts"] = data
data.clear()

@property
def get_loaded_namespaces(self):
Expand Down

0 comments on commit 7da58a3

Please sign in to comment.