Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Improve autocompletion #230

Merged
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
42 changes: 31 additions & 11 deletions kuksa_viss_client/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@
class TestClient(Cmd):
def get_childtree(self, pathText):
childVssTree = self.vssTree
if "." in pathText:

paths = [pathText]
if "/" in pathText:
paths = pathText.split("/")
elif "." in pathText:
paths = pathText.split(".")
for path in paths[:-1]:
if path in childVssTree:
childVssTree = childVssTree[path]
elif 'children' in childVssTree and path in childVssTree['children']:
childVssTree = childVssTree['children'][path]
if 'children' in childVssTree:

for path in paths[:-1]:
if path in childVssTree:
childVssTree = childVssTree[path]
elif 'children' in childVssTree and path in childVssTree['children']:
childVssTree = childVssTree['children'][path]

if 'children' in childVssTree:
childVssTree = childVssTree['children']
return childVssTree

Expand All @@ -49,17 +55,31 @@ def path_completer(self, text, line, begidx, endidx):
self.pathCompletionItems = []
childTree = self.get_childtree(text)
prefix = ""
if "." in text:
seperator="/"

if "/" in text:
prefix = text[:text.rfind("/")]+"/"
elif "." in text:
prefix = text[:text.rfind(".")]+"."
seperator="."

for key in childTree:
child = childTree[key]
if isinstance(child, dict):
description = ""
nodetype = "unknown"

if 'description' in child:
description = "("+child['description']+")"
self.pathCompletionItems.append(CompletionItem(prefix + key, description))
description = child['description']

if 'type' in child:
nodetype=child['type'].capitalize()

self.pathCompletionItems.append(CompletionItem(prefix + key, nodetype+": "+ description))

if 'children' in child:
self.pathCompletionItems.append(CompletionItem(prefix + key + ".", "(children...)"))
self.pathCompletionItems.append(CompletionItem(prefix + key+seperator, "Children of branch "+prefix+key))


return basic_complete(text, line, begidx, endidx, self.pathCompletionItems)

Expand Down