indexes: stubs with snapshots should respect pushed properties as well

GitOrigin-RevId: 04b9b4442e384ba13daefad087c1e4154ad3e3d4
This commit is contained in:
Dmitry Batkovich
2020-05-09 05:25:10 +00:00
committed by intellij-monorepo-bot
parent e79b5b2ea1
commit c6ddd2a9ff
7 changed files with 97 additions and 6 deletions
@@ -402,9 +402,13 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
CodeStyleManager.getInstance(getProject()).reformat(psiFile)
assert JavaPsiFacade.getInstance(project).findClass("Foo", scope)
def stamp = ((FileBasedIndexImpl)FileBasedIndex.instance).getIndexModificationStamp(StubUpdatingIndex.INDEX_ID, project)
IdeaTestUtil.setModuleLanguageLevel(myFixture.module, LanguageLevel.JDK_1_3)
assert ((PsiJavaFile)psiFile).importList.node
assert stamp != ((FileBasedIndexImpl)FileBasedIndex.instance).getIndexModificationStamp(StubUpdatingIndex.INDEX_ID, project)
}
void "test rename file with indexed associated unsaved document don't lost its data"() {
@@ -0,0 +1,24 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Proof of concept to mix pushed properties to stub index composite indexer data.
*/
@ApiStatus.Experimental
@ApiStatus.Internal
public interface PushedFilePropertiesRetriever {
static PushedFilePropertiesRetriever getInstance() {
return ServiceManager.getService(PushedFilePropertiesRetriever.class);
}
@NotNull
List<String> dumpSortedPushedProperties(@NotNull VirtualFile file);
}
@@ -3,21 +3,26 @@ package com.intellij.psi.stubs;
import com.intellij.diagnostic.PluginException;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.templateLanguages.TemplateLanguage;
import com.intellij.psi.tree.IStubFileElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
class StubBuilderType {
private static final Logger LOG = Logger.getInstance(StubBuilderType.class);
private final IStubFileElementType myElementType;
private final List<String> myProperties;
private final BinaryFileStubBuilder myBinaryFileStubBuilder;
private final Object myBinarySubBuilder;
StubBuilderType(@NotNull IStubFileElementType elementType) {
StubBuilderType(@NotNull IStubFileElementType elementType, @NotNull List<String> properties) {
myElementType = elementType;
myProperties = properties;
myBinaryFileStubBuilder = null;
myBinarySubBuilder = null;
}
@@ -26,6 +31,7 @@ class StubBuilderType {
myElementType = null;
myBinaryFileStubBuilder = binaryFileStubBuilder;
myBinarySubBuilder = null;
myProperties = Collections.emptyList();
}
StubBuilderType(@NotNull BinaryFileStubBuilder.CompositeBinaryFileStubBuilder binaryFileStubBuilder,
@@ -33,6 +39,7 @@ class StubBuilderType {
myElementType = null;
myBinaryFileStubBuilder = binaryFileStubBuilder;
myBinarySubBuilder = binarySubBuilder;
myProperties = Collections.emptyList();
}
BinaryFileStubBuilder getBinaryFileStubBuilder() {
@@ -46,7 +53,8 @@ class StubBuilderType {
PluginException.logPluginError(LOG, myElementType.getLanguage() + " stub version should call super.getStubVersion()",
null, myElementType.getClass());
}
return myElementType.getClass().getName() + ":" + myElementType.getStubVersion();
String baseVersion = myElementType.getClass().getName() + ":" + myElementType.getStubVersion();
return myProperties.isEmpty() ? baseVersion : (baseVersion + ":" + StringUtil.join(myProperties, ","));
} else {
assert myBinaryFileStubBuilder != null;
String baseVersion = myBinaryFileStubBuilder.getClass().getName() + ":" + myBinaryFileStubBuilder.getStubVersion();
@@ -65,11 +73,12 @@ class StubBuilderType {
StubBuilderType type = (StubBuilderType)o;
return Objects.equals(myElementType, type.myElementType) &&
Objects.equals(myBinaryFileStubBuilder, type.myBinaryFileStubBuilder) &&
Objects.equals(myProperties, type.myProperties) &&
Objects.equals(myBinarySubBuilder, type.myBinarySubBuilder);
}
@Override
public int hashCode() {
return Objects.hash(myElementType, myBinaryFileStubBuilder, myBinarySubBuilder);
return Objects.hash(myElementType, myBinaryFileStubBuilder, myBinarySubBuilder, myProperties);
}
}
@@ -21,10 +21,12 @@ import com.intellij.lang.ParserDefinition;
import com.intellij.lang.TreeBackedLighterAST;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.roots.impl.PushedFilePropertiesRetriever;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiFile;
import com.intellij.psi.StubBuilder;
@@ -75,9 +77,11 @@ public class StubTreeBuilder {
final IFileElementType elementType = parserDefinition.getFileNodeType();
if (!(elementType instanceof IStubFileElementType)) return null;
boolean shouldBuildStubFor = ((IStubFileElementType)elementType).shouldBuildStubFor(file.getFile());
VirtualFile vFile = file.getFile();
boolean shouldBuildStubFor = ((IStubFileElementType)elementType).shouldBuildStubFor(vFile);
if (toBuild && !shouldBuildStubFor) return null;
return new StubBuilderType((IStubFileElementType)elementType);
@NotNull List<String> properties = PushedFilePropertiesRetriever.getInstance().dumpSortedPushedProperties(vFile);
return new StubBuilderType((IStubFileElementType)elementType, properties);
}
return null;
@@ -0,0 +1,45 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.roots.impl;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.stubs.StubUpdatingIndex;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class PushedFilePropertiesRetrieverImpl implements PushedFilePropertiesRetriever {
@NotNull
@Override
public List<String> dumpSortedPushedProperties(@NotNull VirtualFile file) {
if (file.isDirectory()) {
throw new IllegalArgumentException("file " + file + " is expected to be a regular file");
}
if (StubUpdatingIndex.USE_SNAPSHOT_MAPPINGS) {
List<FilePropertyPusher<?>> extensions = FilePropertyPusher.EP_NAME.getExtensionList();
List<String> properties = new SmartList<>();
for (FilePropertyPusher<?> extension : extensions) {
Object property;
VirtualFile vfsObject;
if (extension.pushDirectoriesOnly()) {
vfsObject = file.getParent();
}
else {
vfsObject = file;
}
property = vfsObject.getUserData(extension.getFileDataKey());
if (property != null) {
properties.add(property.toString());
}
}
ContainerUtil.sort(properties);
return properties;
}
else {
return Collections.emptyList();
}
}
}
@@ -48,6 +48,8 @@ import java.util.stream.Stream;
public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<SerializedStubTree>
implements CustomImplementationFileBasedIndexExtension<Integer, SerializedStubTree> {
static final Logger LOG = Logger.getInstance(StubUpdatingIndex.class);
public static final boolean USE_SNAPSHOT_MAPPINGS = SystemProperties.is("stubs.use.snapshot.mappings");
private static final int VERSION = 45 + (PersistentHashMapValueStorage.COMPRESSION_ENABLED ? 1 : 0);
// todo remove once we don't need this for stub-ast mismatch debug info
@@ -75,7 +77,7 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
@Override
public boolean hasSnapshotMapping() {
return SystemProperties.is("stubs.use.snapshot.mappings");
return USE_SNAPSHOT_MAPPINGS;
}
public static boolean canHaveStub(@NotNull VirtualFile file) {
@@ -92,6 +92,9 @@
<postStartupActivity implementation="com.intellij.refactoring.suggested.SuggestedRefactoringProviderImpl$Startup"/>
<notificationWhitelist groupIds="Code style settings migration;Find Problems;Missing SDKs;Automatic indent detection;Indexing;
Framework Detection;Power Save Mode;Show control flow group"/>
<applicationService serviceInterface="com.intellij.openapi.roots.impl.PushedFilePropertiesRetriever"
serviceImplementation="com.intellij.openapi.roots.impl.PushedFilePropertiesRetrieverImpl"/>
</extensions>
<xi:include href="/META-INF/VCS.xml" xpointer="xpointer(/idea-plugin/*)">