Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into edt-2023-3
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmazNasibullin committed Mar 26, 2024
2 parents 98b4b5f + 9166ae3 commit e8408c6
Show file tree
Hide file tree
Showing 29 changed files with 718 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

### Прочие изменения

- Контекстная команда форматирования документирующего комментария в редакторе модуля #1418

### Исправленные ошибки

Expand Down Expand Up @@ -313,6 +314,7 @@
- Исправлен расчета типов возвращаемых значений функций с вызовом сервера
- Испрвление проверки типа локальной переменной в variable-value-type
- Проверка типов invocation-parameter-type-intersect при вызове метода, если существуют документирующие комментарии использует только декларированные типы
- Исправлена ошибка, при которой не выполнялась автосортировка вложенных подсистем при включенной автосортировке верхнеуровневых объектов метаданных

## 0.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,32 @@ private void appendSubordinateObjects(Collection<SortItem> result, Map<EClass, L
}
}

private void appendSubordinateSubsystems(Collection<SortItem> result, IBmTransaction transaction)
{
for (Iterator<IBmObject> iterator =
transaction.getTopObjectIterator(MdClassPackage.Literals.SUBSYSTEM); iterator.hasNext();)
{
IBmObject subsystem = iterator.next();

EList<?> subordinateSubsystems =
(EList<?>)subsystem.eGet(MdClassPackage.Literals.SUBSYSTEM__SUBSYSTEMS, false);
if (subordinateSubsystems.size() > 1)
{
String fqn = subsystem.bmGetFqn();
result.add(new SortItem(fqn, MdClassPackage.Literals.SUBSYSTEM__SUBSYSTEMS, sorter));
}
}
}

