mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
allow customization of stub root for multi-root psi files (CR-IC-1700)
This commit is contained in:
@@ -100,4 +100,7 @@ public interface FileViewProvider extends Cloneable, UserDataHolder {
|
||||
|
||||
@NotNull
|
||||
FileViewProvider createCopy(@NotNull VirtualFile copy);
|
||||
|
||||
@NotNull
|
||||
PsiFile getStubBindingRoot();
|
||||
}
|
||||
|
||||
@@ -162,6 +162,12 @@ public class DummyHolderViewProvider extends UserDataHolderBase implements FileV
|
||||
throw new RuntimeException("Clone is not supported for DummyHolderProviders. Use DummyHolder clone directly.");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiFile getStubBindingRoot() {
|
||||
return getPsi(getBaseLanguage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement findElementAt(final int offset) {
|
||||
final LeafElement element = ((PsiFileImpl)getPsi(getBaseLanguage())).calcTreeElement().findLeafElementAt(offset);
|
||||
|
||||
@@ -578,4 +578,12 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi
|
||||
return myModificationStamp;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiFile getStubBindingRoot() {
|
||||
final PsiFile psi = getPsi(getBaseLanguage());
|
||||
assert psi != null;
|
||||
return psi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Pair<StubBasedPsiElementBase, CompositeElement>> calcStubAstBindings(final ASTNode root, final Document cachedDocument) {
|
||||
private List<Pair<StubBasedPsiElementBase, CompositeElement>> calcStubAstBindings(final ASTNode root, final Document cachedDocument) {
|
||||
final StubTree stubTree = derefStub();
|
||||
if (stubTree == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -695,6 +695,12 @@ public abstract class PsiFileImpl extends ElementBase implements PsiFileEx, PsiF
|
||||
final VirtualFile vFile = getVirtualFile();
|
||||
if (!(vFile instanceof VirtualFileWithId)) return null;
|
||||
|
||||
final PsiFile stubBindingRoot = getViewProvider().getStubBindingRoot();
|
||||
if (stubBindingRoot != this) {
|
||||
LOG.error("Attempted to create stubs for non-root file: " + this + ", stub binding root: " + stubBindingRoot);
|
||||
return null;
|
||||
}
|
||||
|
||||
ObjectStubTree tree = StubTreeLoader.getInstance().readOrBuild(getProject(), vFile, this);
|
||||
if (!(tree instanceof StubTree)) return null;
|
||||
StubTree stubHolder = (StubTree)tree;
|
||||
|
||||
@@ -56,6 +56,7 @@ public class StubTreeBuilder {
|
||||
final IFileElementType type = LanguageParserDefinitions.INSTANCE.forLanguage(l).getFileNodeType();
|
||||
|
||||
PsiFile psi = inputData.getPsiFile();
|
||||
psi = psi.getViewProvider().getStubBindingRoot();
|
||||
CharSequence contentAsText = inputData.getContentAsText();
|
||||
psi.putUserData(IndexingDataKeys.FILE_TEXT_CONTENT_KEY, contentAsText);
|
||||
|
||||
|
||||
@@ -34,10 +34,11 @@ public abstract class StubProcessingHelperBase {
|
||||
public <Psi extends PsiElement> boolean processStubsInFile(final Project project, final VirtualFile file, StubIdList value, final Processor<? super Psi> processor) {
|
||||
StubTree stubTree = null;
|
||||
|
||||
final PsiFile _psifile = PsiManager.getInstance(project).findFile(file);
|
||||
PsiFile _psifile = PsiManager.getInstance(project).findFile(file);
|
||||
PsiFileWithStubSupport psiFile = null;
|
||||
|
||||
if (_psifile != null && !(_psifile instanceof PsiPlainTextFile)) {
|
||||
_psifile = _psifile.getViewProvider().getStubBindingRoot();
|
||||
if (_psifile instanceof PsiFileWithStubSupport) {
|
||||
psiFile = (PsiFileWithStubSupport)_psifile;
|
||||
stubTree = psiFile.getStubTree();
|
||||
|
||||
Reference in New Issue
Block a user