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

Реализация подсказки директив компиляции closes #300

This commit is contained in:
salexdv 2022-11-14 09:05:45 +03:00
parent 851fbd36c2
commit 04fd6b2b30
2 changed files with 73 additions and 3 deletions

View File

@ -3477,6 +3477,34 @@ class bslHelper {
}
/**
* Fills array of completion for compile directives
*
* @param {array} suggestions array of suggestions for provideCompletionItems
*/
getCompilerDirectivesCompetition(suggestions) {
for (const [key, value] of Object.entries(bslGlobals.compilerDirectives)) {
if ((key == 'ru' && !engLang) || (key == 'en' && engLang)) {
for (const [directive, empty] of Object.entries(value)) {
suggestions.push({
label: directive,
kind: monaco.languages.CompletionItemKind.Enum,
insertText: directive,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
});
}
}
}
}
/**
* Fills completions for object's methods and properties
* into expressions like 'Types = New Array; Types.Cou<-(unt)'
@ -3643,6 +3671,47 @@ class bslHelper {
}
/**
* Determines if compile directives is needed
*
* @returns {bool}
*/
requireCompilerDirectives(triggerCharacter) {
if (triggerCharacter && triggerCharacter == '&' && this.column == 2) {
return true;
}
else {
if (this.wordData) {
const range = new monaco.Range(
this.lineNumber,
this.wordData.startColumn - 1,
this.lineNumber,
this.wordData.startColumn
);
return (this.wordData.startColumn == 2 && this.model.getValueInRange(range) == '&')
}
else if (this.column == 2) {
const range = new monaco.Range(
this.lineNumber,
1,
this.lineNumber,
2
);
return (this.model.getValueInRange(range) == '&')
}
}
return false
}
/**
* Completion provider for code-mode
*
@ -3656,9 +3725,10 @@ class bslHelper {
let suggestions = [];
if (context.triggerCharacter && context.triggerCharacter == ' ') {
this.getClassCompletion(suggestions, bslGlobals.classes, true);
}
else if (this.requireCompilerDirectives(context.triggerCharacter)) {
this.getCompilerDirectivesCompetition(suggestions);
}
else {

View File

@ -515,7 +515,7 @@ define([], function () {
bsl: {
languageDef: bsl_language,
completionProvider: {
triggerCharacters: ['.', '"', ' '],
triggerCharacters: ['.', '"', ' ', '&'],
provideCompletionItems: function (model, position, context, token) {
resetSuggestWidgetDisplay();
let bsl = new bslHelper(model, position);