private Map<EClass, List<EReference>> getSubordinateListsToSort(Iterator<EClass> eClassIterator,
IProject project)
{
Map<EClass, List<EReference>> sortListRefs = new HashMap<>();
while (eClassIterator.hasNext())
{
EClass topObjectEClass = eClassIterator.next();
if (topObjectEClass.equals(CONFIGURATION) || !MD_OBJECT.isSuperTypeOf(topObjectEClass))
if (topObjectEClass.equals(CONFIGURATION) || topObjectEClass.equals(MdClassPackage.Literals.SUBSYSTEM)
|| !MD_OBJECT.isSuperTypeOf(topObjectEClass))
{
continue;
}
Expand Down Expand Up @@ -516,6 +534,10 @@ private void appendByConfiguration(Collection<SortItem> result, IBmTransaction t
{
result.add(new SortItem(CONFIGURATION_FQN, feature, sorter));
}
if (feature.equals(MdClassPackage.Literals.CONFIGURATION__SUBSYSTEMS))
{
appendSubordinateSubsystems(result, transaction);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0
com._1c.g5.v8.dt.bsl.comment;version="[3.0.0,4.0.0)",
com._1c.g5.v8.dt.bsl.common;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.bsl.documentation.comment;version="[4.0.0,5.0.0)",
com._1c.g5.v8.dt.bsl.formatting;version="[3.0.0,4.0.0)",
com._1c.g5.v8.dt.bsl.model;version="[5.0.0,6.0.0)",
com._1c.g5.v8.dt.bsl.model.util;version="[4.7.0,5.0.0)",
com._1c.g5.v8.dt.bsl.resource.owner;version="[2.0.0,3.0.0)",
Expand All @@ -38,6 +39,7 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0
com._1c.g5.v8.dt.core.model;version="[6.0.0,7.0.0)",
com._1c.g5.v8.dt.core.platform;version="[11.0.0,12.0.0)",
com._1c.g5.v8.dt.form.model;version="[11.1.0,12.0.0)",
com._1c.g5.v8.dt.lcore.nodemodel.util;version="[1.0.0,2.0.0)",
com._1c.g5.v8.dt.lcore.ui.texteditor;version="[1.1.0,2.0.0)",
com._1c.g5.v8.dt.mcore;version="[7.0.0,8.0.0)",
com._1c.g5.v8.dt.metadata.mdclass;version="[9.0.0,10.0.0)",
Expand Down
2 changes: 2 additions & 0 deletions bundles/com.e1c.v8codestyle.bsl.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

command.enableStrictTypes.mnemonic = E
command.enableStrictTypes.name = Enable @strict-types in modules
command.formatDocComment.mnemonic = F
command.formatDocComment.name = Format Method Documentation Comment

menu.label = Source

Expand Down
22 changes: 22 additions & 0 deletions bundles/com.e1c.v8codestyle.bsl.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@
id="com.e1c.v8codestyle.bsl.ui.commands.addStrictTypesAnnotationCommand"
name="%command.enableStrictTypes.name">
</command>
<command
id="com.e1c.v8codestyle.bsl.ui.commands.formatDocCommentCommand"
name="%command.formatDocComment.name">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
Expand Down Expand Up @@ -330,6 +334,16 @@
</reference>
</visibleWhen>
</command>
<command
commandId="com.e1c.v8codestyle.bsl.ui.commands.formatDocCommentCommand"
style="push">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com._1c.g5.v8.dt.bsl.Bsl.Editor.editable">
</reference>
</visibleWhen>
</command>
</menu>
</menuContribution>
</extension>
Expand All @@ -343,6 +357,14 @@
definitionId="com._1c.g5.v8.dt.bsl.Bsl.Editor.editable">
</reference></activeWhen>
</handler>
<handler
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.internal.bsl.ui.handlers.FormatDocCommentModuleEditorHandler"
commandId="com.e1c.v8codestyle.bsl.ui.commands.formatDocCommentCommand">
<activeWhen>
<reference
definitionId="com._1c.g5.v8.dt.bsl.Bsl.Editor.editable">
</reference></activeWhen>
</handler>
</extension>

<extension point="com.e1c.g5.v8.dt.check.fixes">
Expand Down
2 changes: 2 additions & 0 deletions bundles/com.e1c.v8codestyle.bsl.ui/plugin_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

command.enableStrictTypes.mnemonic = В
command.enableStrictTypes.name = Включить строгую типизацию (@strict-types) в модулях
command.formatDocComment.mnemonic = Ф
command.formatDocComment.name = Форматировать документирующий комментарий метода

menu.label = Исходники

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

import com._1c.g5.v8.dt.bsl.common.IBslPreferences;
import com._1c.g5.v8.dt.bsl.documentation.comment.BslMultiLineCommentDocumentationProvider;
import com._1c.g5.v8.dt.bsl.ui.contentassist.BslProposalProvider;
import com._1c.g5.v8.dt.core.filesystem.IQualifiedNameFilePathConverter;
import com._1c.g5.v8.dt.core.model.IModelEditingSupport;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider;
import com._1c.g5.wiring.AbstractServiceAwareModule;
import com.e1c.g5.v8.dt.check.qfix.IFixRepository;
import com.e1c.v8codestyle.bsl.IModuleStructureProvider;
Expand Down Expand Up @@ -59,6 +61,8 @@ protected void doConfigure()
bind(BslMultiLineCommentDocumentationProvider.class)
.toProvider(() -> rsp.get(BslMultiLineCommentDocumentationProvider.class));
bind(EObjectAtOffsetHelper.class).toProvider(() -> rsp.get(EObjectAtOffsetHelper.class));
bind(BslProposalProvider.class).toProvider(() -> rsp.get(BslProposalProvider.class));
bind(IndentTextEditorProvider.class).toProvider(() -> rsp.get(IndentTextEditorProvider.class));

// CodeStyle Services
bind(IModuleStructureProvider.class).toService();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/*******************************************************************************
* Copyright (C) 2024, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.v8codestyle.internal.bsl.ui.handlers;

import java.util.List;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.handly.buffer.BufferChange;
import org.eclipse.handly.snapshot.NonExpiringSnapshot;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.nodemodel.ICompositeNode;
import org.eclipse.xtext.nodemodel.ILeafNode;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.util.Triple;
import org.eclipse.xtext.util.Tuples;
import org.eclipse.xtext.util.concurrent.CancelableUnitOfWork;

import com._1c.g5.ides.ui.texteditor.xtext.embedded.EmbeddedEditorBuffer;
import com._1c.g5.v8.dt.bsl.common.IBslPreferences;
import com._1c.g5.v8.dt.bsl.documentation.comment.BslCommentUtils;
import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocCommentSerializer;
import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocumentationComment;
import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocumentationComment.Description;
import com._1c.g5.v8.dt.bsl.documentation.comment.BslMultiLineCommentDocumentationProvider;
import com._1c.g5.v8.dt.bsl.documentation.comment.IDescriptionPart;
import com._1c.g5.v8.dt.bsl.documentation.comment.TextPart;
import com._1c.g5.v8.dt.bsl.model.Method;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.bsl.ui.contentassist.BslProposalProvider;
import com._1c.g5.v8.dt.bsl.ui.menu.BslHandlerUtil;
import com._1c.g5.v8.dt.bsl.util.BslUtil;
import com._1c.g5.v8.dt.common.PreferenceUtils;
import com._1c.g5.v8.dt.common.StringUtils;
import com._1c.g5.v8.dt.core.model.EditingMode;
import com._1c.g5.v8.dt.core.model.IModelEditingSupport;
import com._1c.g5.v8.dt.core.platform.IV8Project;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com._1c.g5.v8.dt.lcore.nodemodel.util.CustomNodeModelUtils;
import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider;
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
import com.google.inject.Inject;

/**
* The Handler to format current method's documentation comment in opened in BSL editor.
*
* @author Dmitriy Marmyshev
*/
public class FormatDocCommentModuleEditorHandler
extends AbstractHandler
{

@Inject
private BslMultiLineCommentDocumentationProvider commentProvider;

@Inject
private BslProposalProvider proposalProvider;

@Inject
private IBslPreferences bslPreferences;

@Inject
private IV8ProjectManager v8projectManager;

@Inject
private IndentTextEditorProvider indentProvider;

@Inject
private IModelEditingSupport modelEditingSupport;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException
{
IWorkbenchPart part = HandlerUtil.getActivePart(event);

XtextEditor target = BslHandlerUtil.extractXtextEditor(part);
if (target != null)
{
final ITextViewer viewer = BslHandlerUtil.getTextViewer(target);
IXtextDocument document = target.getDocument();

Triple<Integer, Integer, String> content =
document.readOnly(new CancelableUnitOfWork<Triple<Integer, Integer, String>, XtextResource>()
{
@Override
public Triple<Integer, Integer, String> exec(XtextResource resource, CancelIndicator monitor)
throws Exception
{
if (resource.getContents() != null && !resource.getContents().isEmpty())
{
EObject obj = resource.getContents().get(0);
if (obj instanceof Module)
return getFormatedDocComment((Module)obj, viewer);
}
return null;
}

});

if (content != null && content.getFirst() > -1 && content.getSecond() > -1 && content.getThird() != null)
{
replaceDocComment(document, content.getThird(), content.getFirst(), content.getSecond());
}

}
return null;
}

private void replaceDocComment(IXtextDocument document, String comment, int insertOffset, int length)
{
TextEdit change = new ReplaceEdit(insertOffset, length, comment);

try (EmbeddedEditorBuffer buffer = new EmbeddedEditorBuffer(document))
{
NonExpiringSnapshot snapshot = new NonExpiringSnapshot(buffer);
BufferChange bufferChange = new BufferChange(change);
bufferChange.setBase(snapshot);
buffer.applyChange(bufferChange, new NullProgressMonitor());
}
catch (CoreException e)
{
UiPlugin.logError(e);
}
}

private Triple<Integer, Integer, String> getFormatedDocComment(Module module, ITextViewer viewer)
{
if (!modelEditingSupport.canEdit(module, EditingMode.DIRECT))
{
return null;
}

Method method = getNearestMethod(module, (viewer.getSelectedRange()).x);
if (method != null)
{
List<INode> lines = commentProvider.getDocumentationNodes(method);
if (lines.isEmpty())
{
return null;
}
int methodOffset = lines.get(0).getOffset();
int length = lines.get(lines.size() - 1).getEndOffset() - methodOffset;

String lineFormatter = proposalProvider.getLineFormatter(module, methodOffset, viewer.getDocument());
IV8Project project = v8projectManager.getProject(module);
boolean oldFormat = (project != null && project.getProject() != null)
? this.bslPreferences.getDocumentCommentProperties(project.getProject()).oldCommentFormat() : true;

BslDocumentationComment docComment =
BslCommentUtils.parseTemplateComment(method, oldFormat, commentProvider);
if (isEmpty(docComment.getDescription()))
{
docComment.getDescription().getParts().clear();
}

boolean isRussian = BslUtil.isRussian(method, v8projectManager);
String indent = indentProvider.getIndent();

String lineSeparator = resolveLineSeparator(project);
String comment = BslDocCommentSerializer.newBuilder()
.setOldFormat(oldFormat)
.setScriptVariant(isRussian)
.lineSeparator(lineSeparator)
.ignoreLineNumbers()
.build()
.serialize(docComment, lineFormatter, indent)
.concat(lineSeparator);

return Tuples.create(methodOffset, length, comment);
}
return null;
}

private boolean isEmpty(Description description)
{
for (IDescriptionPart part : description.getParts())
{
if (part instanceof TextPart)
{
String text = ((TextPart)part).getText();
if (StringUtils.isNotBlank(text))
{
return false;
}
}
else
{
return false;
}
}
return true;
}

private Method getNearestMethod(Module module, int offset)
{
ICompositeNode iCompositeNode = NodeModelUtils.findActualNodeFor(module);
ILeafNode node = CustomNodeModelUtils.findLeafNodeAtOffset(iCompositeNode, offset);
EObject actualObject = NodeModelUtils.findActualSemanticObjectFor(node);
if (actualObject instanceof Method)
return (Method)actualObject;
return EcoreUtil2.getContainerOfType(actualObject, Method.class);
}

private static String resolveLineSeparator(IV8Project v8project)
{
if (v8project == null)
return System.lineSeparator();
return PreferenceUtils.getLineSeparator(v8project.getProject());
}

}
Loading

0 comments on commit e8408c6

Please sign in to comment.