Skip to content

Commit 30c10bc

Browse files
autocomplete logic rebuild - faster, easier
1 parent 3ced08f commit 30c10bc

File tree

5 files changed

+89
-43
lines changed

5 files changed

+89
-43
lines changed

%WebTerminal/Engine.cls.xml

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,32 @@ This method watches only for tail of global and detects if global still alive</D
416416
<Method name="GenerateAutocompleteFile">
417417
<Description>
418418
Generates autocomplete file for namespace. Second parameter deсides if
419-
it will be regenerated again </Description>
419+
it will be regenerated again. But if namespace equals to "%" - generates
420+
autocomplete file for system classes. Make sure that autocomplete for
421+
system classes generates one time and forever. </Description>
420422
<FormalSpec>namespace:%String,newFile:%Boolean</FormalSpec>
421423
<ReturnType>%String</ReturnType>
422424
<Implementation><![CDATA[
425+
423426
set filename = ..GetJSAutocompleteFilePath($NAMESPACE)
424427
428+
set system = 0
429+
if (namespace = "%") {
430+
set namespace = "%SYS"
431+
set filename = ..GetJSAutocompleteFilePath("_")
432+
set system = 1
433+
}
434+
435+
if (system) && (##class(%File).Exists(filename)) {
436+
do ..SendData("_", ..ConstClientLoadAutocomplete)
437+
quit $$$OK
438+
}
439+
425440
do ..StartClearIO()
426441
427-
if ('##class(%SYS.Namespace).Exists($REPLACE(namespace,"_","%"))) {
442+
if ('##class(%SYS.Namespace).Exists(namespace)) {
428443
do ..EndClearIO()
429-
do ..SendData("Wrong namespace name: " _ namespace)
444+
do ..SendData("Wrong namespace: " _ namespace)
430445
quit $$$NOTOK
431446
}
432447
@@ -449,15 +464,12 @@ it will be regenerated again </Description>
449464
quit $$$OK
450465
}
451466
452-
set filename = ..GetJSAutocompleteFilePath(namespace)
453-
454467
}
455468
456-
do ..SendData("Generating language file for " _ namespace _ ", pleace, wait.")
457-
458-
// write empty file in case of other terminal applications may require it
459-
//do ..WriteToFile(filename,"{}")
460-
469+
set thisName = $REPLACE(namespace,"_","%")
470+
if (system) { set thisName = "SYSTEM" }
471+
do ..SendData("Generating language file for " _ thisName _ ", pleace, wait. ")
472+
461473
// get all classes names
462474
set result = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary")
463475
do result.Execute()
@@ -466,14 +478,20 @@ it will be regenerated again </Description>
466478
The next COULD BE IMPROVED FOR SPEED, I beleive.
467479
Generates compressed JSON string of type:
468480
{
469-
"%ClassName1": {
470-
"methodName": 0,
471-
"propertyName": 0,
472-
"parameterName": 0,
473-
...
481+
"class": {
482+
"%ClassName1": {
483+
"methodName": 0,
484+
"propertyName": 0,
485+
"parameterName": 0,
486+
...
487+
},
488+
"ClassName2": {
489+
...
490+
}
474491
},
475-
"ClassName2": {
476-
...
492+
"global": {
493+
"^%g1": 0,
494+
"^g2": 0
477495
}
478496
}
479497
*/
@@ -488,6 +506,9 @@ it will be regenerated again </Description>
488506
while (result.Next()) { // forming autocomplete for each class
489507
490508
set className = result.Data("Name")
509+
if (($EXTRACT(className,1)="%")'=system) {
510+
continue
511+
}
491512
do file.Write(first _ """" _ className _ """:{")
492513
if (first = "") set first = ","
493514
@@ -501,36 +522,39 @@ it will be regenerated again </Description>
501522
502523
for i=1:1:countMethods {
503524
set current = current + 1
504-
do file.Write("""" _cdefs.Methods.GetAt(i).Name _ """:0")
525+
do file.Write("""" _ cdefs.Methods.GetAt(i).Name _ """:0")
505526
if (current'=total) do file.Write(",")
506527
}
507528
508529
for i=1:1:countProperties {
509530
set current = current + 1
510-
do file.Write("""" _cdefs.Properties.GetAt(i).Name _ """:0")
531+
do file.Write("""" _ cdefs.Properties.GetAt(i).Name _ """:0")
511532
if (current'=total) do file.Write(",")
512533
}
513534
514535
for i=1:1:countParameters {
515536
set current = current + 1
516-
do file.Write("""" _cdefs.Parameters.GetAt(i).Name _ """:0")
537+
do file.Write("""" _ cdefs.Parameters.GetAt(i).Name _ """:0")
517538
if (current'=total) do file.Write(",")
518539
}
519540
520541
do file.Write("}")
521542
522543
}
523544
524-
do file.Write("},""global"":" _ ..getGlobalsJSON() _"}")
525-
545+
do file.Write("}")
546+
if ('system) {
547+
do file.Write(",""global"":" _ ..getGlobalsJSON())
548+
}
549+
do file.Write("}")
526550
do file.Close()
527-
//do ..WriteToFile(filename,data)
528551
529-
do ..SendData($c(10)_"Language file for " _ namespace _ " classes created.")
552+
do ..SendData($c(10)_"Language file for " _ thisName _ " generated.")
530553
531554
do ..EndClearIO()
532-
533-
do ..SendData(namespace,..ConstClientLoadAutocomplete)
555+
if (system) {
556+
do ..SendData("_",..ConstClientLoadAutocomplete)
557+
} else { do ..SendData(namespace,..ConstClientLoadAutocomplete) }
534558
535559
quit $$$OK
536560
]]></Implementation>
@@ -759,10 +783,10 @@ Method description:
759783
760784
set result = ..AddWatch(data)
761785
if ('$$$ISOK(result)) {
762-
set result = ..RemoveWatch(data)
763-
if ('$$$ISOK(result)) {
764-
do ..SendData("unreal", ..ConstClientWatch)
765-
}
786+
set result = ..RemoveWatch(data)
787+
if ('$$$ISOK(result)) {
788+
do ..SendData("unreal", ..ConstClientWatch)
789+
}
766790
}
767791
768792
} elseif (action = ..ConstServerActionExecuteSQL) { // sql
@@ -771,6 +795,7 @@ Method description:
771795
772796
} elseif (action = ..ConstServerActionGenerateAutocomplete) {
773797
798+
do ..GenerateAutocompleteFile("%", data)
774799
do ..GenerateAutocompleteFile(..CurrentNamespace, data)
775800
776801
} elseif (action = ..ConstServerActionReset) {

csp/webTerminal/index.csp.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</label>
8989
</td>
9090
<td>
91-
Saves your history and autocompletion automatically after browser tab closed
91+
Saves your history, favorites, definitions and autocompletion automatically after browser tab closed and loads it later.
9292
</td>
9393
</tr>
9494
<tr>

csp/webTerminal/js/application.js.xml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
var application = new function() {
88
9-
var version = "0.9.6.8 beta";
9+
var version = "0.9.6.9 beta";
1010
this.debug = false; // remove for release
1111
1212
this.browser = "gc";
@@ -17,7 +17,7 @@ var application = new function() {
1717
*
1818
* 1. Add theme name to the list below;
1919
* 2. Make CSS theme file like theme-default.css;
20-
* 3. Place this file to /css/ directory and name it "theme-<name>.css";
20+
* 3. Place this file to /css/ directory and name it "theme-<name_of_your_theme>.css";
2121
* 4. Check theme in settings and use it!
2222
*
2323
* We're waiting for your cool themes ;)
@@ -39,14 +39,22 @@ var application = new function() {
3939
"</div>" +
4040
"<div class=\"center\">" +
4141
"<span class=\"syntax-_comment\">Global client command syntax</span><br>" +
42-
"<span class=\"syntax-_client\">/{command} {argument1} \"{argument2}\" ...</span><br>" +
42+
"a r <span class=\"syntax-_string\">\"g u\"</span> m e n t №0 <span class=\"syntax-_client\">/{command}</span>" +
43+
" argument1 <span class=\"syntax-_string\">\"argument2\"</span> ...<br>" +
4344
"</div>" +
4445
"<div>" +
45-
"Examples:<br>" +
46+
"Some examples:<br>" +
4647
"<span class=\"syntax-_client\">/define</span> &1 <span class=\"syntax-_string\">\"##class(%File)\"" +
4748
"</span> <span class=\"syntax-_comment\"> To use something like &1.Exists(\"Name\")</span><br>" +
4849
"<span class=\"syntax-_client\">/tail</span> <span class=\"syntax-_global\">^MyGlobal</span> " +
49-
"<span class=\"syntax-_comment\">To watch for global changes.</span><br>&nbsp;" +
50+
"<span class=\"syntax-_comment\">To watch for global changes.</span><br>" +
51+
"<span class=\"syntax-_command\">do</span> <span class=\"syntax-_sysMacro\">##class</span><span class=\"" +
52+
"syntax-_bracket\">(</span><span class=\"syntax-mysuperapplication\">MySuperApplication</span><span cla" +
53+
"ss=\"syntax-_other\">.MySuperClass</span><span class=\"syntax-_bracket\">)</span><span class=\"syntax-" +
54+
"_other\">.MySuperMethod</span><span class=\"syntax-_bracket\">(</span><span class=\"syntax-mysuperargu" +
55+
"ments\">MySuperArguments</span><span class=\"syntax-_bracket\">)</span> <span class=\"syntax-_client\"" +
56+
">/favorite</span> <span class=\"syntax-_other\">1</span> " +
57+
"<span class=\"syntax-_comment\">To save code before command into favorite slot 1.</span><br>&nbsp;" +
5058
"</div>" +
5159
"<table>" +
5260
"<tr>" +
@@ -116,8 +124,10 @@ var application = new function() {
116124
"<td class=\"info\">/autocomplete [new]</td>" +
117125
"<td>" +
118126
"Load all class definitions for current namespace. This may take a while depending on your " +
119-
"system settings. Normally it takes 20-30 seconds for first execution. Next executions will" +
120-
" only load already generated file. If new parameter given, file will be regenerated." +
127+
"system settings. Normally it takes 20-30 seconds for first execution. Next executions will " +
128+
"load already generated files or generate only namespace-specific language while new parameter given." +
129+
"To regenerate system language file (one which generates only first time) you have " +
130+
"to /reset whole terminal application." +
121131
"</td>" +
122132
"</tr>" +
123133
"<tr>" +

csp/webTerminal/js/server.js.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ var server = new function() {
4242
* @param namespace
4343
*/
4444
this.requestAutocompleteFile = function(namespace) {
45-
terminal.output.write("Loading Caché language for " + namespace);
45+
terminal.output.write("Loading Caché language for " + namespace.replace(/_/g,"%"));
4646
ajax.get("js/autocomplete/" + namespace + ".js",function(data,allRight){
47+
namespace = namespace.replace(/_/g,"%");
4748
if (allRight) {
4849
var obj = parser.jsonToObject(data);
49-
if (!obj.hasOwnProperty("class") || !obj.hasOwnProperty("global")) {
50+
if (!obj.hasOwnProperty("class")) {
5051
terminal.output.write("Wrong language file for " + namespace + ".");
5152
} else {
52-
terminal.language.addClasses(obj.class);
53-
terminal.language.addGlobals(obj.global);
53+
if (obj.hasOwnProperty("class")) terminal.language.addClasses(obj.class);
54+
if (obj.hasOwnProperty("global")) terminal.language.addGlobals(obj.global);
5455
terminal.output.write("Language for " + namespace + " merged.");
5556
}
5657
} else {
57-
terminal.output.write("Language load fail.");
58+
terminal.output.write("Language load for " + namespace + " fail.");
5859
}
5960
});
6061
};

csp/webTerminal/js/terminal.js.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ var terminal = new function() {
149149
150150
var commands = {};
151151
152+
/**
153+
* Add new favorite record.
154+
*
155+
* @param index
156+
* @param query
157+
*/
152158
this.add = function(index, query) {
153159
commands[index] = query + "";
154160
};
@@ -966,6 +972,10 @@ var terminal = new function() {
966972
});
967973
};
968974
975+
this.processEscapeBlock = function() {
976+
977+
};
978+
969979
/**
970980
* Writing output to object immediately.
971981
*

0 commit comments

Comments
 (0)