Skip to content

Оптимизировано (и местами исправлено) формирование ссылки на объекты MD #3456

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

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dependencies {
exclude("org.antlr", "antlr-runtime")
}
api("io.github.1c-syntax", "utils", "0.6.2")
api("io.github.1c-syntax", "mdclasses", "0.15.0")
api("io.github.1c-syntax", "mdclasses", "develop-SNAPSHOT")
api("io.github.1c-syntax", "bsl-common-library", "0.8.0")
api("io.github.1c-syntax", "supportconf", "0.14.2")
api("io.github.1c-syntax", "bsl-parser-core", "0.3.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
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.utils.Absolute;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -205,10 +203,7 @@ private FileInfo getFileInfoFromFile(Path srcDir, File file) {
var filePath = srcDir.relativize(Absolute.path(file));
var diagnostics = documentContext.getDiagnostics();
var metrics = documentContext.getMetrics();
var mdoRef = documentContext.getMdObject()
.map(MD::getMdoReference)
.map(MdoReference::getMdoRef)
.orElse("");
var mdoRef = documentContext.getMdoRef();

var fileInfo = new FileInfo(filePath, mdoRef, diagnostics, metrics);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.github._1c_syntax.bsl.languageserver.context.computer.SymbolTreeComputer;
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.MdoRefBuilder;
import com.github._1c_syntax.bsl.languageserver.utils.Trees;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
Expand Down Expand Up @@ -256,6 +257,16 @@ public Optional<MD> getMdObject() {
return getServerContext().getConfiguration().findChild(getUri());
}

/**
* Возвращает строковое представление ссылки связанного с объектом объекта метаданных 1С либо строку URI для
* остальных случаев
*
* @return Строковое представление ссылки
*/
public String getMdoRef() {
return MdoRefBuilder.getMdoRef(this);
}

public List<SDBLTokenizer> getQueries() {
return queries.getOrCompute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.github._1c_syntax.bsl.languageserver.WorkDoneProgressHelper;
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
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;
Expand Down Expand Up @@ -307,7 +306,7 @@ private CF computeConfigurationMetadata() {
}

private void addMdoRefByUri(URI uri, DocumentContext documentContext) {
String mdoRef = MdoRefBuilder.getMdoRef(documentContext);
var mdoRef = documentContext.getMdoRef();

mdoRefs.put(uri, mdoRef);
documentsByMDORef.computeIfAbsent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.github._1c_syntax.bsl.languageserver.context.DocumentContext;
import com.github._1c_syntax.bsl.languageserver.context.symbol.ModuleSymbol;
import com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder;
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
import com.github._1c_syntax.bsl.parser.BSLLexer;
import com.github._1c_syntax.bsl.types.ModuleType;
Expand Down Expand Up @@ -69,7 +68,7 @@ public ModuleSymbol compute() {
}

private static String getName(DocumentContext documentContext) {
String name = MdoRefBuilder.getMdoRef(documentContext);
var name = documentContext.getMdoRef();
var moduleType = documentContext.getModuleType();
if (MODULE_TYPES_TO_APPEND_NAME.contains(moduleType)) {
name += "." + moduleType.name();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ protected void addDiagnostic(String message) {
diagnosticStorage.addDiagnostic(diagnosticRange, message);
}

protected String getMdoRefLocal(MD mdo) {
return documentContext.getServerContext().getConfiguration().getMdoRefLocal(mdo);
}

protected abstract void checkMetadata(MD mdo);

private void checkMetadataWithModules() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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.languageserver.utils.MdoRefBuilder;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.Register;
import com.github._1c_syntax.bsl.mdo.children.Dimension;
Expand Down Expand Up @@ -59,11 +58,11 @@ public DenyIncompleteValuesDiagnostic() {
@Override
protected void checkMetadata(MD mdo) {
if (mdo instanceof Register register) {
var mdoRefLocal = getMdoRefLocal(mdo);
register.getDimensions().stream()
.filter(dimension -> !dimension.isDenyIncompleteValues())
.forEach((Dimension dimension) -> {
var ownerMDOName = MdoRefBuilder.getLocaleOwnerMdoName(documentContext, mdo);
addDiagnostic(info.getMessage(dimension.getName(), ownerMDOName));
addDiagnostic(info.getMessage(dimension.getName(), mdoRefLocal));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
*/
package com.github._1c_syntax.bsl.languageserver.diagnostics;

import com.github._1c_syntax.bsl.languageserver.configuration.Language;
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope;
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.mdo.AttributeOwner;
import com.github._1c_syntax.bsl.mdo.ChildrenOwner;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.types.MdoReference;
import com.github._1c_syntax.bsl.types.ModuleType;
import com.github._1c_syntax.utils.CaseInsensitivePattern;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -134,23 +131,18 @@ public class ForbiddenMetadataNameDiagnostic extends AbstractMetadataDiagnostic
protected void checkMetadata(MD mdo) {

// проверка имени метаданного
checkName(mdo.getName(), mdo.getMdoReference());
checkName(mdo.getName(), mdo);

// проверка имен реквизитов и табличных частей
if (mdo instanceof AttributeOwner childrenOwner) {
childrenOwner.getPlainStorageFields()
.forEach(child -> checkName(child.getName(), child.getMdoReference()));
.forEach(child -> checkName(child.getName(), child));
}
}

private void checkName(String name, MdoReference mdoReference) {
private void checkName(String name, MD md) {
if (FORBIDDEN_NAMES_PATTERN.matcher(name).matches()) {
String mdoRef;
if (serverConfiguration.getLanguage() == Language.RU) {
mdoRef = mdoReference.getMdoRefRu();
} else {
mdoRef = mdoReference.getMdoRef();
}
var mdoRef = getMdoRefLocal(md);
addDiagnostic(info.getMessage(name, mdoRef));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
package com.github._1c_syntax.bsl.languageserver.diagnostics;

import com.github._1c_syntax.bsl.languageserver.configuration.Language;
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticParameter;
Expand Down Expand Up @@ -65,7 +64,7 @@ public class MetadataObjectNameLengthDiagnostic extends AbstractMetadataDiagnost
@Override
protected void checkMetadata(MD mdo) {
if (mdo.getName().length() > maxMetadataObjectNameLength) {
addAttributeDiagnostic(mdo);
addDiagnostic(info.getMessage(getMdoRefLocal(mdo), maxMetadataObjectNameLength));
}
}

Expand All @@ -81,14 +80,4 @@ protected void check() {
super.check();
}
}

private void addAttributeDiagnostic(MD attribute) {
String mdoRef;
if (serverConfiguration.getLanguage() == Language.RU) {
mdoRef = attribute.getMdoReference().getMdoRefRu();
} else {
mdoRef = attribute.getMdoReference().getMdoRef();
}
addDiagnostic(info.getMessage(mdoRef, maxMetadataObjectNameLength));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static String getMethodNameByLocation(BSLParserRuleContext node, Range r

@Override
protected void check() {
if (documentContext.getServerContext().getConfiguration().getConfigurationSource() == ConfigurationSource.EMPTY){
if (documentContext.getServerContext().getConfiguration().getConfigurationSource() == ConfigurationSource.EMPTY) {
return;
}
locationRepository.getSymbolOccurrencesByLocationUri(documentContext.getUri())
Expand All @@ -88,7 +88,7 @@ private Optional<CallData> getReferenceToMethodCall(SymbolOccurrence symbolOccur
// т.к. через refIndex.getReferences нельзя получить приватные методы, приходится обходить символы модуля
final var methodSymbol = document.get()
.getSymbolTree().getMethodSymbol(symbol.getSymbolName());
if (methodSymbol.isEmpty()){
if (methodSymbol.isEmpty()) {
final var location = symbolOccurrence.getLocation();
// Нельзя использовать symbol.getSymbolName(), т.к. имя в нижнем регистре
return Optional.of(
Expand All @@ -97,7 +97,7 @@ private Optional<CallData> getReferenceToMethodCall(SymbolOccurrence symbolOccur
location.getRange(), false, false));
}
// вызовы приватных методов внутри самого модуля пропускаем
if (document.get().getUri().equals(documentContext.getUri())){
if (document.get().getUri().equals(documentContext.getUri())) {
return Optional.empty();
}
return methodSymbol
Expand All @@ -109,7 +109,7 @@ private Optional<CallData> getReferenceToMethodCall(SymbolOccurrence symbolOccur

private void fireIssue(CallData callData) {
final String message;
if (!callData.exists){
if (!callData.exists) {
message = info.getMessage(callData.methodName, callData.moduleName);
} else {
message = info.getResourceString(PRIVATE_METHOD_MESSAGE, callData.methodName, callData.moduleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected void check() {

private void checkMethod(EventSubscription eventSubs, String methodName, CommonModule commonModule) {
documentContext.getServerContext()
.getDocument(commonModule.getMdoReference().getMdoRef(), ModuleType.CommonModule)
.getDocument(commonModule.getMdoRef(), ModuleType.CommonModule)
.ifPresent((DocumentContext commonModuleContext) -> {
var method = commonModuleContext.getSymbolTree().getMethods().stream()
.filter(methodSymbol -> methodSymbol.getName().equalsIgnoreCase(methodName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ private List<ModuleSymbol> getPrivilegedModuleSymbols() {
}

private Optional<ModuleSymbol> getPrivilegedModuleSymbol(CommonModule mdCommonModule) {
return documentContext.getServerContext().getDocument(
mdCommonModule.getMdoReference().getMdoRef(), ModuleType.CommonModule)
return documentContext.getServerContext().getDocument(mdCommonModule.getMdoRef(), ModuleType.CommonModule)
.map(documentContext1 -> documentContext1.getSymbolTree().getModule());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
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.languageserver.utils.MdoRefBuilder;
import com.github._1c_syntax.bsl.languageserver.utils.Ranges;
import com.github._1c_syntax.bsl.mdo.Module;
import com.github._1c_syntax.bsl.mdo.ModuleOwner;
Expand Down Expand Up @@ -79,13 +78,8 @@ protected void check() {
.filter(Module::isProtected)
.findAny();
if (hasProtected.isPresent()) {
addDiagnostic(moduleOwner);
diagnosticStorage.addDiagnostic(diagnosticRange, info.getMessage(configuration.getMdoRefLocal(moduleOwner)));
}
});
}

private void addDiagnostic(ModuleOwner moduleOwner) {
var ownerMDOName = MdoRefBuilder.getLocaleOwnerMdoName(documentContext, moduleOwner);
diagnosticStorage.addDiagnostic(diagnosticRange, info.getMessage(ownerMDOName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
package com.github._1c_syntax.bsl.languageserver.diagnostics;

import com.github._1c_syntax.bsl.languageserver.configuration.Language;
import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticMetadata;
import com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope;
Expand Down Expand Up @@ -92,30 +91,20 @@ protected void checkMetadata(MD mdo) {

if (mdo instanceof AttributeOwner attributeOwner && !attributeOwner.getAllAttributes().isEmpty()) {
var mdoName = stringInterner.intern(mdo.getName());
checkkAttributes(attributeOwner.getAllAttributes(), mdoName);
checkAttributes(attributeOwner.getAllAttributes(), mdoName);
}

if (mdo instanceof TabularSectionOwner tabularSectionOwner && !tabularSectionOwner.getTabularSections().isEmpty()) {
tabularSectionOwner.getTabularSections().forEach((TabularSection table) -> {
var tableName = stringInterner.intern(table.getName());
checkkAttributes(table.getAllAttributes(), tableName);
checkAttributes(table.getAllAttributes(), tableName);
});
}
}

private void checkkAttributes(List<Attribute> attributeOwner, String mdoName) {
private void checkAttributes(List<Attribute> attributeOwner, String mdoName) {
attributeOwner.stream()
.filter(attribute -> mdoName.equalsIgnoreCase(attribute.getName()))
.forEach(attribute -> addAttributeDiagnostic(attribute, mdoName));
}

private void addAttributeDiagnostic(Attribute attribute, String mdoName) {
String mdoRef;
if (serverConfiguration.getLanguage() == Language.RU) {
mdoRef = attribute.getMdoReference().getMdoRefRu();
} else {
mdoRef = attribute.getMdoReference().getMdoRef();
}
addDiagnostic(info.getMessage(mdoRef, mdoName));
.forEach(attribute -> addDiagnostic(info.getMessage(getMdoRefLocal(attribute), mdoName)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ private void checkMethod(ScheduledJob scheduleJob, CommonModule mdCommonModule,
final var fullName = getFullName(mdCommonModule, methodName);
scheduledJobHandlers.computeIfAbsent(fullName, k -> new ArrayList<>()).add(scheduleJob);

documentContext.getServerContext().getDocument(
mdCommonModule.getMdoReference().getMdoRef(), ModuleType.CommonModule)
documentContext.getServerContext().getDocument(mdCommonModule.getMdoRef(), ModuleType.CommonModule)
.ifPresent((DocumentContext commonModuleContext) -> {
var method = commonModuleContext.getSymbolTree().getMethods().stream()
.filter(methodSymbol -> methodSymbol.getName().equalsIgnoreCase(methodName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.github._1c_syntax.bsl.mdo.Form;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.storage.form.FormItem;
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
import com.github._1c_syntax.bsl.types.ModuleType;
import org.eclipse.lsp4j.Range;

Expand Down Expand Up @@ -108,9 +107,6 @@ private void checkForm(Form form) {
}

private String getMdoRef(Form form) {
if (documentContext.getServerContext().getConfiguration().getScriptVariant() == ScriptVariant.ENGLISH) {
return form.getMdoReference().getMdoRef();
}
return form.getMdoReference().getMdoRefRu();
return documentContext.getServerContext().getConfiguration().getMdoRefLocal(form);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void checkService(HTTPService httpService) {
httpService.getUrlTemplates().stream()
.flatMap(httpServiceURLTemplate -> httpServiceURLTemplate.getMethods().stream())
.forEach((HTTPServiceMethod service) -> {
final var serviceName = service.getMdoReference().getMdoRef();
final var serviceName = service.getMdoRef();
if (service.getHandler().isEmpty()) {
addMissingHandlerDiagnostic(serviceName);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.MethodDescription;
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.ParameterDescription;
import com.github._1c_syntax.bsl.languageserver.context.symbol.description.TypeDescription;
import com.github._1c_syntax.bsl.languageserver.utils.MdoRefBuilder;
import com.github._1c_syntax.bsl.languageserver.utils.Resources;
import lombok.RequiredArgsConstructor;
import org.eclipse.lsp4j.SymbolKind;
Expand Down Expand Up @@ -142,7 +141,7 @@ public String getSectionWithCodeFences(Collection<String> codeBlocks, String res
public String getLocation(MethodSymbol symbol) {
var documentContext = symbol.getOwner();
var startPosition = symbol.getSelectionRange().getStart();
String mdoRef = MdoRefBuilder.getMdoRef(documentContext);
var mdoRef = documentContext.getMdoRef();

return String.format(
"[%s](%s#%d)",
Expand All @@ -155,7 +154,7 @@ public String getLocation(MethodSymbol symbol) {
public String getLocation(VariableSymbol symbol) {
var documentContext = symbol.getOwner();
var startPosition = symbol.getSelectionRange().getStart();
String mdoRef = MdoRefBuilder.getMdoRef(documentContext);
var mdoRef = documentContext.getMdoRef();

String parentPostfix = symbol.getRootParent(SymbolKind.Method)
.map(sourceDefinedSymbol -> "." + sourceDefinedSymbol.getName())
Expand Down
Loading
Loading