Search in sources :

Example 1 with ModuleType

use of com.github._1c_syntax.mdclasses.mdo.support.ModuleType in project bsl-language-server by 1c-syntax.

the class ModuleSymbolComputer method getName.

private static String getName(DocumentContext documentContext) {
    String name = MdoRefBuilder.getMdoRef(documentContext);
    ModuleType moduleType = documentContext.getModuleType();
    if (MODULE_TYPES_TO_APPEND_NAME.contains(moduleType)) {
        name += "." + moduleType.name();
    }
    return name;
}
Also used : ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType)

Example 2 with ModuleType

use of com.github._1c_syntax.mdclasses.mdo.support.ModuleType in project bsl-language-server by 1c-syntax.

the class ServerContextTest method testConfigurationMetadata.

@Test
void testConfigurationMetadata() {
    Path path = Absolute.path(PATH_TO_METADATA);
    serverContext.setConfigurationRoot(path);
    Configuration configurationMetadata = serverContext.getConfiguration();
    assertThat(configurationMetadata).isNotNull();
    assertThat(configurationMetadata.getScriptVariant()).isEqualTo(ScriptVariant.RUSSIAN);
    assertThat(configurationMetadata.getConfigurationSource()).isEqualTo(ConfigurationSource.DESIGNER);
    assertThat(configurationMetadata.getCompatibilityMode().getMinor()).isEqualTo(3);
    assertThat(configurationMetadata.getCompatibilityMode().getVersion()).isEqualTo(10);
    File file = new File(PATH_TO_METADATA, PATH_TO_MODULE_FILE);
    ModuleType type = configurationMetadata.getModuleType(Absolute.uri(file.toURI()));
    assertThat(type).isEqualTo(ModuleType.CommonModule);
}
Also used : Path(java.nio.file.Path) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) Configuration(com.github._1c_syntax.mdclasses.Configuration) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ModuleType

use of com.github._1c_syntax.mdclasses.mdo.support.ModuleType in project bsl-language-server by 1c-syntax.

the class GenerateStandardRegionsSupplier method getCodeActions.

/**
 * При необходимости создает {@code CodeAction} для генерации отсутствующих
 * стандартных областей 1С
 *
 * @param params          параметры вызова генерации {@code codeAction}
 * @param documentContext представление программного модуля
 * @return {@code List<CodeAction>} если модуль не содержит всех стандартных областей,
 * пустой {@code List} если генерация областей не требуется
 */
@Override
public List<CodeAction> getCodeActions(CodeActionParams params, DocumentContext documentContext) {
    ModuleType moduleType = documentContext.getModuleType();
    FileType fileType = documentContext.getFileType();
    ScriptVariant regionsLanguage = getRegionsLanguage(documentContext, fileType);
    Set<String> neededStandardRegions;
    if (fileType == FileType.BSL) {
        neededStandardRegions = Regions.getStandardRegionsNamesByModuleType(moduleType, regionsLanguage);
    } else {
        neededStandardRegions = Regions.getOneScriptStandardRegions(regionsLanguage);
    }
    Set<String> documentRegionsNames = documentContext.getSymbolTree().getModuleLevelRegions().stream().map(RegionSymbol::getName).collect(Collectors.toSet());
    neededStandardRegions.removeAll(documentRegionsNames);
    if (neededStandardRegions.isEmpty()) {
        return Collections.emptyList();
    }
    String regionFormat = regionsLanguage == ScriptVariant.ENGLISH ? "#Region %s%n%n#EndRegion%n" : "#Область %s%n%n#КонецОбласти%n";
    String result = neededStandardRegions.stream().map(s -> String.format(regionFormat, s)).collect(Collectors.joining("\n"));
    TextEdit textEdit = new TextEdit(calculateFixRange(params.getRange()), result);
    WorkspaceEdit edit = new WorkspaceEdit();
    Map<String, List<TextEdit>> changes = Map.of(documentContext.getUri().toString(), Collections.singletonList(textEdit));
    edit.setChanges(changes);
    CodeAction codeAction = new CodeAction("Generate missing regions");
    codeAction.setDiagnostics(new ArrayList<>());
    codeAction.setKind(CodeActionKind.Refactor);
    codeAction.setEdit(edit);
    return List.of(codeAction);
}
Also used : ScriptVariant(com.github._1c_syntax.mdclasses.mdo.support.ScriptVariant) Language(com.github._1c_syntax.bsl.languageserver.configuration.Language) Range(org.eclipse.lsp4j.Range) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Regions(com.github._1c_syntax.bsl.languageserver.utils.Regions) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) ArrayList(java.util.ArrayList) RegionSymbol(com.github._1c_syntax.bsl.languageserver.context.symbol.RegionSymbol) Configuration(com.github._1c_syntax.mdclasses.Configuration) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) TextEdit(org.eclipse.lsp4j.TextEdit) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) ConfigurationSource(com.github._1c_syntax.mdclasses.common.ConfigurationSource) Map(java.util.Map) Position(org.eclipse.lsp4j.Position) CodeAction(org.eclipse.lsp4j.CodeAction) Set(java.util.Set) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) List(java.util.List) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) CodeActionKind(org.eclipse.lsp4j.CodeActionKind) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) TextEdit(org.eclipse.lsp4j.TextEdit) CodeAction(org.eclipse.lsp4j.CodeAction) ScriptVariant(com.github._1c_syntax.mdclasses.mdo.support.ScriptVariant) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ModuleType

