You've already forked bsl_console
mirror of
https://github.com/salexdv/bsl_console.git
synced 2025-09-16 09:06:17 +02:00
Добавлен функционал работы с точками останова и подсветки строки отладки
This commit is contained in:
13
README.md
13
README.md
@@ -127,6 +127,10 @@
|
||||
| `isDCSMode` | Возвращает `true`, если редактор находится в режиме СКД и `false` в любом другом случае |
|
||||
| `isSuggestWidgetVisible` | Возвращает видимость стандартного списка подсказок |
|
||||
| `isParameterHintsWidgetVisible`| Возвращает видимость списка подсказок для параметров функции/метода |
|
||||
| `setDebugMode` | Включает/выключает режим отладки (влияет на возможность использования команды "Вычислить выражение") |
|
||||
| `isDebugMode` | Возвращает `true`, если редактор находится в режиме отладки и `false` в другом случае |
|
||||
| `setUsingDebugger` | Включает/выключает возможность интерактивного управления точками останова |
|
||||
| `isUsingDebugger` | Возвращает `true`, возможность интерактивного управления точками останова включена и `false` в другом случае |
|
||||
|
||||
### Взаимодействие
|
||||
|
||||
@@ -187,6 +191,11 @@
|
||||
| [`setReviewIssues`](docs/set_review_issues.md) | Устанавливает замечания в режиме Code Review |
|
||||
| `goNextIssue` | Переход к следующему замечанию |
|
||||
| `goPreviousIssue` | Переход к предыдущему замечанию |
|
||||
| `getBreakpoints` | Возвращает сериализованный в JSON массив номеров строк точек останова |
|
||||
| `updateBreakpoints` | Устанавливает/удаляет точку останова в строке по её номеру |
|
||||
| `removeAllBreakpoints` | Удаляет все установленные точки останова |
|
||||
| `setCurrentDebugLine` | Устанавливает цветовое выделение строки отладки по её номеру |
|
||||
| `deleteCurrentDebugLine` | Удаляет цветовое выделение существующей строки отладки |
|
||||
|
||||
## События, генерируемые редактором для 1С:Предприятия
|
||||
|
||||
@@ -212,6 +221,9 @@
|
||||
| `EVENT_ON_INSERT_SNIPPET` | При вставке сниппета (шаблона) [(подробнее)](docs/insert_snippet_event.md) |
|
||||
| `EVENT_GET_VARIABLE_DATA` | При расшифровке значения переменной в табло [(подробнее)](docs/get_var_data_event.md) |
|
||||
| `EVENT_ON_KEY_ESC` | При нажатии ESC [(подробнее)](docs/key_esc_event.md) |
|
||||
| `EVENT_EVALUATE_EXPRESSION` | При выборе пункта меню "Вычислить выражение". Возвращает выделенный в редакторе текст |
|
||||
| `EVENT_UPDATE_BREAKPOINTS` | При интерактивном добавлении/удалении точки останова в редакторе. Возвращает сериализованный в JSON массив номеров строк точек останова |
|
||||
| `EVENT_REMOVE_ALL_BREAKPOINTS` | При интерактивном удалении всех точек останова в редакторе |
|
||||
|
||||
*Перед началом работы с редактором из 1С Предприятия желательно вызвать функцию инициализации и передать в нее текущую версию платформы.*
|
||||
Пример:
|
||||
@@ -246,6 +258,7 @@ setLanguageMode('bsl');
|
||||
|
||||
## Продукты, использующие консоль
|
||||
|
||||
* [OneDebugger](https://infostart.ru/public/2095430/)
|
||||
* [Infostart Toolkit](https://infostart.ru/journal/news/news/infostart-toolkit-1-3-teper-s-novym-redaktorom-koda-na-baze-monaco-editor_1303095/)
|
||||
* [Конвертация данных 3 расширение](https://infostart.ru/public/1289837/)
|
||||
* [Контекстная подсказка в 1С КД3](https://github.com/GenVP/TipsInCD3)
|
||||
|
@@ -25,7 +25,7 @@ define(['vs/editor/editor.main'], function () {
|
||||
overviewRuler: {
|
||||
color: color,
|
||||
darkColor: color,
|
||||
position: 1
|
||||
position: 2
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -78,6 +78,44 @@ define(['vs/editor/editor.main'], function () {
|
||||
|
||||
}
|
||||
|
||||
getSortedBreakpoints = function () {
|
||||
|
||||
return new Map([...editor.breakpoints.entries()].sort((a, b) => a[0] - b[0]));
|
||||
|
||||
}
|
||||
|
||||
updateBreakpoints = function (line) {
|
||||
|
||||
if (line != undefined) {
|
||||
|
||||
let breakpoint = editor.breakpoints.get(line);
|
||||
|
||||
if (breakpoint) {
|
||||
editor.breakpoints.delete(line);
|
||||
}
|
||||
else {
|
||||
let color = '#7e96a8';
|
||||
breakpoint = {
|
||||
range: new monaco.Range(line, 1, line),
|
||||
options: {
|
||||
isWholeLine: true,
|
||||
linesDecorationsClassName: 'breakpoint',
|
||||
overviewRuler: {
|
||||
color: color,
|
||||
darkColor: color,
|
||||
position: 1
|
||||
}
|
||||
}
|
||||
};
|
||||
editor.breakpoints.set(line, breakpoint);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
editor.updateDecorations([]);
|
||||
|
||||
}
|
||||
|
||||
getActions = function(version1C) {
|
||||
|
||||
let actions = {};
|
||||
@@ -197,6 +235,47 @@ define(['vs/editor/editor.main'], function () {
|
||||
}
|
||||
};
|
||||
|
||||
if (isUsingDebugger()) {
|
||||
|
||||
actions.add_breakpoint_bsl = {
|
||||
label: 'Установить/удалить точку останова',
|
||||
key: monaco.KeyCode.F9,
|
||||
cmd: monaco.KeyMod.chord(monaco.KeyCode.F9),
|
||||
order: 1.9,
|
||||
callback: function (ed) {
|
||||
updateBreakpoints(getCurrentLine());
|
||||
sendEvent('EVENT_UPDATE_BREAKPOINTS', getBreakpoints());
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
actions.remove_all_breakpoints_bsl = {
|
||||
label: 'Удалить все точки останова',
|
||||
order: 1.9,
|
||||
callback: function (ed) {
|
||||
removeAllBreakpoints();
|
||||
sendEvent('EVENT_REMOVE_ALL_BREAKPOINTS');
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if (isDebugMode()) {
|
||||
|
||||
actions.evaluate_expression_bsl = {
|
||||
label: 'Вычислить выражение',
|
||||
key: monaco.KeyMod.Shift | monaco.KeyCode.F9,
|
||||
cmd: monaco.KeyMod.chord(monaco.KeyMod.Shift | monaco.KeyCode.F9),
|
||||
order: 1.9,
|
||||
callback: function (ed) {
|
||||
sendEvent('EVENT_EVALUATE_EXPRESSION', selectedText());
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!isDCSMode()) {
|
||||
@@ -205,7 +284,7 @@ define(['vs/editor/editor.main'], function () {
|
||||
label: 'Установить/удалить закладку',
|
||||
key: monaco.KeyMod.Alt | monaco.KeyCode.F2,
|
||||
cmd: monaco.KeyMod.chord(monaco.KeyMod.Alt | monaco.KeyCode.F2),
|
||||
order: 1.9,
|
||||
order: 1.10,
|
||||
callback: function (ed) {
|
||||
let line = getCurrentLine();
|
||||
updateBookmarks(line);
|
||||
|
@@ -52,6 +52,29 @@
|
||||
border-radius: 20%;
|
||||
}
|
||||
|
||||
.breakpoint {
|
||||
background: #ff0000;
|
||||
width: 10px !important;
|
||||
height: 10px !important;
|
||||
left: 4px !important;
|
||||
top: 3px !important;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.debug-line {
|
||||
background: #8abfe2;
|
||||
}
|
||||
|
||||
.debug-line-pointer {
|
||||
width: 0 !important;
|
||||
height: 0 !important;
|
||||
top: 5px !important;
|
||||
left: 4px !important;
|
||||
border-top: 5px solid transparent;
|
||||
border-left: 10px solid #8abfe2;
|
||||
border-bottom: 5px solid transparent;
|
||||
}
|
||||
|
||||
.statusbar-widget {
|
||||
background: #028fef;
|
||||
color: #fff;
|
||||
|
213
src/editor.js
213
src/editor.js
@@ -9,6 +9,8 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
readOnlyMode = false;
|
||||
queryMode = false;
|
||||
DCSMode = false;
|
||||
debugMode = false;
|
||||
usingDebugger = false;
|
||||
version1C = '';
|
||||
userName = '';
|
||||
contextActions = [];
|
||||
@@ -86,10 +88,14 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
reserMark();
|
||||
bslHelper.setText(txt, range, usePadding);
|
||||
|
||||
if (getText())
|
||||
if (getText()) {
|
||||
checkBookmarksCount();
|
||||
else
|
||||
checkBreakpointsCount();
|
||||
}
|
||||
else {
|
||||
removeAllBookmarks();
|
||||
removeAllBreakpoints();
|
||||
}
|
||||
|
||||
editor.checkBookmarks = true;
|
||||
|
||||
@@ -116,11 +122,15 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
else
|
||||
setText(txt);
|
||||
|
||||
if (getText())
|
||||
if (getText()) {
|
||||
checkBookmarksCount();
|
||||
else
|
||||
checkBreakpointsCount();
|
||||
}
|
||||
else {
|
||||
removeAllBookmarks();
|
||||
|
||||
revomeAllBreakpoints();
|
||||
}
|
||||
|
||||
if (mod_event)
|
||||
setOption('generateModificationEvent', true);
|
||||
|
||||
@@ -367,6 +377,32 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
|
||||
}
|
||||
|
||||
setDebugMode = function(mode) {
|
||||
|
||||
debugMode = mode;
|
||||
initContextMenuActions();
|
||||
|
||||
}
|
||||
|
||||
isDebugMode = function() {
|
||||
|
||||
return debugMode;
|
||||
|
||||
}
|
||||
|
||||
setUsingDebugger = function(mode) {
|
||||
|
||||
usingDebugger = mode;
|
||||
initContextMenuActions();
|
||||
|
||||
}
|
||||
|
||||
isUsingDebugger = function() {
|
||||
|
||||
return usingDebugger;
|
||||
|
||||
}
|
||||
|
||||
getCurrentLanguageId = function() {
|
||||
|
||||
let identifier = getActiveEditor().getModel().getLanguageIdentifier();
|
||||
@@ -1089,6 +1125,60 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
|
||||
}
|
||||
|
||||
removeAllBreakpoints = function() {
|
||||
|
||||
editor.breakpoints.clear();
|
||||
editor.updateDecorations([]);
|
||||
|
||||
}
|
||||
|
||||
getBreakpoints = function () {
|
||||
|
||||
let sorted_breakpoints = getSortedBreakpoints();
|
||||
return JSON.stringify(Array.from(sorted_breakpoints.keys()));
|
||||
|
||||
}
|
||||
|
||||
setCurrentDebugLine = function (line) {
|
||||
|
||||
editor.currentDebugLine.clear();
|
||||
|
||||
debugLine = {
|
||||
range: new monaco.Range(line, 1, line),
|
||||
options: {
|
||||
isWholeLine: true,
|
||||
className: 'debug-line',
|
||||
}
|
||||
}
|
||||
|
||||
pointer = {
|
||||
range: new monaco.Range(line, 1, line),
|
||||
options: {
|
||||
isWholeLine: true,
|
||||
linesDecorationsClassName: 'debug-line-pointer',
|
||||
overviewRuler: {
|
||||
position: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DebugLineSet = {
|
||||
line: debugLine,
|
||||
pointer: pointer
|
||||
}
|
||||
|
||||
editor.currentDebugLine.set(line, DebugLineSet);
|
||||
editor.updateDecorations([]);
|
||||
|
||||
}
|
||||
|
||||
deleteCurrentDebugLine = function () {
|
||||
|
||||
editor.currentDebugLine.clear();
|
||||
editor.updateDecorations([]);
|
||||
|
||||
}
|
||||
|
||||
setActiveSuggestLabel = function (label) {
|
||||
|
||||
let element = document.querySelector('.monaco-list-rows .focused .monaco-icon-name-container');
|
||||
@@ -1888,6 +1978,8 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
editor.sendEvent = sendEvent;
|
||||
editor.decorations = [];
|
||||
editor.bookmarks = new Map();
|
||||
editor.breakpoints = new Map();
|
||||
editor.currentDebugLine = new Map();
|
||||
editor.checkBookmarks = true;
|
||||
editor.diff_decorations = [];
|
||||
|
||||
@@ -1899,6 +1991,15 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
permanent_decor.push(value);
|
||||
});
|
||||
|
||||
editor.breakpoints.forEach(function (value) {
|
||||
permanent_decor.push(value);
|
||||
});
|
||||
|
||||
editor.currentDebugLine.forEach(function (value) {
|
||||
permanent_decor.push(value.line);
|
||||
permanent_decor.push(value.pointer);
|
||||
});
|
||||
|
||||
permanent_decor = permanent_decor.concat(editor.diff_decorations);
|
||||
|
||||
getQueryDelimiterDecorations(permanent_decor);
|
||||
@@ -1939,7 +2040,10 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
sendEvent('EVENT_CONTENT_CHANGED', '');
|
||||
|
||||
checkBookmarksAfterRemoveLine(e);
|
||||
checkBreakpointsAfterRemoveLine(e);
|
||||
|
||||
updateBookmarks(undefined);
|
||||
updateBreakpoints(undefined);
|
||||
|
||||
setOption('lastContentChanges', e);
|
||||
|
||||
@@ -1985,6 +2089,7 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
if (e.event.detail == 2 && element.classList.contains('line-numbers')) {
|
||||
let line = e.target.position.lineNumber;
|
||||
updateBookmarks(line);
|
||||
updateBreakpoints(line);
|
||||
}
|
||||
|
||||
if (element.classList.contains('diff-navi')) {
|
||||
@@ -2010,6 +2115,7 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
if (text === '\n') {
|
||||
checkNewStringLine();
|
||||
checkBookmarksAfterNewLine();
|
||||
checkBreakpointsAfterNewLine();
|
||||
}
|
||||
|
||||
});
|
||||
@@ -3091,6 +3197,35 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
|
||||
}
|
||||
|
||||
function checkBreakpointsAfterNewLine() {
|
||||
|
||||
let line = getCurrentLine();
|
||||
let content = getLineContent(line);
|
||||
|
||||
if (content)
|
||||
line--;
|
||||
|
||||
let line_check = getLineCount();
|
||||
|
||||
while (line <= line_check) {
|
||||
|
||||
let breakpoint = editor.breakpoints.get(line_check);
|
||||
|
||||
if (breakpoint) {
|
||||
breakpoint.range.startLineNumber = line_check + 1;
|
||||
breakpoint.range.endLineNumber = line_check + 1;
|
||||
editor.breakpoints.set(line_check + 1, breakpoint);
|
||||
editor.breakpoints.delete(line_check);
|
||||
}
|
||||
|
||||
line_check--;
|
||||
|
||||
}
|
||||
|
||||
updateBreakpoints(undefined);
|
||||
|
||||
}
|
||||
|
||||
function checkBookmarksAfterRemoveLine(contentChangeEvent) {
|
||||
|
||||
if (contentChangeEvent.changes.length && editor.checkBookmarks) {
|
||||
@@ -3143,6 +3278,58 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
|
||||
}
|
||||
|
||||
function checkBreakpointsAfterRemoveLine(contentChangeEvent) {
|
||||
|
||||
if (contentChangeEvent.changes.length && editor.checkBookmarks) {
|
||||
|
||||
let changes = contentChangeEvent.changes[0];
|
||||
let range = changes.range;
|
||||
|
||||
if (!changes.text && range.startLineNumber != range.endLineNumber) {
|
||||
|
||||
let line = range.startLineNumber;
|
||||
let prev_breakpoint = editor.breakpoints.get(range.endLineNumber);
|
||||
|
||||
if (prev_breakpoint) {
|
||||
|
||||
for (l = line; l <= range.endLineNumber; l++) {
|
||||
editor.breakpoints.delete(l);
|
||||
}
|
||||
|
||||
prev_breakpoint.range.startLineNumber = line;
|
||||
prev_breakpoint.range.endLineNumber = line;
|
||||
editor.breakpoints.set(line, prev_breakpoint);
|
||||
|
||||
}
|
||||
|
||||
for (l = line + 1; l <= range.endLineNumber; l++) {
|
||||
editor.breakpoints.delete(l);
|
||||
}
|
||||
|
||||
let line_check = range.endLineNumber;
|
||||
let diff = range.endLineNumber - line;
|
||||
|
||||
while (line_check < getLineCount()) {
|
||||
|
||||
let breakpoint = editor.breakpoints.get(line_check);
|
||||
|
||||
if (breakpoint) {
|
||||
breakpoint.range.startLineNumber = line_check - diff;
|
||||
breakpoint.range.endLineNumber = line_check - diff;
|
||||
editor.breakpoints.set(line_check - diff, breakpoint);
|
||||
editor.breakpoints.delete(line_check);
|
||||
}
|
||||
|
||||
line_check++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function checkBookmarksCount() {
|
||||
|
||||
let count = getLineCount();
|
||||
@@ -3159,6 +3346,22 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit
|
||||
|
||||
}
|
||||
|
||||
function checkBreakpointsCount() {
|
||||
|
||||
let count = getLineCount();
|
||||
let keys = [];
|
||||
|
||||
editor.breakpoints.forEach(function (value, key) {
|
||||
if (count < key)
|
||||
keys.push(key);
|
||||
});
|
||||
|
||||
keys.forEach(function (key) {
|
||||
editor.breakpoints.delete(key);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function checkEmptySuggestions() {
|
||||
|
||||
let msg_element = document.querySelector('.suggest-widget .message');
|
||||
|
Reference in New Issue
Block a user