Search in sources :

Example 6 with Document

use of com.intellij.openapi.editor.Document in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoRecursiveCallMarkerProvider method collectSlowLineMarkers.

@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    Set<Integer> lines = ContainerUtil.newHashSet();
    for (PsiElement element : elements) {
        if (element instanceof GoCallExpr) {
            PsiElement resolve = GoPsiImplUtil.resolveCall((GoCallExpr) element);
            if (resolve instanceof GoFunctionOrMethodDeclaration) {
                if (isRecursiveCall(element, (GoFunctionOrMethodDeclaration) resolve)) {
                    PsiDocumentManager instance = PsiDocumentManager.getInstance(element.getProject());
                    Document document = instance.getDocument(element.getContainingFile());
                    int textOffset = element.getTextOffset();
                    if (document == null)
                        continue;
                    int lineNumber = document.getLineNumber(textOffset);
                    if (!lines.contains(lineNumber)) {
                        result.add(new RecursiveMethodCallMarkerInfo(element));
                    }
                    lines.add(lineNumber);
                }
            }
        }
    }
}
Also used : GoFunctionOrMethodDeclaration(com.goide.psi.GoFunctionOrMethodDeclaration) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) GoCallExpr(com.goide.psi.GoCallExpr) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 7 with Document

use of com.intellij.openapi.editor.Document in project go-lang-idea-plugin by go-lang-plugin-org.

the class DlvBreakpointType method isLineBreakpointAvailable.

private static boolean isLineBreakpointAvailable(@NotNull VirtualFile file, int line, @NotNull Project project) {
    Document document = FileDocumentManager.getInstance().getDocument(file);
    if (document == null || document.getLineEndOffset(line) == document.getLineStartOffset(line))
        return false;
    Checker canPutAtChecker = new Checker();
    XDebuggerUtil.getInstance().iterateLine(project, document, line, canPutAtChecker);
    return canPutAtChecker.isLineBreakpointAvailable();
}
Also used : Document(com.intellij.openapi.editor.Document)

Example 8 with Document

use of com.intellij.openapi.editor.Document in project intellij-elixir by KronicDeth.

the class Logger method excerpt.

@NotNull
private static String excerpt(@NotNull PsiFile containingFile, @NotNull PsiElement element) {
    StringBuilder excerptBuilder = new StringBuilder();
    excerptBuilder.append('\n');
    excerptBuilder.append("### Excerpt\n");
    excerptBuilder.append('\n');
    excerptBuilder.append("```\n");
    excerptBuilder.append(element.getText());
    excerptBuilder.append('\n');
    excerptBuilder.append("```\n");
    FileViewProvider fileViewProvider = containingFile.getViewProvider();
    Document document = fileViewProvider.getDocument();
    if (document != null) {
        TextRange textRange = element.getTextRange();
        int startingLine = document.getLineNumber(textRange.getStartOffset());
        int endingLine = document.getLineNumber(textRange.getEndOffset());
        excerptBuilder.append(" Line(s) ");
        excerptBuilder.append(startingLine);
        excerptBuilder.append('-');
        excerptBuilder.append(endingLine);
        VirtualFile virtualFile = containingFile.getVirtualFile();
        if (virtualFile != null) {
            excerptBuilder.append(" in ");
            excerptBuilder.append(virtualFile.getPath());
        }
        excerptBuilder.append("\n");
    }
    return excerptBuilder.toString();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileViewProvider(com.intellij.psi.FileViewProvider) TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Document

use of com.intellij.openapi.editor.Document in project intellij-elixir by KronicDeth.

the class QuoteHandler method getClosingQuote.

/*
     * Instance Methods
     */
@Nullable
@Override
public CharSequence getClosingQuote(HighlighterIterator highlighterIterator, int offset) {
    Document document = highlighterIterator.getDocument();
    CharSequence closingQuote = null;
    if (document != null) {
        if (offset >= 3) {
            String openingQuote = document.getText(new TextRange(offset - 3, offset));
            closingQuote = StackFrame.TERMINATOR_BY_PROMOTER.get(openingQuote);
            if (closingQuote != null) {
                closingQuote = "\n" + closingQuote;
            }
        }
        if (closingQuote == null && offset >= 1) {
            String openingQuote = document.getText(new TextRange(offset - 1, offset));
            closingQuote = StackFrame.TERMINATOR_BY_PROMOTER.get(openingQuote);
        }
    }
    return closingQuote;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) Document(com.intellij.openapi.editor.Document) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with Document

use of com.intellij.openapi.editor.Document in project intellij-plugins by StepicOrg.

the class ProgrammingLanguageUtils method closeStepNodeFile.

private static ArrayList<VirtualFile> closeStepNodeFile(@NotNull Project project, @NotNull StepNode targetStepNode) {
    FileDocumentManager documentManager = FileDocumentManager.getInstance();
    ArrayList<VirtualFile> needClose = new ArrayList<>();
    for (VirtualFile file : FileEditorManager.getInstance(project).getOpenFiles()) {
        if (StudyUtils.getStudyNode(project, file) != targetStepNode) {
            continue;
        }
        final Document document = ApplicationManager.getApplication().runReadAction((Computable<Document>) () -> documentManager.getDocument(file));
        if (document == null) {
            continue;
        }
        ApplicationManager.getApplication().invokeAndWait(() -> documentManager.saveDocument(document));
        needClose.add(file);
    }
    return needClose;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Document(com.intellij.openapi.editor.Document)

Aggregations

Document (com.intellij.openapi.editor.Document)1072 VirtualFile (com.intellij.openapi.vfs.VirtualFile)243 PsiFile (com.intellij.psi.PsiFile)191 Project (com.intellij.openapi.project.Project)163 NotNull (org.jetbrains.annotations.NotNull)138 Nullable (org.jetbrains.annotations.Nullable)129 TextRange (com.intellij.openapi.util.TextRange)122 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)117 PsiElement (com.intellij.psi.PsiElement)107 Editor (com.intellij.openapi.editor.Editor)104 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)56 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)45 IncorrectOperationException (com.intellij.util.IncorrectOperationException)43 IOException (java.io.IOException)42 RangeMarker (com.intellij.openapi.editor.RangeMarker)35 MockVirtualFile (com.intellij.mock.MockVirtualFile)33 ArrayList (java.util.ArrayList)32 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)30 File (java.io.File)30 List (java.util.List)29