com.intellij.psi.text.BlockSupport Java Examples

The following examples show how to use com.intellij.psi.text.BlockSupport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GLSLParser.java    From glsl4idea with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@NotNull
public ASTNode parse(@NotNull IElementType root, @NotNull PsiBuilder builder) {
    try {
        parseLight(root, builder);
        return builder.getTreeBuilt();
    } catch (ProcessCanceledException | BlockSupport.ReparsedSuccessfullyException expected) {
        // Not a problem
        throw expected;
    } catch (Exception ex) {
        crashing = true;
        Logger.getLogger("GLSLParser").log(Level.WARNING, "Crashed while trying to parse "+root, ex);
        throw ex;
    }
}
 
Example #2
Source File: PomModelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Runnable reparseFile(@Nonnull final PsiFile file, @Nonnull FileElement treeElement, @Nonnull CharSequence newText) {
  TextRange changedPsiRange = ChangedPsiRangeUtil.getChangedPsiRange(file, treeElement, newText);
  if (changedPsiRange == null) return null;

  final DiffLog log = BlockSupport.getInstance(myProject).reparseRange(file, treeElement, changedPsiRange, newText, new EmptyProgressIndicator(), treeElement.getText());
  return () -> runTransaction(new PomTransactionBase(file, getModelAspect(TreeAspect.class)) {
    @Override
    public PomModelEvent runInner() throws IncorrectOperationException {
      return new TreeAspectEvent(PomModelImpl.this, log.performActualPsiChange(file));
    }
  });
}
 
Example #3
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public PsiBuilderImpl(@Nonnull Project project,
                      @Nonnull ParserDefinition parserDefinition,
                      @Nonnull LanguageVersion languageVersion,
                      @Nonnull Lexer lexer,
                      @Nonnull ASTNode chameleon,
                      @Nonnull CharSequence text) {
  this(project, SharedImplUtil.getContainingFile(chameleon), languageVersion, parserDefinition, lexer, SharedImplUtil.findCharTableByTree(chameleon), text,
       Pair.getFirst(chameleon.getUserData(BlockSupport.TREE_TO_BE_REPARSED)), Pair.getSecond(chameleon.getUserData(BlockSupport.TREE_TO_BE_REPARSED)), null,
       chameleon);
}
 
Example #4
Source File: PsiBuilderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void checkTreeDepth(final int maxDepth, final boolean isFileRoot) {
  if (myFile == null) return;
  final PsiFile file = myFile.getOriginalFile();
  final Boolean flag = file.getUserData(BlockSupport.TREE_DEPTH_LIMIT_EXCEEDED);
  if (maxDepth > BlockSupport.INCREMENTAL_REPARSE_DEPTH_LIMIT) {
    if (!Boolean.TRUE.equals(flag)) {
      file.putUserData(BlockSupport.TREE_DEPTH_LIMIT_EXCEEDED, Boolean.TRUE);
    }
  }
  else if (isFileRoot && flag != null) {
    file.putUserData(BlockSupport.TREE_DEPTH_LIMIT_EXCEEDED, null);
  }
}
 
Example #5
Source File: DocumentCommitThread.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void assertAfterCommit(@Nonnull Document document, @Nonnull final PsiFile file, @Nonnull FileElement oldFileNode) {
  if (oldFileNode.getTextLength() != document.getTextLength()) {
    final String documentText = document.getText();
    String fileText = file.getText();
    boolean sameText = Comparing.equal(fileText, documentText);
    String errorMessage = "commitDocument() left PSI inconsistent: " +
                          DebugUtil.diagnosePsiDocumentInconsistency(file, document) +
                          "; node.length=" +
                          oldFileNode.getTextLength() +
                          "; doc.text" +
                          (sameText ? "==" : "!=") +
                          "file.text" +
                          "; file name:" +
                          file.getName() +
                          "; type:" +
                          file.getFileType() +
                          "; lang:" +
                          file.getLanguage();
    //PluginException.logPluginError(LOG, errorMessage, null, file.getLanguage().getClass());
    LOG.error(errorMessage);

    file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE);
    try {
      BlockSupport blockSupport = BlockSupport.getInstance(file.getProject());
      final DiffLog diffLog = blockSupport.reparseRange(file, file.getNode(), new TextRange(0, documentText.length()), documentText, createProgressIndicator(), oldFileNode.getText());
      diffLog.doActualPsiChange(file);

      if (oldFileNode.getTextLength() != document.getTextLength()) {
        LOG.error("PSI is broken beyond repair in: " + file);
        //PluginException.logPluginError(LOG, "PSI is broken beyond repair in: " + file, null, file.getLanguage().getClass());
      }
    }
    finally {
      file.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, null);
    }
  }
}
 
Example #6
Source File: PsiDocumentManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void bulkUpdateStarting(@Nonnull Document document) {
  document.putUserData(BlockSupport.DO_NOT_REPARSE_INCREMENTALLY, Boolean.TRUE);
}