1
0
mirror of https://github.com/salexdv/bsl_console.git synced 2024-11-24 08:33:29 +02:00

Подсказка переменных объявленных в итерациях

This commit is contained in:
salexdv 2022-09-04 10:44:03 +03:00
parent f406d1fe40
commit b7031cc182

View File

@ -3355,22 +3355,71 @@ class bslHelper {
/** /**
* Looks for variables into iterations of loops * Looks for variables into iterations of loops
* in current position
*
* @param {string} pattern to look for variables
* *
* @returns {array} array with variables names * @returns {array} array with variables names
*/ */
getLoopsVarNames() { getLoopsVarNamesForCurrentPosition(pattern) {
let names = []; 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]; if (loop_start) {
let varDef = match.matches[match.matches.length - 1];
if (!names.some(name => name === varDef)) let start_pos = new monaco.Position(loop_start.range.startLineNumber, loop_start.range.startColumn);
names.push(varDef); 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; let funcLine = 0;
names = names.concat(this.getFunctionsVarsNames(currentLine, funcLine)); names = names.concat(this.getFunctionsVarsNames(currentLine, funcLine));
names = names.concat(this.getDefaultVarsNames(currentLine, funcLine)); names = names.concat(this.getDefaultVarsNames(currentLine, funcLine));
names = names.concat(this.getLoopsVarNames(currentLine));
if (currentLine == 0)
names = names.concat(this.getLoopsVarNames());
return names; return names;