Skip to content

Commit 943aada

Browse files
Excluded lsf files in sources jar from indexing, resolving, errors search
1 parent c4710a9 commit 943aada

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed

src/com/lsfusion/lang/LSFReferenceAnnotator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public class LSFReferenceAnnotator extends LSFVisitor implements Annotator {
8888

8989
@Override
9090
public synchronized void annotate(@NotNull PsiElement psiElement, AnnotationHolder holder) {
91+
if (psiElement instanceof LSFElement lsfElement && lsfElement.isInLibrarySources()) {
92+
return;
93+
}
94+
9195
myHolder = holder;
9296
try {
9397
psiElement.accept(this);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
package com.lsfusion.lang.psi;
22

3+
import com.intellij.openapi.roots.ProjectFileIndex;
4+
import com.intellij.openapi.vfs.VirtualFile;
35
import com.intellij.psi.PsiElement;
46

57
public interface LSFElement extends PsiElement {
68

79
boolean isCorrect(); // для pin'ов, если pin сработал а не все элементы есть
810

911
LSFFile getLSFFile();
12+
13+
default boolean isInLibrarySources() {
14+
LSFFile lsfFile = getLSFFile();
15+
if (lsfFile != null) {
16+
VirtualFile virtualFile = lsfFile.getVirtualFile();
17+
if (virtualFile != null) {
18+
return ProjectFileIndex.getInstance(getProject()).isInLibrarySource(virtualFile);
19+
}
20+
}
21+
return false;
22+
}
1023
}

src/com/lsfusion/lang/psi/LSFGlobalResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static <S extends FullNameStubElement<S, T>, T extends LSFFullNameDeclara
136136
}
137137

138138
public static <G extends LSFStubbedElement> Collection<G> getItemsFromIndex(LSFStringStubIndex<G> index, String name, Project project, GlobalSearchScope scope, LSFLocalSearchScope localScope) {
139-
Collection<G> elements = index.get(name, project, scope);
139+
Collection<G> elements = index.get(name, project, new LSFSourceFilterScope(scope));
140140

141141
Collection<G> filteredElements = new ArrayList<>();
142142

src/com/lsfusion/lang/psi/LSFResolver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.jetbrains.annotations.Nullable;
2424

2525
import java.util.ArrayList;
26+
import java.util.Collections;
2627
import java.util.List;
2728

2829
public class LSFResolver implements ResolveCache.AbstractResolver<LSFReference, LSFResolveResult> {
@@ -31,7 +32,10 @@ public class LSFResolver implements ResolveCache.AbstractResolver<LSFReference,
3132
@Nullable
3233
@Override
3334
public LSFResolveResult resolve(@NotNull LSFReference reference, boolean incompleteCode) {
34-
return reference.resolveNoCache();
35+
if (reference.isInLibrarySources()) {
36+
return new LSFResolveResult(Collections.emptyList());
37+
}
38+
return reference.resolveNoCache();
3539
}
3640

3741
public static Query<PsiReference> searchWordUsages(Project project, String compoundID) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.lsfusion.lang.psi;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.roots.ProjectFileIndex;
5+
import com.intellij.openapi.vfs.VirtualFile;
6+
import com.intellij.psi.search.DelegatingGlobalSearchScope;
7+
import com.intellij.psi.search.GlobalSearchScope;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public class LSFSourceFilterScope extends DelegatingGlobalSearchScope {
11+
private ProjectFileIndex fileIndex;
12+
private boolean includeLibrarySources;
13+
14+
public LSFSourceFilterScope(@NotNull GlobalSearchScope baseScope) {
15+
this(baseScope, false);
16+
}
17+
18+
public LSFSourceFilterScope(@NotNull GlobalSearchScope baseScope, boolean includeLibrarySources) {
19+
super(baseScope);
20+
Project project = getProject();
21+
fileIndex = project == null ? null : ProjectFileIndex.getInstance(project);
22+
this.includeLibrarySources = includeLibrarySources;
23+
}
24+
25+
@Override
26+
public boolean contains(@NotNull VirtualFile file) {
27+
if (!super.contains(file)) {
28+
return false;
29+
}
30+
31+
if (fileIndex == null) {
32+
return false;
33+
}
34+
35+
if (includeLibrarySources || myBaseScope.isForceSearchingInLibrarySources()) {
36+
return true;
37+
}
38+
return !fileIndex.isInLibrarySource(file);
39+
}
40+
41+
@NotNull
42+
public static LSFSourceFilterScope allScope(@NotNull Project project) {
43+
return new LSFSourceFilterScope(GlobalSearchScope.allScope(project));
44+
}
45+
}

src/com/lsfusion/lang/psi/indexes/LSFStringStubIndex.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
import com.intellij.psi.search.GlobalSearchScope;
66
import com.intellij.psi.stubs.StringStubIndexExtension;
77
import com.intellij.psi.stubs.StubIndex;
8+
import com.lsfusion.lang.psi.LSFSourceFilterScope;
89
import com.lsfusion.lang.psi.LSFStubbedElement;
910

1011
import java.util.Collection;
1112

1213
public abstract class LSFStringStubIndex<Psi extends LSFStubbedElement> extends StringStubIndexExtension<Psi> {
1314
@Override
1415
public Collection<Psi> get(String s, Project project, GlobalSearchScope scope) {
15-
return DumbService.getInstance(project).runReadActionInSmartMode(() -> StubIndex.getElements(getKey(), s, project, scope, getPsiClass()));
16+
return DumbService.getInstance(project).runReadActionInSmartMode(() -> StubIndex.getElements(getKey(), s, project, new LSFSourceFilterScope(scope), getPsiClass()));
1617
}
1718

1819
protected abstract Class<Psi> getPsiClass();

src/com/lsfusion/util/LSFFileUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.intellij.psi.search.FilenameIndex;
2020
import com.intellij.psi.search.GlobalSearchScope;
2121
import com.lsfusion.lang.psi.LSFGlobalResolver;
22+
import com.lsfusion.lang.psi.LSFSourceFilterScope;
2223
import com.lsfusion.lang.psi.Result;
2324
import com.lsfusion.lang.psi.declarations.LSFModuleDeclaration;
2425
import org.jetbrains.annotations.NotNull;
@@ -277,7 +278,8 @@ public static GlobalSearchScope getScope(List<String> modulesToInclude, Project
277278
}
278279
}
279280
} else
280-
modulesScope = allScope(project);
281+
// all places without source lsf files by default. is used in errors search and enabling/disabling meta for now
282+
modulesScope = LSFSourceFilterScope.allScope(project);
281283
return modulesScope;
282284
}
283285
}

0 commit comments

Comments
 (0)