1818
1919import com .intellij .openapi .module .Module ;
2020import com .intellij .openapi .module .ModuleUtilCore ;
21- import com .intellij .openapi .project .Project ;
22- import com .intellij .openapi .roots .ModuleRootManager ;
2321import com .intellij .openapi .util .Condition ;
2422import com .intellij .openapi .util .TextRange ;
25- import com .intellij .openapi .vfs .LocalFileSystem ;
2623import com .intellij .openapi .vfs .VirtualFile ;
2724import com .intellij .psi .PsiCompiledElement ;
2825import com .intellij .psi .PsiDirectory ;
3532import com .intellij .psi .impl .source .resolve .reference .impl .providers .FileReferenceSet ;
3633import com .intellij .util .ProcessingContext ;
3734import com .intellij .util .containers .ContainerUtil ;
38- import io . protostuff . jetbrains . plugin . settings . ProtobufSettings ;
35+ import java . util . ArrayList ;
3936import java .util .Collection ;
4037import java .util .Collections ;
4138import java .util .List ;
@@ -53,48 +50,39 @@ public class FilePathReferenceProvider extends PsiReferenceProvider {
5350
5451 private final boolean myEndingSlashNotAllowed ;
5552
53+ interface SourceRootsProvider {
54+ VirtualFile [] getSourceRoots (Module module );
55+ }
56+
57+ private List <SourceRootsProvider > sourceRootsProviders = new ArrayList <>();
58+
5659 public FilePathReferenceProvider () {
5760 this (true );
5861 }
5962
6063 public FilePathReferenceProvider (boolean endingSlashNotAllowed ) {
6164 myEndingSlashNotAllowed = endingSlashNotAllowed ;
65+ sourceRootsProviders .add (new AllSourceRootsProvider ());
66+ sourceRootsProviders .add (new CustomIncludePathRootsProvider ());
67+ sourceRootsProviders .add (new LibrariesAndSdkClassesRootsProvider ());
6268 }
6369
6470 @ NotNull
65- public static Collection <PsiFileSystemItem > getRoots (@ Nullable final Module thisModule ) {
66- if (thisModule == null ) {
71+ public Collection <PsiFileSystemItem > getRoots (@ Nullable final Module module ) {
72+ if (module == null ) {
6773 return Collections .emptyList ();
6874 }
6975
70- ModuleRootManager moduleRootManager = ModuleRootManager .getInstance (thisModule );
7176 Set <PsiFileSystemItem > result = ContainerUtil .newLinkedHashSet ();
72- final PsiManager psiManager = PsiManager .getInstance (thisModule .getProject ());
73-
74- VirtualFile [] libraryUrls = moduleRootManager .orderEntries ().getAllLibrariesAndSdkClassesRoots ();
75- for (VirtualFile file : libraryUrls ) {
76- PsiDirectory directory = psiManager .findDirectory (file );
77- if (directory != null ) {
78- result .add (directory );
79- }
80- }
81-
82- VirtualFile [] sourceRoots = moduleRootManager .orderEntries ().getAllSourceRoots ();
83- for (VirtualFile root : sourceRoots ) {
84- final PsiDirectory directory = psiManager .findDirectory (root );
85- if (directory != null ) {
86- result .add (directory );
87- }
88- }
89-
90- Project project = thisModule .getProject ();
91- ProtobufSettings settings = project .getComponent (ProtobufSettings .class );
92- List <String > includePaths = settings .getIncludePaths ();
93- for (String includePath : includePaths ) {
94- VirtualFile path = LocalFileSystem .getInstance ().findFileByPath (includePath );
95- if (path != null && path .isDirectory ()) {
96- PsiDirectory psiDirectory = psiManager .findDirectory (path );
97- result .add (psiDirectory );
77+ PsiManager psiManager = PsiManager .getInstance (module .getProject ());
78+
79+ for (SourceRootsProvider sourceRootsProvider : sourceRootsProviders ) {
80+ VirtualFile [] sourceRoots = sourceRootsProvider .getSourceRoots (module );
81+ for (VirtualFile root : sourceRoots ) {
82+ final PsiDirectory directory = psiManager .findDirectory (root );
83+ if (directory != null ) {
84+ result .add (directory );
85+ }
9886 }
9987 }
10088 return result ;
@@ -188,4 +176,5 @@ protected boolean isPsiElementAccepted(PsiElement element) {
188176 protected FileReference createFileReference (FileReferenceSet referenceSet , final TextRange range , final int index , final String text ) {
189177 return new FileReference (referenceSet , range , index , text );
190178 }
179+
191180}
0 commit comments