-
Notifications
You must be signed in to change notification settings - Fork 121
WIP Add diagnostic for AttachIdleHandler #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Использование метода ПодключитьОбработчикОжидания (AttachIdleHandler) | ||
|
|
||
| | Тип | Поддерживаются<br/>языки | Важность | Включена<br/>по умолчанию | Время на<br/>исправление (мин) | Тэги | | ||
| | :-: | :-: | :-: | :-: | :-: | :-: | | ||
| | `Ошибка` | `BSL`<br/>`OS` | `Информационный` | `Да` | `1` | `error`<br/>`unpredictable` | | ||
|
|
||
| <!-- Блоки выше заполняются автоматически, не трогать --> | ||
| ## Описание диагностики | ||
| Подключение или отключение обработчика ожидания с указанием несуществующего метода | ||
|
|
||
| ## Примеры | ||
| Неправильно | ||
|
|
||
| ```Bsl | ||
|
|
||
| &НаКлиенте | ||
| Процедура НайтиСтрокуСОшибкой(Команда) | ||
|
|
||
| ПодключитьОбработчикОжидания("НеизвестныйМетод", 0.1, Истина); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| ``` | ||
|
|
||
| Правильно | ||
|
|
||
| ```Bsl | ||
| &НаКлиенте | ||
| Процедура НайтиСтроку(Команда) | ||
|
|
||
| ПодключитьОбработчикОжидания("ВыполнитьПоиск", 0.1, Истина); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| &НаКлиенте | ||
| Процедура ВыполнитьПоиск() | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| ``` | ||
| ## Источники | ||
|
|
||
| * Полезная информация: [Отложенная обработка события элемента управления в форме](https://its.1c.ru/db/metod8dev/content/1820/hdoc) | ||
|
|
||
| ## Сниппеты | ||
|
|
||
| <!-- Блоки ниже заполняются автоматически, не трогать --> | ||
| ### Экранирование кода | ||
|
|
||
| ```bsl | ||
| // BSLLS:AttachIdleHandler-off | ||
| // BSLLS:AttachIdleHandler-on | ||
| ``` | ||
|
|
||
| ### Параметр конфигурационного файла | ||
|
|
||
| ```json | ||
| "AttachIdleHandler": false | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Usage AttachIdleHandler (AttachIdleHandler) | ||
|
|
||
| | Type | Scope | Severity | Activated<br/>by default | Minutes<br/>to fix | Tags | | ||
| | :-: | :-: | :-: | :-: | :-: | :-: | | ||
| | `Error` | `BSL`<br/>`OS` | `Info` | `Yes` | `1` | `error`<br/>`unpredictable` | | ||
|
|
||
| <!-- Блоки выше заполняются автоматически, не трогать --> | ||
| ## Description | ||
| Attach or detach idle handler with not existed method | ||
|
|
||
| ## Examples | ||
|
|
||
| BAD | ||
|
|
||
| ```Bsl | ||
|
|
||
| &НаКлиенте | ||
| Процедура НайтиСтрокуСОшибкой(Команда) | ||
|
|
||
| ПодключитьОбработчикОжидания("НеизвестныйМетод", 0.1, Истина); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| ``` | ||
|
|
||
| GOOD | ||
|
|
||
| ```Bsl | ||
| &НаКлиенте | ||
| Процедура НайтиСтроку(Команда) | ||
|
|
||
| ПодключитьОбработчикОжидания("ВыполнитьПоиск", 0.1, Истина); | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| &НаКлиенте | ||
| Процедура ВыполнитьПоиск() | ||
|
|
||
| КонецПроцедуры | ||
|
|
||
| ``` | ||
| ## Sources | ||
|
|
||
| * Usage info: [Отложенная обработка события элемента управления в форме](https://its.1c.ru/db/metod8dev/content/1820/hdoc) | ||
|
|
||
| ## Snippets | ||
|
|
||
| <!-- Блоки ниже заполняются автоматически, не трогать --> | ||
| ### Diagnostic ignorance in code | ||
|
|
||
| ```bsl | ||
| // BSLLS:AttachIdleHandler-off | ||
| // BSLLS:AttachIdleHandler-on | ||
| ``` | ||
|
|
||
| ### Parameter for config | ||
|
|
||
| ```json | ||
| "AttachIdleHandler": false | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * This file is a part of BSL Language Server. | ||
| * | ||
| * Copyright © 2018-2020 | ||
| * Alexey Sosnoviy <[email protected]>, Nikita Gryzlov <[email protected]> and contributors | ||
| * | ||
| * SPDX-License-Identifier: LGPL-3.0-or-later | ||
| * | ||
| * BSL Language Server is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 3.0 of the License, or (at your option) any later version. | ||
| * | ||
| * BSL Language Server is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with BSL Language Server. | ||
| */ | ||
| package com.github._1c_syntax.bsl.languageserver.diagnostics; | ||
|
|
||
| import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo; | ||
| import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata; | ||
| import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticSeverity; | ||
| import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticTag; | ||
| import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType; | ||
| import com.github._1c_syntax.bsl.parser.BSLParser; | ||
| import com.github._1c_syntax.utils.CaseInsensitivePattern; | ||
| import org.antlr.v4.runtime.RuleContext; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| @DiagnosticMetadata( | ||
| type = DiagnosticType.ERROR, | ||
| severity = DiagnosticSeverity.INFO, | ||
| minutesToFix = 1, | ||
| tags = { | ||
| DiagnosticTag.ERROR, | ||
| DiagnosticTag.UNPREDICTABLE | ||
| } | ||
MinimaJack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ) | ||
| public class AttachIdleHandlerDiagnostic extends AbstractFindMethodDiagnostic { | ||
| private static final String BOOLEAN_TYPE = "Boolean"; | ||
| private static final String DATE_TYPE = "Datetime"; | ||
| private static final String NULL_TYPE = "Null"; | ||
| private static final String NUMBER_TYPE = "Number"; | ||
| private static final String STRING_TYPE = "String"; | ||
| private static final String UNDEFINED_TYPE = "Undefined"; | ||
|
|
||
| private static final Pattern MESSAGE_PATTERN = CaseInsensitivePattern.compile( | ||
| "ПодключитьОбработчикОжидания|AttachIdleHandler|ОтключитьОбработчикОжидания|DetachIdleHandler" | ||
| ); | ||
|
|
||
| /** | ||
| * Конструктор по умолчанию | ||
| * | ||
| * @param info служебная информация о диагностике | ||
| */ | ||
| AttachIdleHandlerDiagnostic(DiagnosticInfo info) { | ||
| super(info, MESSAGE_PATTERN); | ||
| } | ||
|
|
||
| /** | ||
| * Получение типа константного значения | ||
| * | ||
| * @param constValue - значение | ||
| */ | ||
| private static String getTypeFromConstValue(BSLParser.ConstValueContext constValue) { | ||
| String result; | ||
| if (constValue.string() != null) { | ||
| result = STRING_TYPE; | ||
| } else if (constValue.DATETIME() != null) { | ||
| result = DATE_TYPE; | ||
| } else if (constValue.numeric() != null) { | ||
| result = NUMBER_TYPE; | ||
| } else if (constValue.TRUE() != null) { | ||
| result = BOOLEAN_TYPE; | ||
| } else if (constValue.FALSE() != null) { | ||
| result = BOOLEAN_TYPE; | ||
| } else if (constValue.NULL() != null) { | ||
| result = NULL_TYPE; | ||
| } else { | ||
| result = UNDEFINED_TYPE; | ||
| } | ||
|
|
||
| return result; | ||
|
||
|
|
||
| } | ||
|
|
||
| @Override | ||
| protected boolean checkGlobalMethodCall(BSLParser.GlobalMethodCallContext ctx) { | ||
|
|
||
| if (!getMethodPattern().matcher(ctx.methodName().getText()).matches()) { | ||
| return false; | ||
| } | ||
| if (ctx.doCall().callParamList().callParam().size() == 0) { | ||
MinimaJack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return false; | ||
| } | ||
|
|
||
| Optional<String> methodName = Optional.ofNullable(ctx.doCall()) | ||
MinimaJack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .map(BSLParser.DoCallContext::callParamList) | ||
| .flatMap(callParamListContext -> callParamListContext.callParam().stream().findFirst()) | ||
| .map(BSLParser.CallParamContext::expression) | ||
| .map(BSLParser.ExpressionContext::member) | ||
| .flatMap(memberListContext -> memberListContext.stream().findFirst()) | ||
| .map(BSLParser.MemberContext::constValue) | ||
| .filter(constValue -> getTypeFromConstValue(constValue).equals(STRING_TYPE)) | ||
| .map(RuleContext::getText) | ||
| .map(constValueText -> constValueText.substring(1, constValueText.length() - 1)); | ||
|
|
||
| if (methodName.isPresent()) { | ||
| boolean methodExist = documentContext.getSymbolTree().getMethods() | ||
| .stream() | ||
| .anyMatch(e -> e.getName().equalsIgnoreCase(methodName.get())); | ||
|
|
||
| return !methodExist; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| diagnosticMessage=Select existed method in params | ||
| diagnosticName=Usage AttachIdleHandler |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| diagnosticMessage=Выбирите существующий метод в параметрах | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Опечатка Выбирите |
||
| diagnosticName=Использование метода ПодключитьОбработчикОжидания | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * This file is a part of BSL Language Server. | ||
| * | ||
| * Copyright © 2018-2020 | ||
| * Alexey Sosnoviy <[email protected]>, Nikita Gryzlov <[email protected]> and contributors | ||
| * | ||
| * SPDX-License-Identifier: LGPL-3.0-or-later | ||
| * | ||
| * BSL Language Server is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Lesser General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 3.0 of the License, or (at your option) any later version. | ||
| * | ||
| * BSL Language Server is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with BSL Language Server. | ||
| */ | ||
| package com.github._1c_syntax.bsl.languageserver.diagnostics; | ||
|
|
||
| import org.eclipse.lsp4j.Diagnostic; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static com.github._1c_syntax.bsl.languageserver.util.Assertions.assertThat; | ||
|
|
||
| class AttachIdleHandlerDiagnosticTest extends AbstractDiagnosticTest<AttachIdleHandlerDiagnostic> { | ||
| AttachIdleHandlerDiagnosticTest() { | ||
| super(AttachIdleHandlerDiagnostic.class); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void test() { | ||
|
|
||
| List<Diagnostic> diagnostics = getDiagnostics(); | ||
|
|
||
| assertThat(diagnostics).hasSize(2); | ||
| assertThat(diagnostics, true) | ||
| .hasRange(9, 4, 9, 32) | ||
| .hasRange(38, 0, 38, 27); | ||
|
|
||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Предлагаю переназвать правило для большей детализации - Не существует обработчик ожидания в управляемой форме.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно просто на форме...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
да, можно и на форме, если у тебя отловятся и модули обычных форм )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В новой версии платформы управляемые формы переименованы в просто формы.