Added indices for functions and properties in package and used them to speed up completion

This commit is contained in:
Valentin Kipyatkov
2014-11-28 19:58:01 +03:00
parent 9f6dd3ce2e
commit 375a8f6049
5 changed files with 125 additions and 25 deletions
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.stubindex;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import java.util.Collection;
public class JetTopLevelFunctionByPackageIndex extends StringStubIndexExtension<JetNamedFunction> {
private static final StubIndexKey<String, JetNamedFunction> KEY = KotlinIndexUtil.createIndexKey(JetTopLevelFunctionByPackageIndex.class);
private static final JetTopLevelFunctionByPackageIndex ourInstance = new JetTopLevelFunctionByPackageIndex();
public static JetTopLevelFunctionByPackageIndex getInstance() {
return ourInstance;
}
private JetTopLevelFunctionByPackageIndex() {}
@NotNull
@Override
public StubIndexKey<String, JetNamedFunction> getKey() {
return KEY;
}
@Override
public Collection<JetNamedFunction> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
}
}
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.stubindex;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetProperty;
import java.util.Collection;
public class JetTopLevelPropertyByPackageIndex extends StringStubIndexExtension<JetProperty> {
private static final StubIndexKey<String, JetProperty> KEY = KotlinIndexUtil.createIndexKey(JetTopLevelPropertyByPackageIndex.class);
private static final JetTopLevelPropertyByPackageIndex ourInstance = new JetTopLevelPropertyByPackageIndex();
public static JetTopLevelPropertyByPackageIndex getInstance() {
return ourInstance;
}
private JetTopLevelPropertyByPackageIndex() {}
@NotNull
@Override
public StubIndexKey<String, JetProperty> getKey() {
return KEY;
}
@Override
public Collection<JetProperty> get(String fqName, Project project, @NotNull GlobalSearchScope scope) {
return super.get(fqName, project, JetSourceFilterScope.kotlinSourcesAndLibraries(scope, project));
}
}
@@ -118,10 +118,14 @@ public class StubIndexServiceImpl implements StubIndexService {
sink.occurrence(JetProbablyNothingFunctionShortNameIndex.getInstance().getKey(), name);
}
}
// can have special fq name in case of syntactically incorrect function with no name
FqName topFQName = stub.getFqName();
if (topFQName != null) {
sink.occurrence(JetTopLevelFunctionsFqnNameIndex.getInstance().getKey(), topFQName.asString());
if (stub.isTopLevel()) {
// can have special fq name in case of syntactically incorrect function with no name
FqName fqName = stub.getFqName();
if (fqName != null) {
sink.occurrence(JetTopLevelFunctionsFqnNameIndex.getInstance().getKey(), fqName.asString());
sink.occurrence(JetTopLevelFunctionByPackageIndex.getInstance().getKey(), fqName.parent().asString());
}
}
}
@@ -145,11 +149,13 @@ public class StubIndexServiceImpl implements StubIndexService {
sink.occurrence(JetProbablyNothingPropertyShortNameIndex.getInstance().getKey(), name);
}
}
// can have special fq name in case of syntactically incorrect function with no name
if (stub.isTopLevel()) {
FqName topFQName = stub.getFqName();
if (topFQName != null) {
sink.occurrence(JetTopLevelPropertiesFqnNameIndex.getInstance().getKey(), topFQName.asString());
FqName fqName = stub.getFqName();
// can have special fq name in case of syntactically incorrect property with no name
if (fqName != null) {
sink.occurrence(JetTopLevelPropertiesFqnNameIndex.getInstance().getKey(), fqName.asString());
sink.occurrence(JetTopLevelPropertyByPackageIndex.getInstance().getKey(), fqName.parent().asString());
}
}
}
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.stubindex.resolve
import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StringStubIndexExtension
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider
import org.jetbrains.jet.lang.resolve.name.FqName
@@ -33,6 +32,9 @@ import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils
import java.util.ArrayList
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
import org.jetbrains.jet.plugin.stubindex.JetClassByPackageIndex
import org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionByPackageIndex
import com.intellij.psi.stubs.StringStubIndexExtension
import org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertyByPackageIndex
public class StubBasedPackageMemberDeclarationProvider(
private val fqName: FqName,
@@ -43,33 +45,25 @@ public class StubBasedPackageMemberDeclarationProvider(
override fun getDeclarations(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): List<JetDeclaration> {
val result = ArrayList<JetDeclaration>()
if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) {
JetClassByPackageIndex.getInstance().get(fqName.asString(), project, searchScope)
.filterTo(result) { nameFilter(it.getNameAsSafeName()) }
fun addFromIndex(index: StringStubIndexExtension<out JetNamedDeclaration>) {
index.get(fqName.asString(), project, searchScope).filterTo(result) { nameFilter(it.getNameAsSafeName()) }
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) {
addFromIndex(JetClassByPackageIndex.getInstance())
}
//TODO: add by package indices for functions and properties too?
if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) {
result.addDeclarations(JetTopLevelFunctionsFqnNameIndex.getInstance(), nameFilter)
addFromIndex(JetTopLevelFunctionByPackageIndex.getInstance())
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) {
result.addDeclarations(JetTopLevelPropertiesFqnNameIndex.getInstance(), nameFilter)
addFromIndex(JetTopLevelPropertyByPackageIndex.getInstance())
}
return result
}
private fun MutableCollection<JetDeclaration>.addDeclarations(index: StringStubIndexExtension<out JetNamedDeclaration>,
nameFilter: (Name) -> Boolean) {
index.getAllKeys(project)
.stream()
.map { FqName(it) }
.filter { !it.isRoot() && it.parent() == fqName && nameFilter(it.shortName()) }
.toSet()
.flatMapTo(this) { index[it.asString(), project, searchScope] }
}
override fun getClassOrObjectDeclarations(name: Name): Collection<JetClassLikeInfo> {
return JetFullClassNameIndex.getInstance().get(childName(name), project, searchScope)
.map { JetClassInfoUtil.createClassLikeInfo(it) }
+2
View File
@@ -395,6 +395,8 @@
<stubElementTypeHolder class="org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetExactPackagesIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetClassByPackageIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelFunctionByPackageIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelPropertyByPackageIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetClassShortNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetTopLevelNonExtensionFunctionShortNameIndex"/>