Skip to content
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

Игнорирование серверных модулей при диагностике UsingSynchronousCalls #3341

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -29,6 +30,7 @@
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.mdclasses.Configuration;
import com.github._1c_syntax.bsl.mdo.CommonModule;
import com.github._1c_syntax.bsl.mdo.support.UseMode;
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.utils.CaseInsensitivePattern;
Expand Down Expand Up @@ -134,9 +136,30 @@ public ParseTree visitFile(BSLParser.FileContext ctx) {
return ctx;
}

if (isServerModule(documentContext)) {
return ctx;
}

return super.visitFile(ctx);
}

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

private static boolean isServerCommonModule(DocumentContext documentContext) {
var mdObject = documentContext.getMdObject();

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

@Override
public ParseTree visitSub(BSLParser.SubContext ctx) {
var methodSymbol = documentContext.getSymbolTree().getMethodSymbol(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.github._1c_syntax.utils.Absolute;
import org.eclipse.lsp4j.Diagnostic;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.test.annotation.DirtiesContext;

import java.nio.file.Paths;
Expand All @@ -45,7 +47,10 @@ 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";

@Test
void testDontUse() {
Expand Down Expand Up @@ -120,9 +125,22 @@ void testUse() {
assertThat(diagnostics).isEmpty();
}

@ParameterizedTest
@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);

List<Diagnostic> diagnostics = getDiagnostics(context);
assertThat(diagnostics).isEmpty();
}

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

private DocumentContext getDocumentContextWithUseFlag(UseMode useMode, String moduleFile) {
var path = Absolute.path(PATH_TO_METADATA);
var testFile = Paths.get(PATH_TO_MODULE_FILE).toAbsolutePath();
var testFile = Paths.get(moduleFile).toAbsolutePath();

initServerContext(path);
var serverContext = spy(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<MetaDataObject xmlns="http://v8.1c.ru/8.3/MDClasses" xmlns:app="http://v8.1c.ru/8.2/managed-application/core" xmlns:cfg="http://v8.1c.ru/8.1/data/enterprise/current-config" xmlns:cmi="http://v8.1c.ru/8.2/managed-application/cmi" xmlns:ent="http://v8.1c.ru/8.1/data/enterprise" xmlns:lf="http://v8.1c.ru/8.2/managed-application/logform" xmlns:style="http://v8.1c.ru/8.1/data/ui/style" xmlns:sys="http://v8.1c.ru/8.1/data/ui/fonts/system" xmlns:v8="http://v8.1c.ru/8.1/data/core" xmlns:v8ui="http://v8.1c.ru/8.1/data/ui" xmlns:web="http://v8.1c.ru/8.1/data/ui/colors/web" xmlns:win="http://v8.1c.ru/8.1/data/ui/colors/windows" xmlns:xen="http://v8.1c.ru/8.3/xcf/enums" xmlns:xpr="http://v8.1c.ru/8.3/xcf/predef" xmlns:xr="http://v8.1c.ru/8.3/xcf/readable" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.10">
<Catalog uuid="1571c5a0-e3bf-482b-9468-c7618340198f">
<InternalInfo>
<xr:GeneratedType name="CatalogObject.СправочникСМенеджером" category="Object">
<xr:TypeId>cd5d9910-c790-46e8-8c99-a0f38f3f9e39</xr:TypeId>
<xr:ValueId>b69e7b91-a362-429c-b5b4-39e1fd765840</xr:ValueId>
</xr:GeneratedType>
<xr:GeneratedType name="CatalogRef.СправочникСМенеджером" category="Ref">
<xr:TypeId>c3d8d716-ce70-459f-9a75-2b8c77a0194b</xr:TypeId>
<xr:ValueId>e4215019-0558-438e-b225-b0f926f42b8a</xr:ValueId>
</xr:GeneratedType>
<xr:GeneratedType name="CatalogSelection.СправочникСМенеджером" category="Selection">
<xr:TypeId>604fe1d0-b22f-48a6-8335-c86562ba654c</xr:TypeId>
<xr:ValueId>fa9ac073-8e89-47de-8aab-9a3badb9a894</xr:ValueId>
</xr:GeneratedType>
<xr:GeneratedType name="CatalogList.СправочникСМенеджером" category="List">
<xr:TypeId>e2756a94-423f-4fff-ab71-622cd2d99f62</xr:TypeId>
<xr:ValueId>23864a50-78d1-48ab-88a6-e3f4d212b34f</xr:ValueId>
</xr:GeneratedType>
<xr:GeneratedType name="CatalogManager.СправочникСМенеджером" category="Manager">
<xr:TypeId>227a9ad8-b4aa-4d7d-8cc0-bed15e263277</xr:TypeId>
<xr:ValueId>d2fae109-dc57-483e-a56a-f2baf0515b86</xr:ValueId>
</xr:GeneratedType>
</InternalInfo>
<Properties>
<Name>СправочникСМенеджером</Name>
<Synonym/>
<Comment/>
<Hierarchical>false</Hierarchical>
<HierarchyType>HierarchyFoldersAndItems</HierarchyType>
<LimitLevelCount>false</LimitLevelCount>
<LevelCount>2</LevelCount>
<FoldersOnTop>true</FoldersOnTop>
<UseStandardCommands>true</UseStandardCommands>
<Owners/>
<SubordinationUse>ToItems</SubordinationUse>
<CodeLength>9</CodeLength>
<DescriptionLength>25</DescriptionLength>
<CodeType>String</CodeType>
<CodeAllowedLength>Variable</CodeAllowedLength>
<CodeSeries>WholeCatalog</CodeSeries>
<CheckUnique>true</CheckUnique>
<Autonumbering>true</Autonumbering>
<DefaultPresentation>AsDescription</DefaultPresentation>
<Characteristics/>
<PredefinedDataUpdate>Auto</PredefinedDataUpdate>
<EditType>InDialog</EditType>
<QuickChoice>false</QuickChoice>
<ChoiceMode>BothWays</ChoiceMode>
<InputByString>
<xr:Field>Catalog.СправочникСМенеджером.StandardAttribute.Description</xr:Field>
<xr:Field>Catalog.СправочникСМенеджером.StandardAttribute.Code</xr:Field>
</InputByString>
<SearchStringModeOnInputByString>Begin</SearchStringModeOnInputByString>
<FullTextSearchOnInputByString>DontUse</FullTextSearchOnInputByString>
<ChoiceDataGetModeOnInputByString>Directly</ChoiceDataGetModeOnInputByString>
<DefaultObjectForm/>
<DefaultFolderForm/>
<DefaultListForm/>
<DefaultChoiceForm/>
<DefaultFolderChoiceForm/>
<AuxiliaryObjectForm/>
<AuxiliaryFolderForm/>
<AuxiliaryListForm/>
<AuxiliaryChoiceForm/>
<AuxiliaryFolderChoiceForm/>
<IncludeHelpInContents>false</IncludeHelpInContents>
<BasedOn/>
<DataLockFields/>
<DataLockControlMode>Managed</DataLockControlMode>
<FullTextSearch>Use</FullTextSearch>
<ObjectPresentation/>
<ExtendedObjectPresentation/>
<ListPresentation/>
<ExtendedListPresentation/>
<Explanation/>
<CreateOnInput>Use</CreateOnInput>
<ChoiceHistoryOnInput>Auto</ChoiceHistoryOnInput>
<DataHistory>DontUse</DataHistory>
<UpdateDataHistoryImmediatelyAfterWrite>false</UpdateDataHistoryImmediatelyAfterWrite>
<ExecuteAfterWriteDataHistoryVersionProcessing>false</ExecuteAfterWriteDataHistoryVersionProcessing>
</Properties>
<ChildObjects>
<Attribute uuid="f4b6bb58-962f-4811-809c-84514f07f16d">
<Properties>
<Name>Реквизит1</Name>
<Synonym/>
<Comment/>
<Type>
<v8:Type>xs:string</v8:Type>
<v8:StringQualifiers>
<v8:Length>10</v8:Length>
<v8:AllowedLength>Variable</v8:AllowedLength>
</v8:StringQualifiers>
</Type>
<PasswordMode>false</PasswordMode>
<Format/>
<EditFormat/>
<ToolTip/>
<MarkNegatives>false</MarkNegatives>
<Mask/>
<MultiLine>false</MultiLine>
<ExtendedEdit>false</ExtendedEdit>
<MinValue xsi:nil="true"/>
<MaxValue xsi:nil="true"/>
<FillFromFillingValue>false</FillFromFillingValue>
<FillValue xsi:type="xs:string"/>
<FillChecking>DontCheck</FillChecking>
<ChoiceFoldersAndItems>Items</ChoiceFoldersAndItems>
<ChoiceParameterLinks/>
<ChoiceParameters/>
<QuickChoice>Auto</QuickChoice>
<CreateOnInput>Auto</CreateOnInput>
<ChoiceForm/>
<LinkByType/>
<ChoiceHistoryOnInput>Auto</ChoiceHistoryOnInput>
<Use>ForItem</Use>
<Indexing>DontIndex</Indexing>
<FullTextSearch>Use</FullTextSearch>
<DataHistory>Use</DataHistory>
</Properties>
</Attribute>
</ChildObjects>
</Catalog>
</MetaDataObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading