From 87ea9141d6b01b2259c38e9f92a2455bdefb7545 Mon Sep 17 00:00:00 2001 From: salexdv Date: Fri, 29 Jul 2022 17:14:20 +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=B8=D0=BC=D0=B5=D0=BD=20=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D0=B2=D0=B8=D0=B7=D0=B8=D1=82=D0=BE=D0=B2=20=D0=B8=20=D1=82?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=B8=D1=87=D0=BD=D1=8B=D1=85=20=D1=87=D0=B0?= =?UTF-8?q?=D1=81=D1=82=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bslGlobals.js | 1 + src/bslMetadata.js | 6 +- src/bsl_helper.js | 202 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 181 insertions(+), 28 deletions(-) diff --git a/src/bslGlobals.js b/src/bslGlobals.js index 1d4afde..79ca0b9 100644 --- a/src/bslGlobals.js +++ b/src/bslGlobals.js @@ -34745,6 +34745,7 @@ define([], function () { "ОбъединениеНедопустимыхПодстановкиXS": {}, "ОбъектXDTO": {}, "ОбъектАнализаДанных": {}, + "ОбъектМетаданных": {}, "ОбъектМетаданныхКонфигурация": {}, "ОбъектыСлояГеографическойСхемы": {}, "ОбъявлениеАтрибутаXS": {}, diff --git a/src/bslMetadata.js b/src/bslMetadata.js index c2918cd..62ba09e 100644 --- a/src/bslMetadata.js +++ b/src/bslMetadata.js @@ -863,7 +863,8 @@ define([], function () { "name":"Реквизиты", "name_en":"Attributes", "description":"Коллекция объектов метаданных, описывающих реквизиты данного объекта метаданных.", - "ref":"types.КоллекцияОбъектовМетаданных" + "ref":"types.КоллекцияОбъектовМетаданных", + "list": "properties" }, "СерииКодов":{ "name":"СерииКодов", @@ -899,7 +900,8 @@ define([], function () { "name":"ТабличныеЧасти", "name_en":"TabularSections", "description":"Коллекция объектов метаданных, описывающих табличные части данного объекта метаданных. Элементами коллекции являются объекты типа ОбъектМетаданных: ТабличнаяЧасть.", - "ref":"types.КоллекцияОбъектовМетаданных" + "ref":"types.КоллекцияОбъектовМетаданных", + "list": "tabulars" }, "ТипКода":{ "name":"ТипКода", diff --git a/src/bsl_helper.js b/src/bsl_helper.js index fcf07cb..d33397b 100644 --- a/src/bsl_helper.js +++ b/src/bsl_helper.js @@ -1150,7 +1150,7 @@ class bslHelper { if (ref && ref.indexOf(':') != -1) { if (metadataKey && medatadaName) { if (ref.indexOf(':metadata') != -1) - ref = metadataKey + '.metadata'; + ref = metadataKey + '.metadata.' + medatadaName; else if (ref.indexOf(':obj') != -1) ref = metadataKey + '.' + medatadaName + '.obj'; else @@ -1410,7 +1410,12 @@ class bslHelper { } } else if (subItemName == 'metadata' && this.objectHasProperties(bslMetadata, itemName, 'metadata')) { - this.getClassSuggestions(suggestions, bslMetadata[itemName]['metadata']); + if (refArray.length == 2) + this.fillSuggestionsForMetadataItems(suggestions, bslMetadata[itemName], itemName, wordContext.ref); + else if (refArray.length == 3) { + let item = this.getMetadataItemByName(bslMetadata, itemName, refArray[2]); + this.getItemMedatadaSuggestions(suggestions, item, bslMetadata[itemName]['metadata']); + } } else if (itemName == 'universalObjects' && this.objectHasProperties(bslGlobals, itemName, subItemName)) { this.getUniversalObjectSuggestions(suggestions, bslGlobals[itemName][subItemName], parentRef); @@ -1749,6 +1754,124 @@ class bslHelper { } + /** + * Fills the suggestions for objects from bslGlobals + * like classes or types + * + * @param {array} suggestions the list of suggestions + * @param {object} obj object from BSL-JSON dictionary + */ + getItemMedatadaSuggestions(suggestions, item, metadata) { + + if (metadata.hasOwnProperty('methods')) { + + for (const [mkey, mvalue] of Object.entries(metadata.methods)) { + + let description = mvalue.hasOwnProperty('returns') ? mvalue.returns : ''; + let signatures = this.getMethodsSignature(mvalue); + let command = null; + let postfix = ''; + let post_action = null; + + if (signatures.length) { + postfix = '('; + post_action = 'editor.action.triggerParameterHints'; + } + + if (signatures.length == 0 || (signatures.length == 1 && signatures[0].parameters.length == 0)) + postfix = '()'; + + let ref = null; + if (mvalue.hasOwnProperty('ref')) + ref = mvalue.ref; + + if (ref || signatures.length) { + // If the attribute contains a ref, we need to run the command to save the position of ref + command = { + id: 'vs.editor.ICodeEditor:1:saveref', + arguments: [ + { + "name": mvalue[this.nameField], + "data": { + "ref": ref, + "sig": signatures + }, + "post_action": post_action + } + ] + }; + } + + suggestions.push({ + label: mvalue[this.nameField], + kind: monaco.languages.CompletionItemKind.Method, + insertText: mvalue[this.nameField] + postfix, + insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, + detail: mvalue.description, + documentation: description, + command: command + }); + + } + + } + + if (metadata.hasOwnProperty('properties')) { + + for (const [pkey, pvalue] of Object.entries(metadata.properties)) { + + let command = null; + let ref = null; + let list = []; + + if (pvalue.hasOwnProperty('ref')) + ref = pvalue.ref; + + if (pvalue.hasOwnProperty('list') && item) { + let list_name = pvalue.list; + if (item.child.hasOwnProperty(list_name)) { + for (const [lkey, lvalue] of Object.entries(item.child[list_name])) { + list.push({ + name: lkey, + ref: '', + kind: monaco.languages.CompletionItemKind.Field, + }); + }; + } + } + + if (ref || list) { + command = { + id: 'vs.editor.ICodeEditor:1:saveref', + arguments: [ + { + "name": pvalue[this.nameField], + "data": { + "ref": ref, + "sig": null, + "list": list + } + } + ] + }; + } + + suggestions.push({ + label: pvalue[this.nameField], + kind: monaco.languages.CompletionItemKind.Field, + insertText: pvalue[this.nameField], + insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, + detail: pvalue.description, + documentation: '', + command: command + }); + + } + + } + + } + /** * Fills the suggestions for objects from bslGlobals * like classes or types @@ -2499,6 +2622,47 @@ class bslHelper { } + fillSuggestionsForMetadataItems(suggestions, metadataObject, metadataName, ref) { + + if (Object.keys(metadataObject.items).length) { + + for (const [ikey, ivalue] of Object.entries(metadataObject.items)) { + + let command = null; + + if (ref) { + command = { + id: 'vs.editor.ICodeEditor:1:saveref', + arguments: [ + { + "name": ikey, + "data": { + "ref": ref + '.' + ikey, + "sig": null + } + } + ] + } + } + + suggestions.push({ + label: ikey, + kind: monaco.languages.CompletionItemKind.Field, + insertText: ikey, + insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, + detail: '', + documentation: '', + command: command + }); + } + + } + else { + requestMetadata(metadataName); + } + + } + /** * Fills array of completion for metadata item like Catalogs, * Documents, InformationRegisters, etc. @@ -2593,25 +2757,8 @@ class bslHelper { } else { - this.getMetadataMethods(suggestions, value, 'managerMethods', '', ''); - - if (Object.keys(value.items).length) { - - for (const [ikey, ivalue] of Object.entries(value.items)) { - values.push({ - name: ikey, - detail: '', - description: '', - postfix: '', - kind: monaco.languages.CompletionItemKind.Field, - command: null - }); - } - - } - else { - requestMetadata(metadataName); - } + this.getMetadataMethods(suggestions, value, 'managerMethods', '', ''); + this.fillSuggestionsForMetadataItems(suggestions, value, metadataName); } @@ -5228,12 +5375,15 @@ class bslHelper { if (value.hasOwnProperty(this.nameField)) { - if (value[this.nameField].toLowerCase() == metadataName) { + if (value.name.toLowerCase() == metadataName || value.name_en.toLowerCase() == metadataName) { for (const [ikey, ivalue] of Object.entries(value.items)) { - if (ikey.toLowerCase() == metadataItem) { - return value; + if (ikey.toLowerCase() == metadataItem.toLowerCase()) { + return { + node: value, + child: ivalue + } } } @@ -5290,9 +5440,9 @@ class bslHelper { let item = this.getMetadataItemByName(data, metadataName, metadataItem); - if (item && item.hasOwnProperty('objMethods')) { + if (item && item.node.hasOwnProperty('objMethods')) { - for (const [mkey, mvalue] of Object.entries(item.objMethods)) { + for (const [mkey, mvalue] of Object.entries(item.node.objMethods)) { if (mvalue[this.nameField].toLowerCase() == metadataFunc) {