1
Fork 0
mirror of https://github.com/j1g5awi/krunner-vscode.git synced 2024-11-21 22:49:31 +00:00

Only return paths which exist

This commit is contained in:
Jake Howard 2023-05-16 21:33:04 +01:00
parent d1f3e15b0a
commit 5d431b2708
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -24,6 +24,8 @@ VSCODE_DIRS = [
"VSCodium" "VSCodium"
] ]
HOME = str(Path.home())
class Match(NamedTuple): class Match(NamedTuple):
data: str data: str
@ -68,12 +70,20 @@ def get_path_list():
) )
data = json.loads(rows.fetchone()[0]) data = json.loads(rows.fetchone()[0])
con.close() con.close()
paths.update(
{ for entry in data["entries"]:
"~" + path[len(os.environ["HOME"]) :] if os.environ["HOME"] in path else path if "folderUri" not in entry:
for path in [i["folderUri"][7:] for i in data["entries"] if "folderUri" in i] continue
}
) path = entry["folderUri"].replace("file://", "")
if not os.path.exists(path):
continue
if path.startswith(HOME):
path = path.replace(HOME, "~", 1)
paths.add(path)
return paths return paths
@ -90,8 +100,6 @@ class Runner(dbus.service.Object):
@dbus.service.method(iface, in_signature="s", out_signature="a(sssida{sv})") @dbus.service.method(iface, in_signature="s", out_signature="a(sssida{sv})")
def Match(self, query: str): def Match(self, query: str):
# data, display text, icon, type (Plasma::QueryType), relevance (0-1), properties (subtext, category and urls) # data, display text, icon, type (Plasma::QueryType), relevance (0-1), properties (subtext, category and urls)
matches = get_matches(get_path_list(), query)
return [ return [
Match( Match(
path, path,
@ -101,7 +109,7 @@ class Runner(dbus.service.Object):
ratio, ratio,
{"subtext": path}, {"subtext": path},
) )
for ratio, path in matches for ratio, path in get_matches(get_path_list(), query)
] ]
@dbus.service.method(iface, out_signature="a(sss)") @dbus.service.method(iface, out_signature="a(sss)")