use of com.github._1c_syntax.bsl.languageserver.context.FileType in project bsl-language-server by 1c-syntax.
the class GenerateStandardRegionsSupplier method getRegionsLanguage.
private ScriptVariant getRegionsLanguage(DocumentContext documentContext, FileType fileType) {
ScriptVariant regionsLanguage;
Configuration configuration = documentContext.getServerContext().getConfiguration();
if (configuration.getConfigurationSource() == ConfigurationSource.EMPTY || fileType == FileType.OS) {
regionsLanguage = getScriptVariantFromConfigLanguage();
} else {
regionsLanguage = documentContext.getServerContext().getConfiguration().getScriptVariant();
}
return regionsLanguage;
}
use of com.github._1c_syntax.bsl.languageserver.context.FileType 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);
}
use of com.github._1c_syntax.bsl.languageserver.context.FileType 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();
}
}
use of com.github._1c_syntax.bsl.languageserver.context.FileType in project bsl-language-server by 1c-syntax.
the class DiagnosticsConfiguration method inScope.
private static boolean inScope(DiagnosticInfo diagnosticInfo, FileType fileType) {
DiagnosticScope scope = diagnosticInfo.getScope();
DiagnosticScope fileScope;
if (fileType == FileType.OS) {
fileScope = DiagnosticScope.OS;
} else {
fileScope = DiagnosticScope.BSL;
}
return scope == DiagnosticScope.ALL || scope == fileScope;
}
use of com.github._1c_syntax.bsl.languageserver.context.FileType 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;
}
Aggregations