From b7031cc182a71b76e39b89e34f74f6f430afd33f Mon Sep 17 00:00:00 2001 From: salexdv Date: Sun, 4 Sep 2022 10:44:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BE=D0=B1=D1=8A=D1=8F=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B2=20=D0=B8=D1=82=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bsl_helper.js | 69 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/src/bsl_helper.js b/src/bsl_helper.js index e7d54ba..c61ddfd 100644 --- a/src/bsl_helper.js +++ b/src/bsl_helper.js @@ -3355,22 +3355,71 @@ class bslHelper { /** * Looks for variables into iterations of loops + * in current position + * + * @param {string} pattern to look for variables * * @returns {array} array with variables names */ - getLoopsVarNames() { + getLoopsVarNamesForCurrentPosition(pattern) { let names = []; - let matches = Finder.findMatches(this.model, '(?:для каждого|for each)\\s+([a-zA-Z0-9\u0410-\u044F_,\\s=]+)\\s+(?:из|in)'); - matches = matches.concat(Finder.findMatches(this.model, '(?:для|for)\\s+([a-zA-Z0-9\u0410-\u044F_,\\s=]+)\\s+=.*(?:по|to)')); - for (let idx = 0; idx < matches.length; idx++) { + let loop_start = Finder.findPreviousMatch(this.model, pattern, this.position, false); - let match = matches[idx]; - let varDef = match.matches[match.matches.length - 1]; + if (loop_start) { - if (!names.some(name => name === varDef)) - names.push(varDef); + let start_pos = new monaco.Position(loop_start.range.startLineNumber, loop_start.range.startColumn); + let loop_end = Finder.findNextMatch(this.model, '(?:конеццикла|enddo)', start_pos, false); + + if (loop_end) { + + let end_pos = new monaco.Position(loop_end.range.startLineNumber, loop_end.range.startColumn); + + if (start_pos.isBefore(this.position) && this.position.isBefore(end_pos)) { + names.push(loop_start.matches[loop_start.matches.length - 1]); + } + + } + } + + return names; + + } + + /** + * Looks for variables into iterations of loops + * + * @param {int} currentLine the current line + * + * @returns {array} array with variables names + */ + getLoopsVarNames(currentLine) { + + let names = []; + let each_pattern = '(?:для каждого|for each)\\s+([a-zA-Z0-9\u0410-\u044F_,\\s=]+)\\s+(?:из|in)'; + let for_pattern = '(?:для|for)\\s+([a-zA-Z0-9\u0410-\u044F_,\\s=]+)\\s+=.*(?:по|to)'; + + if (currentLine == 0) { + + let matches = Finder.findMatches(this.model, each_pattern); + matches = matches.concat(Finder.findMatches(this.model, for_pattern)); + + for (let idx = 0; idx < matches.length; idx++) { + + let match = matches[idx]; + let varDef = match.matches[match.matches.length - 1]; + + if (!names.some(name => name === varDef)) + names.push(varDef); + + } + + } + else { + + names = this.getLoopsVarNamesForCurrentPosition(each_pattern); + names = names.concat(this.getLoopsVarNamesForCurrentPosition(for_pattern)); } @@ -3392,9 +3441,7 @@ class bslHelper { let funcLine = 0; names = names.concat(this.getFunctionsVarsNames(currentLine, funcLine)); names = names.concat(this.getDefaultVarsNames(currentLine, funcLine)); - - if (currentLine == 0) - names = names.concat(this.getLoopsVarNames()); + names = names.concat(this.getLoopsVarNames(currentLine)); return names;