Skip to content

Commit a247044

Browse files
committed
Autocomplete moved to separate class
1 parent fdc34fb commit a247044

File tree

2 files changed

+165
-157
lines changed

2 files changed

+165
-157
lines changed

export/WebTerminal/Autocomplete.xml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2015-12-20 13:40:54">
3+
<Class name="WebTerminal.Autocomplete">
4+
<Super>Common</Super>
5+
<TimeChanged>63906,49146.441893</TimeChanged>
6+
<TimeCreated>63906,49098.662696</TimeCreated>
7+
8+
<Method name="AutocompleteExists">
9+
<FormalSpec>namespace:%String</FormalSpec>
10+
<ReturnType>%Boolean</ReturnType>
11+
<Implementation><![CDATA[ quit $get(^%WebTerminal.Autocomplete(namespace)) '= ""
12+
]]></Implementation>
13+
</Method>
14+
15+
<Method name="GenerateAutocomplete">
16+
<Description>
17+
Generates autocomplete for namespace. Second parameter decides if
18+
it will be regenerated again. But if namespace equals to "%" - generates
19+
autocomplete for system classes. Make sure that autocomplete for
20+
system classes generates one time and forever.
21+
@param genSystem - Shows if system classes need to be generated. </Description>
22+
<FormalSpec>namespace:%String,genSystem:%Boolean</FormalSpec>
23+
<ReturnType>%String</ReturnType>
24+
<Implementation><![CDATA[
25+
set trueNs = $case(genSystem, 1:"%", :namespace)
26+
27+
do ..SendData("29", ..#ConstClientOutputLocalized)
28+
do ..SendData(" " _ trueNs _ $C(13, 10))
29+
30+
if ('##class(%SYS.Namespace).Exists(namespace)) {
31+
do ..SendData("30", ..#ConstClientOutputLocalized)
32+
do ..SendData(" " _ namespace _ $C(13, 10))
33+
quit $$$NOTOK
34+
}
35+
36+
// get all classes names
37+
set result = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary")
38+
do result.Execute()
39+
40+
/*
41+
The next COULD BE IMPROVED FOR SPEED, I beleive.
42+
Generates compressed JSON string of type:
43+
{
44+
"class": {
45+
"%ClassName1": {
46+
"methodName": 0,
47+
"propertyName": 0,
48+
"parameterName": 0,
49+
...
50+
},
51+
"ClassName2": {
52+
...
53+
}
54+
},
55+
"global": {
56+
"^%g1": 0,
57+
"^g2": 0
58+
}
59+
}
60+
*/
61+
62+
do ..SendData($C(13, 10))
63+
do ..SendData("32", ..#ConstClientOutputLocalized)
64+
65+
set ac = "{""class"":{" // string with autocomplete
66+
set first = ""
67+
set u = 1
68+
69+
while (result.Next()) { // forming autocomplete for each class
70+
71+
if (genSystem) '= ($Extract(result.Data("Name"), 1) = "%") {
72+
continue
73+
}
74+
75+
set className = result.Data("Name")
76+
77+
do ..SendData($C(27) _ "[30G" _ u)
78+
s u = u + 1
79+
80+
set ac = ac _ first _ """" _ className _ """:{"
81+
if (first = "") set first = ","
82+
83+
set cdefs = ##class(%Dictionary.ClassDefinition).%OpenId(className)
84+
85+
set countMethods = cdefs.Methods.Count()
86+
set countParameters = cdefs.Parameters.Count()
87+
set countProperties = cdefs.Properties.Count()
88+
set total = countMethods + countParameters + countProperties
89+
set current = 0
90+
91+
for i=1:1:countMethods {
92+
set current = current + 1
93+
set ac = ac _ """" _ cdefs.Methods.GetAt(i).Name _ """:0"
94+
if (current'=total) set ac = ac _ ","
95+
}
96+
97+
for i=1:1:countProperties {
98+
set current = current + 1
99+
set ac = ac _ """" _ cdefs.Properties.GetAt(i).Name _ """:0"
100+
if (current'=total) set ac = ac _ ","
101+
}
102+
103+
for i=1:1:countParameters {
104+
set current = current + 1
105+
set ac = ac _ """" _ cdefs.Parameters.GetAt(i).Name _ """:0"
106+
if (current'=total) set ac = ac _ ","
107+
}
108+
109+
set ac = ac _ "}"
110+
111+
}
112+
113+
set ac = ac _ "}"
114+
if ('genSystem) set ac = ac _ ",""global"":" _ ..getGlobalsJSON()
115+
set ac = ac _ "}"
116+
117+
set ^%WebTerminal.Autocomplete(trueNs) = ac
118+
119+
do ..SendData($C(13, 10))
120+
do ..SendData("33", ..#ConstClientOutputLocalized)
121+
do ..SendData($C(13, 10))
122+
//do ..SendData(namespace, ..#ConstClientLoadAutocomplete)
123+
124+
quit $$$OK
125+
]]></Implementation>
126+
</Method>
127+
128+
<Method name="Reset">
129+
<Description>
130+
Returns terminal to default state</Description>
131+
<ClassMethod>1</ClassMethod>
132+
<ReturnType>%Status</ReturnType>
133+
<Implementation><![CDATA[
134+
// delete autocompletion files
135+
kill ^%WebTerminal.Autocomplete
136+
quit $$$OK
137+
]]></Implementation>
138+
</Method>
139+
140+
<Method name="getGlobalsJSON">
141+
<ClassMethod>1</ClassMethod>
142+
<FormalSpec>namespace:%String</FormalSpec>
143+
<ReturnType>%String</ReturnType>
144+
<Implementation><![CDATA[
145+
146+
set out = "{"
147+
set rset=##class(%ResultSet).%New("%SYS.GlobalQuery:NameSpaceList")
148+
set sc=rset.Execute($ZNSPACE,"*",0)
149+
while (rset.Next()) {
150+
set out = out _ """" _ $Piece(rset.GetData(1),"(",1) _ """:0,"
151+
}
152+
set out = $EXTRACT(out,1,$LENGTH(out)-1) _ "}"
153+
154+
// todo:
155+
// Set Rset = ##class(%Library.ResultSet).%New("%SYS.GlobalQuery:NameSpaceListChui")
156+
// s Status=Rset.Execute(NameSpace,Mask,SystemGlobals,.UnavailableDatabases)
157+
158+
q out
159+
]]></Implementation>
160+
</Method>
161+
</Class>
162+
</Export>

export/WebTerminal/Engine.xml

Lines changed: 3 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2015-12-20 11:26:48">
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2015-12-20 13:41:12">
33
<Class name="WebTerminal.Engine">
44
<Description>
55
Cache WEB Terminal version X.X.X/*build.replace:pkg.version*/ core.
66
This class is the server-side core of the terminal application.</Description>
7-
<Super>%CSP.WebSocket,Common,Trace</Super>
8-
<TimeChanged>63906,40862.530498</TimeChanged>
7+
<Super>%CSP.WebSocket,Trace,Autocomplete</Super>
8+
<TimeChanged>63906,49223.903226</TimeChanged>
99
<TimeCreated>63891,56786.028532</TimeCreated>
1010

1111
<Property name="SharedConnection">
@@ -279,160 +279,6 @@ rchr(timeout = 86400, data)
279279
]]></Implementation>
280280
</Method>
281281

282-
<Method name="getGlobalsJSON">
283-
<ClassMethod>1</ClassMethod>
284-
<FormalSpec>namespace:%String</FormalSpec>
285-
<ReturnType>%String</ReturnType>
286-
<Implementation><![CDATA[
287-
288-
set out = "{"
289-
set rset=##class(%ResultSet).%New("%SYS.GlobalQuery:NameSpaceList")
290-
set sc=rset.Execute($ZNSPACE,"*",0)
291-
while (rset.Next()) {
292-
set out = out _ """" _ $Piece(rset.GetData(1),"(",1) _ """:0,"
293-
}
294-
set out = $EXTRACT(out,1,$LENGTH(out)-1) _ "}"
295-
296-
// todo:
297-
// Set Rset = ##class(%Library.ResultSet).%New("%SYS.GlobalQuery:NameSpaceListChui")
298-
// s Status=Rset.Execute(NameSpace,Mask,SystemGlobals,.UnavailableDatabases)
299-
300-
q out
301-
]]></Implementation>
302-
</Method>
303-
304-
<Method name="AutocompleteExists">
305-
<FormalSpec>namespace:%String</FormalSpec>
306-
<ReturnType>%Boolean</ReturnType>
307-
<Implementation><![CDATA[ quit $get(^%WebTerminal.Autocomplete(namespace)) '= ""
308-
]]></Implementation>
309-
</Method>
310-
311-
<Method name="GenerateAutocomplete">
312-
<Description>
313-
Generates autocomplete for namespace. Second parameter decides if
314-
it will be regenerated again. But if namespace equals to "%" - generates
315-
autocomplete for system classes. Make sure that autocomplete for
316-
system classes generates one time and forever.
317-
@param genSystem - Shows if system classes need to be generated. </Description>
318-
<FormalSpec>namespace:%String,genSystem:%Boolean</FormalSpec>
319-
<ReturnType>%String</ReturnType>
320-
<Implementation><![CDATA[
321-
set trueNs = $case(genSystem, 1:"%", :namespace)
322-
323-
do ..SendData("29", ..#ConstClientOutputLocalized)
324-
do ..SendData(" " _ trueNs _ $C(13, 10))
325-
326-
if ('##class(%SYS.Namespace).Exists(namespace)) {
327-
do ..SendData("30", ..#ConstClientOutputLocalized)
328-
do ..SendData(" " _ namespace _ $C(13, 10))
329-
quit $$$NOTOK
330-
}
331-
332-
// get all classes names
333-
set result = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary")
334-
do result.Execute()
335-
336-
/*
337-
The next COULD BE IMPROVED FOR SPEED, I beleive.
338-
Generates compressed JSON string of type:
339-
{
340-
"class": {
341-
"%ClassName1": {
342-
"methodName": 0,
343-
"propertyName": 0,
344-
"parameterName": 0,
345-
...
346-
},
347-
"ClassName2": {
348-
...
349-
}
350-
},
351-
"global": {
352-
"^%g1": 0,
353-
"^g2": 0
354-
}
355-
}
356-
*/
357-
358-
do ..SendData($C(13, 10))
359-
do ..SendData("32", ..#ConstClientOutputLocalized)
360-
361-
set ac = "{""class"":{" // string with autocomplete
362-
set first = ""
363-
set u = 1
364-
365-
while (result.Next()) { // forming autocomplete for each class
366-
367-
if (genSystem) '= ($Extract(result.Data("Name"), 1) = "%") {
368-
continue
369-
}
370-
371-
set className = result.Data("Name")
372-
373-
do ..SendData($C(27) _ "[30G" _ u)
374-
s u = u + 1
375-
376-
set ac = ac _ first _ """" _ className _ """:{"
377-
if (first = "") set first = ","
378-
379-
set cdefs = ##class(%Dictionary.ClassDefinition).%OpenId(className)
380-
381-
set countMethods = cdefs.Methods.Count()
382-
set countParameters = cdefs.Parameters.Count()
383-
set countProperties = cdefs.Properties.Count()
384-
set total = countMethods + countParameters + countProperties
385-
set current = 0
386-
387-
for i=1:1:countMethods {
388-
set current = current + 1
389-
set ac = ac _ """" _ cdefs.Methods.GetAt(i).Name _ """:0"
390-
if (current'=total) set ac = ac _ ","
391-
}
392-
393-
for i=1:1:countProperties {
394-
set current = current + 1
395-
set ac = ac _ """" _ cdefs.Properties.GetAt(i).Name _ """:0"
396-
if (current'=total) set ac = ac _ ","
397-
}
398-
399-
for i=1:1:countParameters {
400-
set current = current + 1
401-
set ac = ac _ """" _ cdefs.Parameters.GetAt(i).Name _ """:0"
402-
if (current'=total) set ac = ac _ ","
403-
}
404-
405-
set ac = ac _ "}"
406-
407-
}
408-
409-
set ac = ac _ "}"
410-
if ('genSystem) set ac = ac _ ",""global"":" _ ..getGlobalsJSON()
411-
set ac = ac _ "}"
412-
413-
set ^%WebTerminal.Autocomplete(trueNs) = ac
414-
415-
do ..SendData($C(13, 10))
416-
do ..SendData("33", ..#ConstClientOutputLocalized)
417-
do ..SendData($C(13, 10))
418-
//do ..SendData(namespace, ..#ConstClientLoadAutocomplete)
419-
420-
quit $$$OK
421-
]]></Implementation>
422-
</Method>
423-
424-
<Method name="Reset">
425-
<Description>
426-
Returns terminal to default state</Description>
427-
<ClassMethod>1</ClassMethod>
428-
<ReturnType>%Status</ReturnType>
429-
<Implementation><![CDATA[
430-
// delete autocompletion files
431-
kill ^%WebTerminal.Autocomplete
432-
quit $$$OK
433-
]]></Implementation>
434-
</Method>
435-
436282
<Method name="SendData">
437283
<Description>
438284
Function sends data derectly to server with specified action</Description>

0 commit comments

Comments
 (0)