From 1044614cc22376be3fda12d85f30fc7b228c351a Mon Sep 17 00:00:00 2001 From: salexdv Date: Wed, 16 Dec 2020 22:18:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BA=D0=B0=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=20=D0=B2=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B5=20(=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D1=8F=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=D0=B7=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=82=D0=B0?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D1=86=D1=8B,=20=D0=BF=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=B8=D0=B7=20=D0=92?= =?UTF-8?q?=D0=A2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bsl_helper.js | 55 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/bsl_helper.js b/src/bsl_helper.js index 3efe433..f7f000b 100644 --- a/src/bsl_helper.js +++ b/src/bsl_helper.js @@ -1648,7 +1648,6 @@ class bslHelper { if (ikey.toLowerCase() == metadataName) { this.fillSuggestionsForMetadataItem(suggestions, ivalue); - } } @@ -1663,6 +1662,58 @@ class bslHelper { } + /** + * Fills array of completition for temporary table + * + * @param {array} suggestions array of suggestions for provideCompletionItems + * @param {string} sourceDefinition source string definition + * @param {position} startPosition the begining of current query + */ + getQueryFieldsCompletitionForTempTable(suggestions, sourceDefinition, startPosition) { + + // Let's find definition for temporary table + let intoMatch = this.model.findPreviousMatch('(?:поместить|into)\\s+' + sourceDefinition, startPosition, true); + + if (intoMatch) { + + // Now we need to find start of this query + let position = new monaco.Position(intoMatch.range.startLineNumber, intoMatch.range.startColumn); + let startMatch = this.model.findPreviousMatch('(?:выбрать|select)', position, true); + + if (startMatch) { + + // Searching field's definition between select...into + let searchRange = new monaco.Range(startMatch.range.startLineNumber, 1, intoMatch.range.startLineNumber, 1); + let matches = this.model.findMatches('^.*\\.(.*?),?\\s?(?:(?:как|as)\\s+(.*?),?)?$', searchRange, true, false, null, true); + + if (matches) { + + for (let idx = 0; idx < matches.length; idx++) { + + let match = matches[idx]; + let field = match.matches[match.matches.length - 1]; + + if (field) { + + suggestions.push({ + label: field, + kind: monaco.languages.CompletionItemKind.Enum, + insertText: field, + insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet + }); + + } + + } + + } + + } + + } + + } + /** * Fills array of completition for fields of querie's table * @@ -1686,7 +1737,7 @@ class bslHelper { sourceDefinition = sourceDefinition.replace(/(из|левое|правое|внутреннее|внешнее|полное|from|left|right|inner|outer|full)?\s?(соединение|join)?/gi, '').trim(); if (!this.getQueryFieldsCompletitionForMetadata(suggestions, sourceDefinition)) { - + this.getQueryFieldsCompletitionForTempTable(suggestions, sourceDefinition, position); } }