use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class CreateVariableFix method invoke.
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
editor = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor;
XmlTag tag = PsiTreeUtil.getContextOfType(myReference, XmlTag.class, true);
if (tag == null)
return;
XmlTag xmlTag = tag.createChildTag("variable", XsltSupport.XSLT_NS, null, false);
xmlTag.setAttribute("name", myReference.getReferencedName());
xmlTag.setAttribute("select", "dummy");
final XmlAttribute select = xmlTag.getAttribute("select", null);
assert select != null;
final PsiElement dummy = XsltSupport.getAttValueToken(select);
assert dummy != null;
final TemplateBuilderImpl builder = createTemplateBuilder(xmlTag);
builder.replaceElement(dummy, new MacroCallNode(new CompleteMacro()));
builder.setEndVariableAfter(select);
final Template template = builder.buildTemplate();
template.addTextSegment("\n");
template.setToIndent(true);
final XmlTag insertionPoint = findVariableInsertionPoint(tag);
moveTo(editor, insertionPoint);
TemplateManager.getInstance(project).startTemplate(editor, template);
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class LightDaemonAnalyzerTestCase method doHighlighting.
@NotNull
protected List<HighlightInfo> doHighlighting() {
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
TIntArrayList toIgnoreList = new TIntArrayList();
if (!doFolding()) {
toIgnoreList.add(Pass.UPDATE_FOLDING);
}
if (!doInspections()) {
toIgnoreList.add(Pass.LOCAL_INSPECTIONS);
toIgnoreList.add(Pass.WHOLE_FILE_LOCAL_INSPECTIONS);
}
int[] toIgnore = toIgnoreList.isEmpty() ? ArrayUtil.EMPTY_INT_ARRAY : toIgnoreList.toNativeArray();
Editor editor = getEditor();
PsiFile file = getFile();
if (editor instanceof EditorWindow) {
editor = ((EditorWindow) editor).getDelegate();
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
}
return CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, toIgnore, false);
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class PassExecutorService method submitPasses.
void submitPasses(@NotNull Map<FileEditor, HighlightingPass[]> passesMap, @NotNull DaemonProgressIndicator updateProgress) {
if (isDisposed())
return;
// null keys are ok
MultiMap<Document, FileEditor> documentToEditors = MultiMap.createSet();
MultiMap<FileEditor, TextEditorHighlightingPass> documentBoundPasses = MultiMap.createSmart();
MultiMap<FileEditor, EditorBoundHighlightingPass> editorBoundPasses = MultiMap.createSmart();
List<Pair<FileEditor, TextEditorHighlightingPass>> passesWithNoDocuments = new ArrayList<>();
Set<VirtualFile> vFiles = new HashSet<>();
for (Map.Entry<FileEditor, HighlightingPass[]> entry : passesMap.entrySet()) {
FileEditor fileEditor = entry.getKey();
HighlightingPass[] passes = entry.getValue();
Document document;
if (fileEditor instanceof TextEditor) {
Editor editor = ((TextEditor) fileEditor).getEditor();
LOG.assertTrue(!(editor instanceof EditorWindow));
document = editor.getDocument();
} else {
VirtualFile virtualFile = ((FileEditorManagerEx) FileEditorManager.getInstance(myProject)).getFile(fileEditor);
document = virtualFile == null ? null : FileDocumentManager.getInstance().getDocument(virtualFile);
}
if (document != null) {
vFiles.add(FileDocumentManager.getInstance().getFile(document));
}
int prevId = 0;
for (final HighlightingPass pass : passes) {
if (pass instanceof EditorBoundHighlightingPass) {
EditorBoundHighlightingPass editorPass = (EditorBoundHighlightingPass) pass;
// have to make ids unique for this document
editorPass.setId(nextPassId.incrementAndGet());
editorBoundPasses.putValue(fileEditor, editorPass);
} else {
TextEditorHighlightingPass textEditorHighlightingPass = convertToTextHighlightingPass(pass, document, nextPassId, prevId);
document = textEditorHighlightingPass.getDocument();
documentBoundPasses.putValue(fileEditor, textEditorHighlightingPass);
if (document == null) {
passesWithNoDocuments.add(Pair.create(fileEditor, textEditorHighlightingPass));
} else {
documentToEditors.putValue(document, fileEditor);
}
prevId = textEditorHighlightingPass.getId();
}
}
}
List<ScheduledPass> freePasses = new ArrayList<>(documentToEditors.size() * 5);
List<ScheduledPass> dependentPasses = new ArrayList<>(documentToEditors.size() * 10);
// (fileEditor, passId) -> created pass
Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted = new THashMap<>(passesMap.size());
final AtomicInteger threadsToStartCountdown = new AtomicInteger(0);
for (Map.Entry<Document, Collection<FileEditor>> entry : documentToEditors.entrySet()) {
Collection<FileEditor> fileEditors = entry.getValue();
Document document = entry.getKey();
FileEditor preferredFileEditor = getPreferredFileEditor(document, fileEditors);
List<TextEditorHighlightingPass> passes = (List<TextEditorHighlightingPass>) documentBoundPasses.get(preferredFileEditor);
if (passes.isEmpty()) {
continue;
}
sortById(passes);
for (TextEditorHighlightingPass currentPass : passes) {
createScheduledPass(preferredFileEditor, currentPass, toBeSubmitted, passes, freePasses, dependentPasses, updateProgress, threadsToStartCountdown);
}
}
for (Map.Entry<FileEditor, Collection<EditorBoundHighlightingPass>> entry : editorBoundPasses.entrySet()) {
FileEditor fileEditor = entry.getKey();
Collection<EditorBoundHighlightingPass> createdEditorBoundPasses = entry.getValue();
List<TextEditorHighlightingPass> createdDocumentBoundPasses = (List<TextEditorHighlightingPass>) documentBoundPasses.get(fileEditor);
List<TextEditorHighlightingPass> allCreatedPasses = new ArrayList<>(createdDocumentBoundPasses);
allCreatedPasses.addAll(createdEditorBoundPasses);
for (EditorBoundHighlightingPass pass : createdEditorBoundPasses) {
createScheduledPass(fileEditor, pass, toBeSubmitted, allCreatedPasses, freePasses, dependentPasses, updateProgress, threadsToStartCountdown);
}
}
for (Pair<FileEditor, TextEditorHighlightingPass> pair : passesWithNoDocuments) {
FileEditor fileEditor = pair.first;
TextEditorHighlightingPass pass = pair.second;
createScheduledPass(fileEditor, pass, toBeSubmitted, ContainerUtil.emptyList(), freePasses, dependentPasses, updateProgress, threadsToStartCountdown);
}
if (CHECK_CONSISTENCY && !ApplicationInfoImpl.isInStressTest()) {
assertConsistency(freePasses, toBeSubmitted, threadsToStartCountdown);
}
log(updateProgress, null, vFiles + " ----- starting " + threadsToStartCountdown.get(), freePasses);
for (ScheduledPass dependentPass : dependentPasses) {
mySubmittedPasses.put(dependentPass, Job.NULL_JOB);
}
for (ScheduledPass freePass : freePasses) {
submit(freePass);
}
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class FoldingUpdate method updateInjectedFoldRegions.
@Nullable
public static Runnable updateInjectedFoldRegions(@NotNull final Editor editor, @NotNull final PsiFile file, final boolean applyDefaultState) {
if (file instanceof PsiCompiledElement)
return null;
ApplicationManager.getApplication().assertReadAccessAllowed();
final Project project = file.getProject();
Document document = editor.getDocument();
LOG.assertTrue(!PsiDocumentManager.getInstance(project).isUncommited(document));
final FoldingModel foldingModel = editor.getFoldingModel();
final long timeStamp = document.getModificationStamp();
Object lastTimeStamp = editor.getUserData(LAST_UPDATE_INJECTED_STAMP_KEY);
if (lastTimeStamp instanceof Long && ((Long) lastTimeStamp).longValue() == timeStamp)
return null;
List<DocumentWindow> injectedDocuments = InjectedLanguageUtil.getCachedInjectedDocuments(file);
if (injectedDocuments.isEmpty())
return null;
final List<EditorWindow> injectedEditors = new ArrayList<>();
final List<PsiFile> injectedFiles = new ArrayList<>();
final List<FoldingMap> maps = new ArrayList<>();
for (final DocumentWindow injectedDocument : injectedDocuments) {
if (!injectedDocument.isValid()) {
continue;
}
InjectedLanguageUtil.enumerate(injectedDocument, file, (injectedFile, places) -> {
if (!injectedFile.isValid())
return;
Editor injectedEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injectedFile);
if (!(injectedEditor instanceof EditorWindow))
return;
injectedEditors.add((EditorWindow) injectedEditor);
injectedFiles.add(injectedFile);
final FoldingMap map = new FoldingMap();
maps.add(map);
getFoldingsFor(injectedFile, injectedEditor.getDocument(), map, false);
});
}
return () -> {
final ArrayList<Runnable> updateOperations = new ArrayList<>(injectedEditors.size());
for (int i = 0; i < injectedEditors.size(); i++) {
EditorWindow injectedEditor = injectedEditors.get(i);
PsiFile injectedFile = injectedFiles.get(i);
if (!injectedEditor.getDocument().isValid())
continue;
FoldingMap map = maps.get(i);
updateOperations.add(new UpdateFoldRegionsOperation(project, injectedEditor, injectedFile, map, applyDefaultState ? EXCEPT_CARET_REGION : NO, !applyDefaultState, true));
}
foldingModel.runBatchFoldingOperation(() -> {
for (Runnable operation : updateOperations) {
operation.run();
}
});
editor.putUserData(LAST_UPDATE_INJECTED_STAMP_KEY, timeStamp);
};
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class BraceHighlightingHandler method getHighlightersList.
@NotNull
private List<RangeHighlighter> getHighlightersList() {
// braces are highlighted across the whole editor, not in each injected editor separately
Editor editor = myEditor instanceof EditorWindow ? ((EditorWindow) myEditor).getDelegate() : myEditor;
List<RangeHighlighter> highlighters = editor.getUserData(BRACE_HIGHLIGHTERS_IN_EDITOR_VIEW_KEY);
if (highlighters == null) {
highlighters = new ArrayList<>();
editor.putUserData(BRACE_HIGHLIGHTERS_IN_EDITOR_VIEW_KEY, highlighters);
}
return highlighters;
}
Aggregations