forked from fuse-open/sublime-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuse_parseutils.py
63 lines (50 loc) · 1.46 KB
/
fuse_parseutils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def trimType(typeDesc):
return typeDesc.rpartition(".")[2]
# Parse a method or constructor into tab completion text, type hint and verbose hint
def parseMethod(access, methodName, args, returntype, asCtor):
verboseHintText = " ".join(access)
methodText = methodName+"("
if asCtor:
typeHint = "Class ("
else:
typeHint = "("
count = 1
for arg in args:
if type(arg) is str:
break
if count>1:
methodText += ", "
typeHint += ", "
argName = arg["Name"]
if arg["IsOut"]:
methodText += "out ${" + str(count) + ":" + argName + "}"
typeHint += "out "
else:
methodText += "${" + str(count) + ":" + argName + "}"
typeHint += trimType(arg["ArgType"]) + " " + argName
count += 1
if asCtor:
typeHint += ")"
else:
typeHint += "):" + trimType(returntype)
methodText += ")"
return (methodText, typeHint, verboseHintText)
def parseUXSuggestion(wordAtCaret, suggestion, suggestedUXNameSpaces, useShortCompletion, foldUXNameSpaces):
isNs = False
outText = suggestion["Suggestion"]
hintText = suggestion["ReturnType"]
if foldUXNameSpaces and wordAtCaret != ":":
colonIdx = outText.find(":") + 1
if colonIdx > 0:
nsname = outText[0:colonIdx]
hinted = nsname in suggestedUXNameSpaces
isNs = True
if not hinted:
suggestedUXNameSpaces.append(nsname)
outText = nsname
hintText = nsname[0:len(nsname)-1]
else:
return None
if not isNs and (not useShortCompletion):
hintText += '="${1}"'
return (outText, hintText)