Skip to content

Commit

Permalink
Ругань Сонара
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Ovsyankin committed Sep 10, 2024
1 parent 8831c1e commit fbe7400
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
package com.github._1c_syntax.bsl.languageserver.diagnostics;

import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.context.symbol.annotations.CompilerDirectiveKind;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata;
Expand All @@ -30,17 +31,14 @@
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticType;
import com.github._1c_syntax.bsl.mdclasses.Configuration;
import com.github._1c_syntax.bsl.mdo.CommonModule;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.support.UseMode;
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.utils.CaseInsensitivePattern;
import org.antlr.v4.runtime.tree.ParseTree;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -138,32 +136,27 @@ public ParseTree visitFile(BSLParser.FileContext ctx) {
return ctx;
}

if (isServerModule(documentContext.getModuleType(), documentContext.getMdObject())) {
if (isServerModule(documentContext)) {
return ctx;
}

return super.visitFile(ctx);
}

private boolean isServerModule(ModuleType moduleType, Optional<MD> mdObject) {
private static boolean isServerModule(DocumentContext documentContext) {
return switch (documentContext.getModuleType()) {
case ApplicationModule, CommandModule, FormModule, ManagedApplicationModule -> false;
case CommonModule -> isServerCommonModule(documentContext);
default -> true; // Все прочие модули это строго серверные и в них синхронные вызовы разрешены
};
}

switch (moduleType) {
case ApplicationModule:
case CommandModule:
case FormModule:
case ManagedApplicationModule:
return false;
case CommonModule: {
if (mdObject.isPresent()) {
var md = (CommonModule) mdObject.get();
return !(md.isClientManagedApplication() || md.isClientOrdinaryApplication());
} else {
return false; // Мы не знаем, что за модуль, проверяем, как обычно.
}
}
default:
return true; // Все прочие модули это строго серверные и в них синхронные вызовы разрешены (и только они возможны)
}
private static boolean isServerCommonModule(DocumentContext documentContext) {
var mdObject = documentContext.getMdObject();

return mdObject.map(mdo -> (CommonModule) mdo)
.filter(commonModule -> !(commonModule.isClientManagedApplication() || commonModule.isClientOrdinaryApplication()))
.isPresent();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class UsingSynchronousCallsDiagnosticTest extends AbstractDiagnosticTest<UsingSy
}

private static final String PATH_TO_METADATA = "src/test/resources/metadata/designer";
private static final String PATH_TO_MODULE_FILE = "src/test/resources/metadata/designer/CommonModules/КлиентскийОбщийМодуль/Ext/Module.bsl";
private static final String PATH_TO_CLIENT_MODULE_FILE = "src/test/resources/metadata/designer/CommonModules/КлиентскийОбщийМодуль/Ext/Module.bsl";
private static final String PATH_TO_SERVER_MODULE_FILE = "src/test/resources/metadata/designer/CommonModules/ПервыйОбщийМодуль/Ext/Module.bsl";
private static final String PATH_TO_OBJECT_MODULE_FILE = "src/test/resources/metadata/designer/Catalogs/СправочникСМенеджером/Ext/ObjectModule.bsl";
private static final String PATH_TO_MANAGER_MODULE_FILE = "src/test/resources/metadata/designer/Catalogs/СправочникСМенеджером/Ext/ManagerModule.bsl";

Expand Down Expand Up @@ -125,7 +126,7 @@ void testUse() {
}

@ParameterizedTest
@ValueSource(strings = {PATH_TO_OBJECT_MODULE_FILE, PATH_TO_MANAGER_MODULE_FILE})
@ValueSource(strings = {PATH_TO_OBJECT_MODULE_FILE, PATH_TO_MANAGER_MODULE_FILE, PATH_TO_SERVER_MODULE_FILE})
void testServerModules(String file) {
var context = getDocumentContextWithUseFlag(UseMode.DONT_USE, file);

Expand All @@ -134,7 +135,7 @@ void testServerModules(String file) {
}

private DocumentContext getDocumentContextWithUseFlag(UseMode useMode) {
return getDocumentContextWithUseFlag(useMode, PATH_TO_MODULE_FILE);
return getDocumentContextWithUseFlag(useMode, PATH_TO_CLIENT_MODULE_FILE);
}

private DocumentContext getDocumentContextWithUseFlag(UseMode useMode, String moduleFile) {
Expand Down

0 comments on commit fbe7400

Please sign in to comment.