Skip to content

Commit

Permalink
Merge pull request #3158 from 1c-syntax/feature/newMDC
Browse files Browse the repository at this point in the history
Поддержка mdclasses 0.12
  • Loading branch information
theshadowco authored Dec 18, 2023
2 parents 637b650 + 60d56fd commit 0c544f4
Show file tree
Hide file tree
Showing 68 changed files with 518 additions and 621 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repositories {
mavenLocal()
mavenCentral()
maven(url = "https://jitpack.io")
maven(url = "https://projectlombok.org/edge-releases")
maven(url = "https://projectlombok.org/edge-releases")
}

group = "io.github.1c-syntax"
Expand Down Expand Up @@ -83,8 +83,8 @@ dependencies {
exclude("org.glassfish", "javax.json")
}
api("com.github.1c-syntax", "utils", "0.5.1")
api("com.github.1c-syntax", "mdclasses", "0.10.4")
api("io.github.1c-syntax", "bsl-common-library", "0.3.0")
api("io.github.1c-syntax", "mdclasses", "0.12.0-rc.5")
api("io.github.1c-syntax", "bsl-common-library", "0.5.0")
api("io.github.1c-syntax", "supportconf", "0.12.1")

// JLanguageTool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.github._1c_syntax.bsl.languageserver.reporters.ReportersAggregator;
import com.github._1c_syntax.bsl.languageserver.reporters.data.AnalysisInfo;
import com.github._1c_syntax.bsl.languageserver.reporters.data.FileInfo;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.types.MdoReference;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.utils.Absolute;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -208,7 +208,7 @@ private FileInfo getFileInfoFromFile(Path srcDir, File file) {
List<Diagnostic> diagnostics = documentContext.getDiagnostics();
MetricStorage metrics = documentContext.getMetrics();
var mdoRef = documentContext.getMdObject()
.map(AbstractMDObjectBase::getMdoReference)
.map(MD::getMdoReference)
.map(MdoReference::getMdoRef)
.orElse("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@
import com.github._1c_syntax.bsl.languageserver.context.symbol.MethodSymbol;
import com.github._1c_syntax.bsl.languageserver.context.symbol.SymbolTree;
import com.github._1c_syntax.bsl.languageserver.utils.Trees;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.Module;
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
import com.github._1c_syntax.bsl.parser.BSLLexer;
import com.github._1c_syntax.bsl.parser.BSLParser;
import com.github._1c_syntax.bsl.parser.BSLTokenizer;
import com.github._1c_syntax.bsl.parser.SDBLTokenizer;
import com.github._1c_syntax.bsl.supconf.SupportConfiguration;
import com.github._1c_syntax.bsl.support.SupportVariant;
import com.github._1c_syntax.bsl.types.ConfigurationSource;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.utils.Lazy;
import edu.umd.cs.findbugs.annotations.Nullable;
import jakarta.annotation.PostConstruct;
Expand All @@ -68,7 +68,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -120,8 +119,6 @@ public class DocumentContext {

private final Lazy<String[]> contentList = new Lazy<>(this::computeContentList, computeLock);
private final Lazy<ModuleType> moduleType = new Lazy<>(this::computeModuleType, computeLock);
private final Lazy<Map<SupportConfiguration, SupportVariant>> supportVariants
= new Lazy<>(this::computeSupportVariants, computeLock);
private final Lazy<ComplexityData> cognitiveComplexityData
= new Lazy<>(this::computeCognitiveComplexity, computeLock);
private final Lazy<ComplexityData> cyclomaticComplexityData
Expand Down Expand Up @@ -240,13 +237,12 @@ public ModuleType getModuleType() {
return moduleType.getOrCompute();
}

public Map<SupportConfiguration, SupportVariant> getSupportVariants() {
return supportVariants.getOrCompute();
public SupportVariant getSupportVariant() {
return getMdObject().map(MD::getSupportVariant).orElse(SupportVariant.NONE);
}

public Optional<AbstractMDObjectBase> getMdObject() {
return Optional
.ofNullable((AbstractMDObjectBase) getServerContext().getConfiguration().getModulesByObject().get(getUri()));
public Optional<MD> getMdObject() {
return getServerContext().getConfiguration().findChild(getUri());
}

public List<SDBLTokenizer> getQueries() {
Expand Down Expand Up @@ -340,7 +336,6 @@ private void clearDependantData() {
diagnosticsLock.unlock();
computeLock.unlock();
}

}

private static FileType computeFileType(URI uri) {
Expand Down Expand Up @@ -371,11 +366,10 @@ private SymbolTree computeSymbolTree() {


private ModuleType computeModuleType() {
return context.getConfiguration().getModuleType(uri);
}

private Map<SupportConfiguration, SupportVariant> computeSupportVariants() {
return context.getConfiguration().getModuleSupport(uri);
return context.getConfiguration()
.getModuleByUri(uri)
.map(Module::getModuleType)
.orElse(ModuleType.UNKNOWN);
}

private ComplexityData computeCognitiveComplexity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
import com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder;
import com.github._1c_syntax.bsl.languageserver.utils.NamedForkJoinWorkerThreadFactory;
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
import com.github._1c_syntax.bsl.mdclasses.CF;
import com.github._1c_syntax.bsl.mdclasses.MDClasses;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.mdclasses.Configuration;
import com.github._1c_syntax.utils.Absolute;
import com.github._1c_syntax.utils.Lazy;
import edu.umd.cs.findbugs.annotations.Nullable;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class ServerContext {
private final LanguageServerConfiguration languageServerConfiguration;

private final Map<URI, DocumentContext> documents = Collections.synchronizedMap(new HashMap<>());
private final Lazy<Configuration> configurationMetadata = new Lazy<>(this::computeConfigurationMetadata);
private final Lazy<CF> configurationMetadata = new Lazy<>(this::computeConfigurationMetadata);
@Nullable
@Setter
private Path configurationRoot;
Expand Down Expand Up @@ -258,7 +259,7 @@ public void closeDocument(DocumentContext documentContext) {
documentContext.clearSecondaryData();
}

public Configuration getConfiguration() {
public CF getConfiguration() {
return configurationMetadata.getOrCompute();
}

Expand All @@ -273,9 +274,9 @@ private DocumentContext createDocumentContext(URI uri) {
return documentContext;
}

private Configuration computeConfigurationMetadata() {
private CF computeConfigurationMetadata() {
if (configurationRoot == null) {
return Configuration.create();
return (CF) MDClasses.createConfiguration();
}

var progress = workDoneProgressHelper.createProgress(0, "");
Expand All @@ -284,15 +285,15 @@ private Configuration computeConfigurationMetadata() {
var factory = new NamedForkJoinWorkerThreadFactory("compute-configuration-");
var executorService = new ForkJoinPool(ForkJoinPool.getCommonPoolParallelism(), factory, null, true);

Configuration configuration;
CF configuration;
try {
configuration = executorService.submit(() -> Configuration.create(configurationRoot)).get();
configuration = (CF) executorService.submit(() -> MDClasses.createConfiguration(configurationRoot)).get();
} catch (ExecutionException e) {
LOGGER.error("Can't parse configuration metadata. Execution exception.", e);
configuration = Configuration.create();
configuration = (CF) MDClasses.createConfiguration();
} catch (InterruptedException e) {
LOGGER.error("Can't parse configuration metadata. Interrupted exception.", e);
configuration = Configuration.create();
configuration = (CF) MDClasses.createConfiguration();
Thread.currentThread().interrupt();
} finally {
executorService.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import com.github._1c_syntax.mdclasses.mdo.MDCommonModule;
import com.github._1c_syntax.bsl.mdo.CommonModule;
import com.github._1c_syntax.utils.CaseInsensitivePattern;

import java.util.regex.Matcher;
Expand All @@ -49,57 +48,57 @@ protected void check() {
}

documentContext.getMdObject()
.filter(MDCommonModule.class::isInstance)
.map(MDCommonModule.class::cast)
.filter(CommonModule.class::isInstance)
.map(CommonModule.class::cast)
.filter(this::flagsCheck)
.map(AbstractMDObjectBase::getName)
.map(CommonModule::getName)
.map(pattern::matcher)
.filter(this::matchCheck)
.ifPresent(commonModule -> diagnosticStorage.addDiagnostic(range));
}

protected abstract boolean flagsCheck(MDCommonModule commonModule);
protected abstract boolean flagsCheck(CommonModule commonModule);

protected boolean matchCheck(Matcher matcher) {
return !matcher.find();
}

protected boolean isClientServer(MDCommonModule commonModule) {
protected boolean isClientServer(CommonModule commonModule) {
return !commonModule.isServerCall()
&& commonModule.isServer()
&& commonModule.isExternalConnection()
&& isClientApplication(commonModule);
}

protected boolean isClient(MDCommonModule commonModule) {
protected boolean isClient(CommonModule commonModule) {
return !commonModule.isServerCall()
&& !commonModule.isServer()
&& !commonModule.isExternalConnection()
&& isClientApplication(commonModule);
}

protected boolean isServerCall(MDCommonModule commonModule) {
protected boolean isServerCall(CommonModule commonModule) {
return commonModule.isServerCall()
&& commonModule.isServer()
&& !commonModule.isExternalConnection()
&& !commonModule.isClientOrdinaryApplication()
&& !commonModule.isClientManagedApplication();
}

protected boolean isServer(MDCommonModule commonModule) {
protected boolean isServer(CommonModule commonModule) {
return !commonModule.isServerCall()
&& commonModule.isServer()
&& commonModule.isExternalConnection()
&& isClientOrdinaryAppIfNeed(commonModule)
&& !commonModule.isClientManagedApplication();
}

private boolean isClientApplication(MDCommonModule commonModule) {
private boolean isClientApplication(CommonModule commonModule) {
return isClientOrdinaryAppIfNeed(commonModule)
&& commonModule.isClientManagedApplication();
}

private boolean isClientOrdinaryAppIfNeed(MDCommonModule commonModule) {
private boolean isClientOrdinaryAppIfNeed(CommonModule commonModule) {
return commonModule.isClientOrdinaryApplication()
|| !serverConfiguration.getDiagnosticsOptions().isOrdinaryAppSupport();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
package com.github._1c_syntax.bsl.languageserver.diagnostics;

import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.ModuleOwner;
import com.github._1c_syntax.bsl.types.MDOType;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBSL;
import com.github._1c_syntax.mdclasses.mdo.AbstractMDObjectBase;
import org.eclipse.lsp4j.Range;

import java.util.ArrayList;
Expand Down Expand Up @@ -103,24 +103,25 @@ protected void addDiagnostic(String message) {
diagnosticStorage.addDiagnostic(diagnosticRange, message);
}

protected abstract void checkMetadata(AbstractMDObjectBase mdo);
protected abstract void checkMetadata(MD mdo);

private void checkMetadataWithModules() {
documentContext.getMdObject()
.filter(mdo -> filterMdoTypes.contains(mdo.getMdoType()))
.filter(AbstractMDObjectBSL.class::isInstance)
.filter(ModuleOwner.class::isInstance)
.map(ModuleOwner.class::cast)
.filter(this::haveMatchingModule)
.ifPresent(this::checkMetadata);
}

private boolean haveMatchingModule(AbstractMDObjectBase mdo) {
private boolean haveMatchingModule(ModuleOwner mdo) {
// чтобы не анализировать несколько раз и не выдавать одинаковые результаты для разных модулей,
// выберем только один модуль, например модуль менеджера
if (documentContext.getModuleType() == ModuleType.ManagerModule){
if (documentContext.getModuleType() == ModuleType.ManagerModule) {
return true;
}

return ((AbstractMDObjectBSL) mdo).getModules().stream()
return mdo.getModules().stream()
.filter(mdoModule -> OBJECT_MODULES.contains(mdoModule.getModuleType()))
.count() == 1;
}
Expand All @@ -135,8 +136,8 @@ private boolean haveMatchingModule(AbstractMDObjectBase mdo) {
private void checkMetadataWithoutModules() {
documentContext.getServerContext().getConfiguration().getChildren().stream()
.filter(mdo -> filterMdoTypes.contains(mdo.getMdoType()))
.filter(mdo -> !(mdo instanceof AbstractMDObjectBSL)
|| (((AbstractMDObjectBSL) mdo).getModules().stream()
.filter(mdo -> !(mdo instanceof ModuleOwner moduleOwner)
|| (moduleOwner.getModules().stream()
.noneMatch(module -> OBJECT_MODULES.contains(module.getModuleType()))))
.forEach(this::checkMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
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.languageserver.utils.Keywords;
import com.github._1c_syntax.bsl.mdo.CommonModule;
import com.github._1c_syntax.bsl.mdo.support.ReturnValueReuse;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.mdclasses.mdo.MDCommonModule;
import com.github._1c_syntax.utils.CaseInsensitivePattern;

import java.util.regex.Pattern;
Expand Down Expand Up @@ -68,18 +68,14 @@ protected void check() {
.forEach(regionSymbol -> diagnosticStorage.addDiagnostic(regionSymbol.getRegionNameRange()));
}

private boolean isCashed(DocumentContext documentContext) {
private static boolean isCashed(DocumentContext documentContext) {
return documentContext.getMdObject()
.filter(MDCommonModule.class::isInstance)
.map(MDCommonModule.class::cast)
.map(MDCommonModule::getReturnValuesReuse)
.filter(this::isReuseValue)
.filter(CommonModule.class::isInstance)
.map(CommonModule.class::cast)
.map(CommonModule::getReturnValuesReuse)
.filter(value -> value == ReturnValueReuse.DURING_REQUEST
|| value == ReturnValueReuse.DURING_SESSION)
.isPresent();
}

private Boolean isReuseValue(ReturnValueReuse value) {
return value == ReturnValueReuse.DURING_REQUEST
|| value == ReturnValueReuse.DURING_SESSION;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,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.parser.BSLParser;
import com.github._1c_syntax.mdclasses.Configuration;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.TerminalNode;

@DiagnosticMetadata(
type = DiagnosticType.ERROR,
Expand All @@ -43,15 +41,14 @@ public class CommonModuleAssignDiagnostic extends AbstractVisitorDiagnostic {
@Override
public ParseTree visitLValue(BSLParser.LValueContext ctx) {

TerminalNode identifier = ctx.IDENTIFIER();
var identifier = ctx.IDENTIFIER();

if (identifier == null
|| ctx.acceptor() != null) {
if (identifier == null || ctx.acceptor() != null) {
return ctx;
}

Configuration configuration = documentContext.getServerContext().getConfiguration();
if (configuration.getCommonModule(identifier.getText()).isPresent()) {
var configuration = documentContext.getServerContext().getConfiguration();
if (configuration.findCommonModule(identifier.getText()).isPresent()) {
diagnosticStorage.addDiagnostic(identifier, info.getMessage(identifier.getText()));
}

Expand Down
Loading

0 comments on commit 0c544f4

Please sign in to comment.