Skip to content

Commit

Permalink
Merge pull request #978 from 1C-Company/bugfix/977-multiple_qfix_dead…
Browse files Browse the repository at this point in the history
…lock

Блокировка UI при попытке применить одновременно несколько BSL-ных квик-фиксов #977
  • Loading branch information
vadimeg authored Feb 14, 2022
2 parents 6631851 + b5fcca9 commit 288286b
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;

import org.eclipse.emf.ecore.EObject;
Expand Down Expand Up @@ -115,8 +113,18 @@ protected void applyChanges(SingleVariantXtextBslModuleFixContext context, IFixS
IModificationContext modificationContext =
((XtextInteractiveBslModuleFixModel)fixModel).getModificationContext();

IXtextDocument document = (IXtextDocument)fixModel.getDocument();
XtextResource xtextResource = document.readOnly(new IUnitOfWork<XtextResource, XtextResource>()
{
@Override
public XtextResource exec(XtextResource state) throws Exception
{
return state;
}
});

ExternalQuickfixModification<EObject> quickFixModification = new ExternalQuickfixModification<>(issue,
EObject.class, element -> fixIssue((IXtextInteractiveBslModuleFixModel)fixModel));
EObject.class, element -> fixIssue((IXtextInteractiveBslModuleFixModel)fixModel, xtextResource));

try
{
Expand All @@ -133,29 +141,24 @@ protected void applyChanges(SingleVariantXtextBslModuleFixContext context, IFixS
}
}

private TextEdit fixIssue(IXtextInteractiveBslModuleFixModel fixModel)
private TextEdit fixIssue(IXtextInteractiveBslModuleFixModel fixModel, XtextResource xtextResource)
{
Issue issue = fixModel.getIssue();
if (issue.getOffset() == null)
{
return null;
}

List<TextEdit> textEdits = new ArrayList<>();
IXtextDocument document = (IXtextDocument)fixModel.getDocument();
document.readOnly(new IUnitOfWork.Void<XtextResource>()
try
{
@Override
public void process(XtextResource state) throws Exception
{
TextEdit te = fixIssue(state, fixModel);
if (te != null)
{
textEdits.add(te);
}
}
});
return !textEdits.isEmpty() ? textEdits.get(0) : null;
return fixIssue(xtextResource, fixModel);
}
catch (Exception e)
{
BslPlugin.log(BslPlugin.createErrorStatus("Error occured when applying quick fix", e)); //$NON-NLS-1$
}

return null;
}

private Collection<IFixChange> prepareChanges(ISingleVariantXtextModuleFixChangeDelegate changeDelegate)
Expand Down Expand Up @@ -224,8 +227,7 @@ public Class<SingleVariantModuleFixChange> getProcessedFixType()
*/
protected static final class FixConfigurer
{
private BiFunction<SingleVariantXtextBslModuleFixContext, IFixSession, Pair<String, String>>
descriptionSupplier;
private BiFunction<SingleVariantXtextBslModuleFixContext, IFixSession, Pair<String, String>> descriptionSupplier; //CHECKSTYLE.OFF: LineLength
private boolean isInteractive = true;
private String description = StringUtils.EMPTY;
private String details = StringUtils.EMPTY;
Expand Down

0 comments on commit 288286b

Please sign in to comment.