Skip to content

Commit 5d8aa1e

Browse files
fixed local autocomplete for set/kill commands
1 parent 01efec6 commit 5d8aa1e

File tree

5 files changed

+71
-6
lines changed

5 files changed

+71
-6
lines changed

classes/%WebTerminal.Engine.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ Method Update(version) As %Status
713713
if ($isobject(httprequest.HttpResponse.Data)) {
714714
do ..SendData($C(13,10))
715715
do ..SendData("35", ..ConstClientOutputLocalized)
716+
do ..SendData($C(13,10))
716717
do $system.OBJ.LoadStream(httprequest.HttpResponse.Data,"",.error,.items)
717718
if (error) {
718719
do ..SendData($C(27)_"[31mFAILED" _ $C(27) _ "[0m" _ $C(13,10))

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"title": "Cache WEB Terminal",
44
"description": "Web-based terminal emulator for Caché administering.",
55
"author": "ZitRo",
6-
"version": "2.0.0-beta.7",
7-
"releaseNumber": "9",
6+
"version": "2.0.0-beta.8",
7+
"releaseNumber": "10",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/intersystems-ru/webterminal.git"

webSource/js/TerminalAutocomplete.js

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ TerminalAutocomplete.prototype.getEndings = function (string) {
176176
};
177177

178178
/**
179-
* @param {TerminalAutocomplete.prototype.TYPES} type
179+
* Register new autocomplete variant.
180+
*
181+
* @param type - TerminalAutocomplete.TYPES.*
180182
* @param {string} lexeme
181183
* @param {string|undefined} [namespace] - If set to undefined, lexeme will be registered in global
182184
* namespace.
@@ -189,8 +191,6 @@ TerminalAutocomplete.prototype.register = function (type, lexeme, namespace, par
189191
: this._trie,
190192
i;
191193

192-
//console.log("Registering", lexeme, "in", namespace || "%", "withing", parents);
193-
194194
if (parents) {
195195
lexeme = (parents || []).join("\n") + "\n" + lexeme;
196196
}
@@ -205,4 +205,67 @@ TerminalAutocomplete.prototype.register = function (type, lexeme, namespace, par
205205

206206
level["\n"] = { type: type };
207207

208+
};
209+
210+
/**
211+
* @param {string} lexeme
212+
* @param {string} [namespace] - If set to undefined, lexeme will be registered in global
213+
* namespace.
214+
* @param {string[]} [parents] - Parents to which child was appended.
215+
*/
216+
TerminalAutocomplete.prototype.clear = function (lexeme, namespace, parents) {
217+
218+
var level = namespace
219+
? this._namespaceTries[namespace] || (this._namespaceTries[namespace] = {})
220+
: this._trie,
221+
i;
222+
223+
if (parents) {
224+
lexeme = (parents || []).join("\n") + "\n" + lexeme;
225+
}
226+
227+
for (i = 0; i < lexeme.length; i++) {
228+
if (level.hasOwnProperty(lexeme[i])) {
229+
level = level[lexeme[i]];
230+
} else {
231+
level = level[lexeme[i]] = {};
232+
}
233+
}
234+
235+
if (level.hasOwnProperty("\n") && level["\n"].type) {
236+
delete level["\n"].type;
237+
}
238+
239+
};
240+
241+
TerminalAutocomplete.prototype.parseForCacheTokens = function (string) {
242+
243+
string = " " + string + " "; // keep two spaces
244+
245+
var re = new RegExp(
246+
"[\\s\\{](set|s)\\s(([a-zA-Z][a-zA-Z0-9]*)|(\\^[a-zA-Z][a-z\\.A-Z0-9]*))\\s*=",
247+
"ig"
248+
),
249+
result = re.exec(string);
250+
251+
if (result && result[2]) {
252+
if (result[2].charAt(0) === "^") {
253+
this.register(this.TYPES.globals, result[2].substr(1), this.NAMESPACE);
254+
} else {
255+
this.register(this.TYPES.common, result[2], this.NAMESPACE);
256+
}
257+
}
258+
259+
re = new RegExp(
260+
"[\\s\\{](k|kill)\\s(([a-zA-Z][a-zA-Z0-9]*)|(\\^[a-zA-Z][a-z\\.A-Z0-9]*))[\\s\\}]",
261+
"ig"
262+
);
263+
result = re.exec(string);
264+
265+
if (result && result[2]) {
266+
if (result[2].charAt(0) === "^") {
267+
this.clear(result[2].substr(1), this.NAMESPACE);
268+
} else this.clear(result[2], this.NAMESPACE);
269+
}
270+
208271
};

webSource/js/TerminalController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var TerminalController = function (TERMINAL) {
2828
*/
2929
this.server = new CacheWebTerminalServer(
3030
this, (location.protocol === "https:" ? "wss:" : "ws:"), location.hostname,
31-
"".concat(/* @echo "location.port || 80" */) || "57772"
31+
"".concat(/* @echo "location.port || 80" */) || "57773"
3232
);
3333

3434
/**

webSource/js/TerminalInput.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ TerminalInput.prototype.submit = function () {
384384
this._handler = null;
385385
handler.call(this, value);
386386
} else {
387+
this.TERMINAL.autocomplete.parseForCacheTokens(value);
387388
this.TERMINAL.controller.terminalQuery(value);
388389
}
389390
this._updateAutocompleteView();

0 commit comments

Comments
 (0)