use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PyStubsTest method testStubIndexMismatch.
public void testStubIndexMismatch() {
VirtualFile vFile = myFixture.getTempDirFixture().createFile("foo.py");
final Project project = myFixture.getProject();
PsiFileImpl fooPyFile = (PsiFileImpl) PsiManager.getInstance(project).findFile(vFile);
assertNotNull(fooPyFile);
final Document fooDocument = fooPyFile.getViewProvider().getDocument();
assertNotNull(fooDocument);
final Collection<PyClass> classes = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
assertEquals(0, classes.size());
new WriteCommandAction.Simple(project, fooPyFile) {
public void run() {
fooDocument.setText("class Foo: pass");
}
}.execute();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(fooDocument);
documentManager.performForCommittedDocument(fooDocument, () -> {
fooPyFile.setTreeElementPointer(null);
//classes = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
//fooPyFile.unloadContent();
DumbServiceImpl.getInstance(project).setDumb(true);
try {
assertEquals(1, ((PyFile) fooPyFile).getTopLevelClasses().size());
assertFalse(fooPyFile.isContentsLoaded());
} finally {
DumbServiceImpl.getInstance(project).setDumb(false);
}
final Collection<PyClass> committedClasses = PyClassNameIndex.find("Foo", project, GlobalSearchScope.allScope(project));
assertEquals(1, committedClasses.size());
});
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class FileIncludeManagerImpl method doResolve.
@Nullable
private PsiFileSystemItem doResolve(@NotNull final FileIncludeInfo info, @NotNull final PsiFile context) {
if (info instanceof FileIncludeInfoImpl) {
String id = ((FileIncludeInfoImpl) info).providerId;
FileIncludeProvider provider = id == null ? null : myProviderMap.get(id);
final PsiFileSystemItem resolvedByProvider = provider == null ? null : provider.resolveIncludedFile(info, context);
if (resolvedByProvider != null) {
return resolvedByProvider;
}
}
PsiFileImpl psiFile = (PsiFileImpl) myPsiFileFactory.createFileFromText("dummy.txt", FileTypes.PLAIN_TEXT, info.path);
psiFile.setOriginalFile(context);
return new FileReferenceSet(psiFile) {
@Override
protected boolean useIncludingFileAsContext() {
return false;
}
}.resolve();
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class CodeCompletionHandlerBase method createCompletionContext.
private static CompletionContext createCompletionContext(PsiFile originalFile, OffsetsInFile hostCopyOffsets) {
CompletionAssertions.assertHostInfo(hostCopyOffsets.getFile(), hostCopyOffsets.getOffsets());
int hostStartOffset = hostCopyOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET);
OffsetsInFile translatedOffsets = hostCopyOffsets.toInjectedIfAny(hostStartOffset);
InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(originalFile.getProject());
PsiFile injected = translatedOffsets == hostCopyOffsets ? null : translatedOffsets.getFile();
if (injected != null) {
if (injected instanceof PsiFileImpl) {
((PsiFileImpl) injected).setOriginalFile(originalFile);
}
DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injected);
CompletionAssertions.assertInjectedOffsets(hostStartOffset, injectedLanguageManager, injected, documentWindow);
}
CompletionContext context = new CompletionContext(translatedOffsets.getFile(), translatedOffsets.getOffsets());
CompletionAssertions.assertFinalOffsets(originalFile, context, injected);
return context;
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class PostfixLiveTemplate method copyFile.
@NotNull
public static PsiFile copyFile(@NotNull PsiFile file, @NotNull StringBuilder fileContentWithoutKey) {
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(file.getProject());
PsiFile copy = psiFileFactory.createFileFromText(file.getName(), file.getFileType(), fileContentWithoutKey);
if (copy instanceof PsiFileImpl) {
((PsiFileImpl) copy).setOriginalFile(TemplateLanguageUtil.getBaseFile(file));
}
VirtualFile vFile = copy.getVirtualFile();
if (vFile != null) {
vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
}
return copy;
}
use of com.intellij.psi.impl.source.PsiFileImpl in project intellij-community by JetBrains.
the class MultiHostRegistrarImpl method registerDocument.
// under com.intellij.psi.PsiLock.LOCK
private static PsiFile registerDocument(final DocumentWindowImpl documentWindow, final PsiFile injectedPsi, final Place shreds, final PsiFile hostPsiFile, final PsiDocumentManager documentManager) {
List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(hostPsiFile);
for (int i = injected.size() - 1; i >= 0; i--) {
DocumentWindowImpl oldDocument = (DocumentWindowImpl) injected.get(i);
final PsiFileImpl oldFile = (PsiFileImpl) documentManager.getCachedPsiFile(oldDocument);
FileViewProvider viewProvider;
if (oldFile == null || !oldFile.isValid() || !((viewProvider = oldFile.getViewProvider()) instanceof InjectedFileViewProvider) || ((InjectedFileViewProvider) viewProvider).isDisposed()) {
injected.remove(i);
Disposer.dispose(oldDocument);
continue;
}
InjectedFileViewProvider oldViewProvider = (InjectedFileViewProvider) viewProvider;
final ASTNode injectedNode = injectedPsi.getNode();
final ASTNode oldFileNode = oldFile.getNode();
assert injectedNode != null : "New node is null";
if (oldDocument.areRangesEqual(documentWindow)) {
if (oldFile.getFileType() != injectedPsi.getFileType() || oldFile.getLanguage() != injectedPsi.getLanguage()) {
injected.remove(i);
Disposer.dispose(oldDocument);
continue;
}
oldFile.putUserData(FileContextUtil.INJECTED_IN_ELEMENT, injectedPsi.getUserData(FileContextUtil.INJECTED_IN_ELEMENT));
assert shreds.isValid();
if (!oldFile.textMatches(injectedPsi)) {
oldViewProvider.performNonPhysically(() -> {
DebugUtil.startPsiModification("injected tree diff");
try {
final DiffLog diffLog = BlockSupportImpl.mergeTrees(oldFile, oldFileNode, injectedNode, new DaemonProgressIndicator(), oldFileNode.getText());
DocumentCommitThread.doActualPsiChange(oldFile, diffLog);
} finally {
DebugUtil.finishPsiModification();
}
});
}
assert shreds.isValid();
return oldFile;
}
}
injected.add(documentWindow);
return injectedPsi;
}
Aggregations