Search in sources :

Example 21 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method setupEditorForInjectedLanguage.

private void setupEditorForInjectedLanguage() {
    Editor editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(myEditor, getFile());
    if (editor instanceof EditorWindow) {
        myFile = ((EditorWindow) editor).getInjectedFile().getViewProvider().getVirtualFile();
        myEditor = editor;
    }
}
Also used : com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) EditorWindow(com.intellij.injected.editor.EditorWindow)

Example 22 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method getAvailableIntentions.

@Override
@NotNull
public List<IntentionAction> getAvailableIntentions() {
    doHighlighting();
    PsiFile file = getFile();
    Editor editor = getEditor();
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
        file = InjectedLanguageUtil.getTopLevelFile(file);
    }
    assertNotNull(file);
    return getAvailableIntentions(editor, file);
}
Also used : com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) EditorWindow(com.intellij.injected.editor.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class CodeInsightTestFixtureImpl method checkResult.

private void checkResult(@NotNull String expectedFile, boolean stripTrailingSpaces, @NotNull SelectionAndCaretMarkupLoader loader, @NotNull String actualText) {
    assertInitialized();
    Project project = getProject();
    Editor editor = getEditor();
    if (editor instanceof EditorWindow) {
        editor = ((EditorWindow) editor).getDelegate();
    }
    UsefulTestCase.doPostponedFormatting(getProject());
    if (stripTrailingSpaces) {
        actualText = stripTrailingSpaces(actualText);
    }
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    String newFileText1 = loader.newFileText;
    if (stripTrailingSpaces) {
        newFileText1 = stripTrailingSpaces(newFileText1);
    }
    actualText = StringUtil.convertLineSeparators(actualText);
    if (!Comparing.equal(newFileText1, actualText)) {
        if (loader.filePath != null) {
            throw new FileComparisonFailure(expectedFile, newFileText1, actualText, loader.filePath);
        } else {
            throw new ComparisonFailure(expectedFile, newFileText1, actualText);
        }
    }
    EditorTestUtil.verifyCaretAndSelectionState(editor, loader.caretState, expectedFile);
}
Also used : Project(com.intellij.openapi.project.Project) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure) ComparisonFailure(junit.framework.ComparisonFailure) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) EditorWindow(com.intellij.injected.editor.EditorWindow) FileComparisonFailure(com.intellij.rt.execution.junit.FileComparisonFailure)

Example 24 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class EditorTestUtil method createEditorContext.

@NotNull
private static DataContext createEditorContext(@NotNull Editor editor) {
    Object hostEditor = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor;
    Map<String, Object> map = ContainerUtil.newHashMap(Pair.create(CommonDataKeys.HOST_EDITOR.getName(), hostEditor), Pair.createNonNull(CommonDataKeys.EDITOR.getName(), editor));
    DataContext parent = DataManager.getInstance().getDataContext(editor.getContentComponent());
    return SimpleDataContext.getSimpleContext(map, parent);
}
Also used : SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) EditorWindow(com.intellij.injected.editor.EditorWindow) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with EditorWindow

use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.

the class CompletionProgressIndicator method stop.

@Override
public void stop() {
    super.stop();
    myQueue.cancelAllUpdates();
    myFreezeSemaphore.up();
    myFinishSemaphore.up();
    GuiUtils.invokeLaterIfNeeded(() -> {
        final CompletionPhase phase = CompletionServiceImpl.getCompletionPhase();
        if (!(phase instanceof CompletionPhase.BgCalculation) || phase.indicator != this)
            return;
        LOG.assertTrue(!getProject().isDisposed(), "project disposed");
        if (myEditor.isDisposed()) {
            myLookup.hideLookup(false);
            CompletionServiceImpl.setCompletionPhase(CompletionPhase.NoCompletion);
            return;
        }
        if (myEditor instanceof EditorWindow) {
            LOG.assertTrue(((EditorWindow) myEditor).getInjectedFile().isValid(), "injected file !valid");
            LOG.assertTrue(((DocumentWindow) myEditor.getDocument()).isValid(), "docWindow !valid");
        }
        PsiFile file = myLookup.getPsiFile();
        LOG.assertTrue(file == null || file.isValid(), "file !valid");
        myLookup.setCalculating(false);
        if (myCount == 0) {
            myLookup.hideLookup(false);
            if (!isAutopopupCompletion()) {
                final CompletionProgressIndicator current = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
                LOG.assertTrue(current == null, current + "!=" + this);
                handleEmptyLookup(!((CompletionPhase.BgCalculation) phase).modifiersChanged);
            }
        } else {
            CompletionServiceImpl.setCompletionPhase(new CompletionPhase.ItemsCalculated(this));
            updateLookup();
        }
    }, myQueue.getModalityState());
}
Also used : PsiFile(com.intellij.psi.PsiFile) EditorWindow(com.intellij.injected.editor.EditorWindow)

Aggregations

EditorWindow (com.intellij.injected.editor.EditorWindow)44 Editor (com.intellij.openapi.editor.Editor)15 TextRange (com.intellij.openapi.util.TextRange)10 Project (com.intellij.openapi.project.Project)9 Document (com.intellij.openapi.editor.Document)8 PsiFile (com.intellij.psi.PsiFile)8 NotNull (org.jetbrains.annotations.NotNull)8 PsiElement (com.intellij.psi.PsiElement)7 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)5 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)4 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)3 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)3 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)3 ArrayList (java.util.ArrayList)3 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)2 DocumentWindow (com.intellij.injected.editor.DocumentWindow)2 InjectedCaret (com.intellij.injected.editor.InjectedCaret)2 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2