use of com.github._1c_syntax.mdclasses.mdo.support.ModuleType in project bsl-language-server by 1c-syntax.

the class DiagnosticsConfiguration method diagnostics.

@Bean
@Scope("prototype")
public List<BSLDiagnostic> diagnostics(DocumentContext documentContext) {
    Collection<DiagnosticInfo> diagnosticInfos = diagnosticInfos();
    DiagnosticsOptions diagnosticsOptions = configuration.getDiagnosticsOptions();
    if (needToComputeDiagnostics(documentContext, diagnosticsOptions)) {
        FileType fileType = documentContext.getFileType();
        CompatibilityMode compatibilityMode = documentContext.getServerContext().getConfiguration().getCompatibilityMode();
        ModuleType moduleType = documentContext.getModuleType();
        return diagnosticInfos.stream().filter(diagnosticInfo -> isEnabled(diagnosticInfo, diagnosticsOptions)).filter(info -> inScope(info, fileType)).filter(info -> correctModuleType(info, moduleType, fileType)).filter(info -> passedCompatibilityMode(info, compatibilityMode)).map(DiagnosticInfo::getDiagnosticClass).map(diagnosticObjectProvider::get).collect(Collectors.toList());
    } else {
        return Collections.emptyList();
    }
}
Also used : SupportConfiguration(com.github._1c_syntax.mdclasses.supportconf.SupportConfiguration) RequiredArgsConstructor(lombok.RequiredArgsConstructor) DocumentContext(com.github._1c_syntax.bsl.languageserver.context.DocumentContext) Scope(org.springframework.context.annotation.Scope) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) DiagnosticScope(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope) LanguageServerConfiguration(com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration) DiagnosticCompatibilityMode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode) Map(java.util.Map) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Mode(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.Mode) SupportVariant(com.github._1c_syntax.mdclasses.supportconf.SupportVariant) Collection(java.util.Collection) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) BSLDiagnostic(com.github._1c_syntax.bsl.languageserver.diagnostics.BSLDiagnostic) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) SkipSupport(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.SkipSupport) Lookup(org.springframework.beans.factory.annotation.Lookup) Bean(org.springframework.context.annotation.Bean) CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) Comparator(java.util.Comparator) Collections(java.util.Collections) DiagnosticsOptions(com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions) ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType) FileType(com.github._1c_syntax.bsl.languageserver.context.FileType) DiagnosticCompatibilityMode(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticCompatibilityMode) CompatibilityMode(com.github._1c_syntax.mdclasses.common.CompatibilityMode) DiagnosticInfo(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticInfo) Scope(org.springframework.context.annotation.Scope) DiagnosticScope(com.github._1c_syntax.bsl.languageserver.diagnostics.metadata.DiagnosticScope) Bean(org.springframework.context.annotation.Bean)

Example 5 with ModuleType

use of com.github._1c_syntax.mdclasses.mdo.support.ModuleType in project bsl-language-server by 1c-syntax.

the class DiagnosticsConfiguration method correctModuleType.

private static boolean correctModuleType(DiagnosticInfo diagnosticInfo, ModuleType moduletype, FileType fileType) {
    if (fileType == FileType.OS) {
        return true;
    }
    ModuleType[] diagnosticModules = diagnosticInfo.getModules();
    if (diagnosticModules.length == 0) {
        return true;
    }
    boolean contain = false;
    for (ModuleType module : diagnosticModules) {
        if (module == moduletype) {
            contain = true;
            break;
        }
    }
    return contain;
}
Also used : ModuleType(com.github._1c_syntax.mdclasses.mdo.support.ModuleType)

Aggregations

ModuleType (com.github._1c_syntax.mdclasses.mdo.support.ModuleType)8 DocumentContext (com.github._1c_syntax.bsl.languageserver.context.DocumentContext)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 LanguageServerConfiguration (com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration)2 FileType (com.github._1c_syntax.bsl.languageserver.context.FileType)2 Configuration (com.github._1c_syntax.mdclasses.Configuration)2 Collection (java.util.Collection)2 Set (java.util.Set)2 RequiredArgsConstructor (lombok.RequiredArgsConstructor)2 Position (org.eclipse.lsp4j.Position)2 Range (org.eclipse.lsp4j.Range)2 Component (org.springframework.stereotype.Component)2 Language (com.github._1c_syntax.bsl.languageserver.configuration.Language)1 DiagnosticsOptions (com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.DiagnosticsOptions)1 Mode (com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.Mode)1 SkipSupport (com.github._1c_syntax.bsl.languageserver.configuration.diagnostics.SkipSupport)1 ServerContext (com.github._1c_syntax.bsl.languageserver.context.ServerContext)1