mirror of
https://github.com/salexdv/bsl_console.git
synced 2024-11-24 08:33:29 +02:00
Описание всех типов и подсказка для функции Тип closes #2
This commit is contained in:
parent
08e9e1e42c
commit
38e80da5b2
1510
src/bslGlobals.js
1510
src/bslGlobals.js
File diff suppressed because it is too large
Load Diff
@ -140,7 +140,7 @@ class bslHelper {
|
||||
exp = expArray[index]
|
||||
else {
|
||||
if (expArray[index].trim() !== '' && !this.lastOperator)
|
||||
this.lastOperator = expArray[index];
|
||||
this.lastOperator = expArray[index].replace(/[a-zA-Z0-9\u0410-\u044F_\.]/, '');
|
||||
}
|
||||
index--;
|
||||
}
|
||||
@ -210,10 +210,11 @@ class bslHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if string contain class constructor (New|Новый)
|
||||
* @param {string} word - last typed word
|
||||
* Determines if string contain class constructor (New|Новый)
|
||||
*
|
||||
* @returns {bool}
|
||||
*/
|
||||
requireClass(word) {
|
||||
requireClass() {
|
||||
|
||||
let exp = this.getLastNExpression(1);
|
||||
return /^(?:new|новый)$/.test(exp);
|
||||
@ -232,6 +233,19 @@ class bslHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if string contain type constructor (Type|Тип)
|
||||
*
|
||||
*
|
||||
* @returns {bool}
|
||||
*/
|
||||
requireType() {
|
||||
|
||||
let exp = this.getFuncName();
|
||||
return (exp == 'type' || exp == 'тип');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills array of completition for language keywords, classes, global functions,
|
||||
* global variables and system enumarations
|
||||
@ -734,6 +748,69 @@ class bslHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills array of completition for types
|
||||
*
|
||||
* @param {array} suggestions array of suggestions for provideCompletionItems
|
||||
* @param {object} data objects from BSL-JSON dictionary
|
||||
* @param {CompletionItemKind} kind - monaco.languages.CompletionItemKind (class, function, constructor etc.)
|
||||
*/
|
||||
getTypesCompletition(suggestions, data, kind) {
|
||||
|
||||
let subType = this.getLastNExpression(2);
|
||||
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
|
||||
let values = [];
|
||||
|
||||
for (const [inkey, invalue] of Object.entries(value)) {
|
||||
|
||||
if (!subType) {
|
||||
|
||||
let suggestion = {
|
||||
label: inkey,
|
||||
kind: kind,
|
||||
insertText: inkey,
|
||||
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
|
||||
}
|
||||
|
||||
if (invalue.hasOwnProperty('ref')) {
|
||||
suggestion.insertText += '.';
|
||||
suggestion['command'] = { id: 'editor.action.triggerSuggest', title: 'suggest_type' };
|
||||
}
|
||||
else {
|
||||
suggestion.insertText += '"';
|
||||
}
|
||||
|
||||
suggestions.push(suggestion);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
if (inkey.toLowerCase() == subType) {
|
||||
|
||||
if (invalue.hasOwnProperty('ref') && bslMetadata.hasOwnProperty(invalue.ref) && bslMetadata[invalue.ref].hasOwnProperty('items')) {
|
||||
|
||||
for (const [mkey, mvalue] of Object.entries(bslMetadata[invalue.ref].items)) {
|
||||
|
||||
suggestions.push({
|
||||
label: mkey,
|
||||
kind: kind,
|
||||
insertText: mkey + '"',
|
||||
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Completition provider
|
||||
*
|
||||
@ -743,32 +820,43 @@ class bslHelper {
|
||||
|
||||
let suggestions = [];
|
||||
|
||||
if (!this.getClassCompletition(suggestions, bslGlobals.classes)) {
|
||||
if (!this.requireType()) {
|
||||
|
||||
if (!this.getClassCompletition(suggestions, bslGlobals.systemEnum)) {
|
||||
if (this.lastOperator != '"') {
|
||||
|
||||
if (!this.getMetadataCompletition(suggestions, bslMetadata)) {
|
||||
if (!this.getClassCompletition(suggestions, bslGlobals.classes)) {
|
||||
|
||||
this.getCommonCompletition(suggestions, bslGlobals.keywords, monaco.languages.CompletionItemKind.Keyword.ru, true);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.keywords, monaco.languages.CompletionItemKind.Keyword.en, true);
|
||||
if (!this.getClassCompletition(suggestions, bslGlobals.systemEnum)) {
|
||||
|
||||
if (!this.getMetadataCompletition(suggestions, bslMetadata)) {
|
||||
|
||||
this.getCommonCompletition(suggestions, bslGlobals.keywords, monaco.languages.CompletionItemKind.Keyword.ru, true);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.keywords, monaco.languages.CompletionItemKind.Keyword.en, true);
|
||||
|
||||
if (this.requireClass()) {
|
||||
this.getCommonCompletition(suggestions, bslGlobals.classes, monaco.languages.CompletionItemKind.Constructor, false);
|
||||
}
|
||||
else {
|
||||
this.getCommonCompletition(suggestions, bslGlobals.globalfunctions, monaco.languages.CompletionItemKind.Function, true);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.globalvariables, monaco.languages.CompletionItemKind.Class, false);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.systemEnum, monaco.languages.CompletionItemKind.Enum, false);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.customFunctions, monaco.languages.CompletionItemKind.Function, true);
|
||||
}
|
||||
|
||||
this.getSnippets(suggestions, snippets);
|
||||
|
||||
}
|
||||
|
||||
if (this.requireClass()) {
|
||||
this.getCommonCompletition(suggestions, bslGlobals.classes, monaco.languages.CompletionItemKind.Constructor, false);
|
||||
}
|
||||
else {
|
||||
this.getCommonCompletition(suggestions, bslGlobals.globalfunctions, monaco.languages.CompletionItemKind.Function, true);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.globalvariables, monaco.languages.CompletionItemKind.Class, false);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.systemEnum, monaco.languages.CompletionItemKind.Enum, false);
|
||||
this.getCommonCompletition(suggestions, bslGlobals.customFunctions, monaco.languages.CompletionItemKind.Function, true);
|
||||
}
|
||||
|
||||
this.getSnippets(suggestions, snippets);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
this.getTypesCompletition(suggestions, bslGlobals.types, monaco.languages.CompletionItemKind.Enum);
|
||||
}
|
||||
|
||||
if (suggestions.length)
|
||||
return { suggestions: suggestions }
|
||||
@ -938,7 +1026,14 @@ class bslHelper {
|
||||
if (exp) {
|
||||
|
||||
let fullText = this.getFullTextBeforePosition();
|
||||
let regex = new RegExp(exp + '\\s?=\\s?(.*)\\(.*\\);', 'gi');
|
||||
let regex = null;
|
||||
try {
|
||||
regex = new RegExp(exp + '\\s?=\\s?(.*)\\(.*\\);', 'gi');
|
||||
}
|
||||
catch {
|
||||
return helper;
|
||||
}
|
||||
|
||||
regex = regex.exec(fullText);
|
||||
|
||||
if (regex && 1 < regex.length) {
|
||||
@ -1143,19 +1238,24 @@ class bslHelper {
|
||||
*/
|
||||
getSigHelp() {
|
||||
|
||||
let helper = this.getMetadataSigHelp(bslMetadata);
|
||||
console.log('last', this.lastOperator);
|
||||
if (this.lastOperator != ')') {
|
||||
|
||||
if (!helper)
|
||||
helper = this.getClassSigHelp(bslGlobals.classes);
|
||||
let helper = this.getMetadataSigHelp(bslMetadata);
|
||||
|
||||
if (!helper)
|
||||
helper = this.getCommonSigHelp(bslGlobals.globalfunctions);
|
||||
if (!helper)
|
||||
helper = this.getClassSigHelp(bslGlobals.classes);
|
||||
|
||||
if (!helper)
|
||||
helper = this.getCommonSigHelp(bslGlobals.customFunctions);
|
||||
if (!helper)
|
||||
helper = this.getCommonSigHelp(bslGlobals.globalfunctions);
|
||||
|
||||
if (helper)
|
||||
return new SignatureHelpResult(helper);
|
||||
if (!helper)
|
||||
helper = this.getCommonSigHelp(bslGlobals.customFunctions);
|
||||
|
||||
if (helper)
|
||||
return new SignatureHelpResult(helper);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
// Register a completion item provider for the new language
|
||||
monaco.languages.registerCompletionItemProvider(language.id, {
|
||||
|
||||
triggerCharacters: [' ', '.'],
|
||||
triggerCharacters: [' ', '.', '"'],
|
||||
|
||||
provideCompletionItems: function (model, position) {
|
||||
let bsl = new bslHelper(model, position);
|
||||
@ -108,6 +108,7 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
monaco.languages.registerSignatureHelpProvider(language.id, {
|
||||
|
||||
signatureHelpTriggerCharacters: ['(', ','],
|
||||
signatureHelpRetriggerCharacters: [')'],
|
||||
|
||||
provideSignatureHelp: (model, position) => {
|
||||
let bsl = new bslHelper(model, position);
|
||||
|
27
src/test.js
27
src/test.js
@ -328,6 +328,33 @@ describe("Проверка автокомлита и подсказок реда
|
||||
expect(help).to.have.property('activeParameter');
|
||||
});
|
||||
|
||||
it("проверка автокомплита для функции 'Тип'", function () {
|
||||
bsl = helper('Тип("');
|
||||
assert.equal(bsl.requireType(), true);
|
||||
let suggestions = [];
|
||||
bsl.getTypesCompletition(suggestions, bslGlobals.types, monaco.languages.CompletionItemKind.Enum)
|
||||
expect(suggestions).to.be.an('array').that.not.is.empty;
|
||||
assert.equal(suggestions.some(suggest => suggest.label === "СправочникСсылка"), true);
|
||||
});
|
||||
|
||||
it("проверка автокомплита для функции 'Тип' обернутой в функцию", function () {
|
||||
bsl = helper('Поиск = Найти(Тип("');
|
||||
assert.equal(bsl.requireType(), true);
|
||||
let suggestions = [];
|
||||
bsl.getTypesCompletition(suggestions, bslGlobals.types, monaco.languages.CompletionItemKind.Enum)
|
||||
expect(suggestions).to.be.an('array').that.not.is.empty;
|
||||
assert.equal(suggestions.some(suggest => suggest.label === "СправочникСсылка"), true);
|
||||
});
|
||||
|
||||
it("проверка автокомплита для функции 'Тип' с указанием конкретного вида метаданных", function () {
|
||||
bsl = helper('Тип("СправочникСсылка.');
|
||||
assert.equal(bsl.requireType(), true);
|
||||
let suggestions = [];
|
||||
bsl.getTypesCompletition(suggestions, bslGlobals.types, monaco.languages.CompletionItemKind.Enum)
|
||||
expect(suggestions).to.be.an('array').that.not.is.empty;
|
||||
assert.equal(suggestions.some(suggest => suggest.label === "Товары"), true);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
mocha.run();
|
||||
|
Loading…
Reference in New Issue
Block a user