Use command parser for completions

This commit is contained in:
Florian Bruhin 2014-04-09 06:58:17 +02:00
parent 1258a466dd
commit deb286272c
2 changed files with 15 additions and 4 deletions

View File

@ -129,7 +129,7 @@ class CommandParser(QObject):
self._cmd = None
self._args = []
def _parse(self, text, aliases=True):
def parse(self, text, aliases=True):
"""Split the commandline text into command and arguments.
Args:
@ -139,6 +139,9 @@ class CommandParser(QObject):
Raise:
NoSuchCommandError if a command wasn't found.
Return:
The parts list.
"""
parts = text.strip().split(maxsplit=1)
if not parts:
@ -150,7 +153,7 @@ class CommandParser(QObject):
except KeyError:
pass
else:
return self._parse(alias, aliases=False)
return self.parse(alias, aliases=False)
try:
cmd = cmdutils.cmd_dict[cmdstr]
except KeyError:
@ -164,6 +167,7 @@ class CommandParser(QObject):
args = [parts[1]]
self._cmd = cmd
self._args = args
return parts
def _check(self):
"""Check if the argument count for the command is correct."""
@ -211,7 +215,7 @@ class CommandParser(QObject):
retvals.append(self.run(sub, count, ignore_exc))
return all(retvals)
try:
self._parse(text)
self.parse(text)
self._check()
except ArgumentCountError:
if ignore_exc:

View File

@ -34,6 +34,8 @@ from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption,
import qutebrowser.config.config as config
import qutebrowser.commands.utils as cmdutils
from qutebrowser.commands.parsers import CommandParser
from qutebrowser.commands.exceptions import NoSuchCommandError
from qutebrowser.config.style import get_stylesheet
from qutebrowser.models.completionfilter import CompletionFilterModel
from qutebrowser.models.commandcompletion import CommandCompletionModel
@ -218,7 +220,12 @@ class CompletionView(QTreeView):
return
text = text.lstrip(':')
parts = text.split(' ') # FIXME what about commands which use shutil?
parser = CommandParser()
try:
parts = parser.parse(text)
except NoSuchCommandError:
parts = text.split(' ')
logging.debug("parts: {}".format(parts))
model = self._get_new_completion(parts)
if model != self._lastmodel: