use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-community by JetBrains.
the class ShowContainerInfoHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
PsiElement container = null;
WeakReference<LightweightHint> ref = editor.getUserData(MY_LAST_HINT_KEY);
LightweightHint hint = SoftReference.dereference(ref);
if (hint != null && hint.isVisible()) {
hint.hide();
container = hint.getUserData(CONTAINER_KEY);
if (container != null && !container.isValid()) {
container = null;
}
}
StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(file);
if (builder instanceof TreeBasedStructureViewBuilder) {
StructureViewModel model = ((TreeBasedStructureViewBuilder) builder).createStructureViewModel(editor);
boolean goOneLevelUp = true;
try {
if (container == null) {
goOneLevelUp = false;
Object element = model.getCurrentEditorElement();
if (element instanceof PsiElement) {
container = (PsiElement) element;
}
}
} finally {
model.dispose();
}
while (true) {
if (container == null || container instanceof PsiFile) {
return;
}
if (goOneLevelUp) {
goOneLevelUp = false;
} else {
if (!isDeclarationVisible(container, editor)) {
break;
}
}
container = container.getParent();
while (container != null && DeclarationRangeUtil.getPossibleDeclarationAtRange(container) == null) {
container = container.getParent();
if (container instanceof PsiFile)
return;
}
}
}
if (container == null) {
return;
}
final TextRange range = DeclarationRangeUtil.getPossibleDeclarationAtRange(container);
if (range == null) {
return;
}
final PsiElement _container = container;
ApplicationManager.getApplication().invokeLater(() -> {
LightweightHint hint1 = EditorFragmentComponent.showEditorFragmentHint(editor, range, true, true);
if (hint1 != null) {
hint1.putUserData(CONTAINER_KEY, _container);
editor.putUserData(MY_LAST_HINT_KEY, new WeakReference<>(hint1));
}
});
}
use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-elixir by KronicDeth.
the class Factory method structureViewBuilder.
@Nullable
public static StructureViewBuilder structureViewBuilder(@NotNull final PsiFile psiFile) {
StructureViewBuilder structureViewBuilder = null;
if (psiFile instanceof ElixirFile) {
final ElixirFile elixirFile = (ElixirFile) psiFile;
structureViewBuilder = new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new Model(elixirFile, editor);
}
@Override
public boolean isRootNodeShown() {
return false;
}
};
}
return structureViewBuilder;
}
use of com.intellij.ide.structureView.StructureViewBuilder in project intellij-plugins by JetBrains.
the class HbStructureViewFactory method getStructureViewBuilder.
@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(@NotNull final PsiFile psiFile) {
return new TemplateLanguageStructureViewBuilder(psiFile) {
@Override
protected StructureViewComposite.StructureViewDescriptor createMainView(FileEditor fileEditor, PsiFile mainFile) {
if (!psiFile.isValid())
return null;
final StructureViewBuilder builder = new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new HbStructureViewModel((HbPsiFile) psiFile, editor);
}
};
StructureView structureView = builder.createStructureView(fileEditor, psiFile.getProject());
return new StructureViewComposite.StructureViewDescriptor(HbLanguage.INSTANCE.getDisplayName(), structureView, HbFileType.INSTANCE.getIcon());
}
};
}
Aggregations