• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Camelcade / Perl5-IDEA / #525521543

22 May 2025 09:13AM UTC coverage: 82.34% (+0.1%) from 82.228%
#525521543

push

github

hurricup
Improved localization handling

Still imperfect, but good enough

0 of 2 new or added lines in 1 file covered. (0.0%)

113 existing lines in 7 files now uncovered.

30912 of 37542 relevant lines covered (82.34%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.0
/plugin/core/src/main/java/com/perl5/lang/perl/idea/project/PerlDirectoryIndex.java
1
/*
2
 * Copyright 2015-2025 Alexandr Evstigneev
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.perl5.lang.perl.idea.project;
18

19
import com.intellij.openapi.Disposable;
20
import com.intellij.openapi.project.Project;
21
import com.intellij.openapi.roots.ModuleRootEvent;
22
import com.intellij.openapi.roots.ModuleRootListener;
23
import com.intellij.openapi.util.Disposer;
24
import com.intellij.openapi.vfs.VirtualFile;
25
import com.intellij.util.indexing.LightDirectoryIndex;
26
import com.intellij.util.messages.MessageBusConnection;
27
import org.jetbrains.annotations.ApiStatus;
28
import org.jetbrains.annotations.Contract;
29
import org.jetbrains.annotations.NotNull;
30
import org.jetbrains.annotations.Nullable;
31

32
import java.util.List;
33
import java.util.function.Function;
34
import java.util.function.Supplier;
35

36
public class PerlDirectoryIndex implements Disposable {
37
  private final @NotNull LightDirectoryIndex<PerlDirectoryIndexEntry> myIndex;
38
  private final @NotNull Function<VirtualFile, VirtualFile> myRootComputator;
39

40
  public PerlDirectoryIndex(@NotNull Project project) {
1✔
41
    myIndex = createIndexForRoots(() -> PerlProjectManager.getInstance(project).getAllLibraryRoots());
1✔
42
    myRootComputator = createRootComputator(myIndex);
1✔
43
    MessageBusConnection connection = project.getMessageBus().connect(this);
1✔
44
    connection.subscribe(ModuleRootListener.TOPIC, new ModuleRootListener() {
1✔
45
      @Override
46
      public void rootsChanged(@NotNull ModuleRootEvent event) {
47
        myIndex.resetIndex();
1✔
48
      }
1✔
49
    });
50
  }
1✔
51

52
  /**
53
   * @return a computator for roots, for external usage. Can be used for roots with dynamic entries
54
   * @implSpec we could probably just create a simpler clone of {@link LightDirectoryIndex}
55
   */
56
  @ApiStatus.Experimental
57
  public @NotNull Function<VirtualFile, VirtualFile> createRootComputator(@NotNull List<VirtualFile> roots) {
58
    Disposable disposable = Disposer.newDisposable();
1✔
59
    Function<VirtualFile, VirtualFile> result = createRootComputator(createIndexForRoots(() -> roots));
1✔
60
    disposable.dispose();
1✔
61
    return result;
1✔
62
  }
63

64
  private @NotNull LightDirectoryIndex<PerlDirectoryIndexEntry> createIndexForRoots(Supplier<List<VirtualFile>> libraryRootsSupplier) {
65
    return new LightDirectoryIndex<>(this, PerlDirectoryIndexEntry.EMPTY,
1✔
66
                                     it -> libraryRootsSupplier.get().forEach(root -> it.putInfo(root, new PerlDirectoryIndexEntry(root))));
1✔
67
  }
68

69
  @Override
70
  public void dispose() {
UNCOV
71
    myIndex.resetIndex();
×
72
  }
×
73

74
  private static Function<VirtualFile, VirtualFile> createRootComputator(@NotNull LightDirectoryIndex<PerlDirectoryIndexEntry> index) {
75
    return virtualFile -> {
1✔
76
      if (virtualFile == null) {
1✔
UNCOV
77
        return null;
×
78
      }
79
      PerlDirectoryIndexEntry indexEntry = index.getInfoForFile(virtualFile);
1✔
80
      if (indexEntry == PerlDirectoryIndexEntry.EMPTY) {
1✔
81
        return null;
1✔
82
      }
83
      return indexEntry.getRoot();
1✔
84
    };
85
  }
86

87
  @Contract("null->null")
88
  public @Nullable VirtualFile getRoot(@Nullable VirtualFile virtualFile) {
89
    return myRootComputator.apply(virtualFile);
1✔
90
  }
91

92
  public static @NotNull PerlDirectoryIndex getInstance(@NotNull Project project) {
93
    return project.getService(PerlDirectoryIndex.class);
1✔
94
  }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc