Skip to content

Commit a24c2f7

Browse files
88: Configuration of custom include paths for new projects
Fixes #88
1 parent 3af255d commit a24c2f7

File tree

7 files changed

+15
-22
lines changed

7 files changed

+15
-22
lines changed

src/main/java/io/protostuff/jetbrains/plugin/GoToClassContributor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private List<ProtoType> getProtoTypes(Project project, boolean includeNonProject
8282
List<VirtualFile> files = new ArrayList<>();
8383
addProjectAndLibraryFiles(project, includeNonProjectItems, files);
8484
if (includeNonProjectItems) {
85-
addFilesFromCustomIncludePath(project, files);
85+
addFilesFromCustomIncludePath(files);
8686
addBundledGoogleProtos(project, files);
8787
}
8888
for (VirtualFile virtualFile : files) {
@@ -122,8 +122,8 @@ private void addProjectAndLibraryFiles(Project project, boolean includeNonProjec
122122
files.addAll(FileTypeIndex.getFiles(ProtoFileType.INSTANCE, scope));
123123
}
124124

125-
private void addFilesFromCustomIncludePath(Project project, List<VirtualFile> files) {
126-
ProtobufSettings settings = project.getComponent(ProtobufSettings.class);
125+
private void addFilesFromCustomIncludePath(List<VirtualFile> files) {
126+
ProtobufSettings settings = ProtobufSettings.getInstance();
127127
List<VirtualFile> includePaths = settings.getIncludePathsVf();
128128
for (VirtualFile includePath : includePaths) {
129129
FileBasedIndex.iterateRecursively(includePath, file -> {

src/main/java/io/protostuff/jetbrains/plugin/reference/file/CustomIncludePathRootsProvider.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.protostuff.jetbrains.plugin.reference.file;
22

33
import com.intellij.openapi.module.Module;
4-
import com.intellij.openapi.project.Project;
54
import com.intellij.openapi.vfs.LocalFileSystem;
65
import com.intellij.openapi.vfs.VirtualFile;
76
import io.protostuff.jetbrains.plugin.psi.ProtoPsiFileRoot;
@@ -18,8 +17,7 @@ class CustomIncludePathRootsProvider implements FilePathReferenceProvider.Source
1817
@Override
1918
public VirtualFile[] getSourceRoots(Module module, ProtoPsiFileRoot psiFileRoot) {
2019
List<VirtualFile> result = new ArrayList<>();
21-
Project project = module.getProject();
22-
ProtobufSettings settings = project.getComponent(ProtobufSettings.class);
20+
ProtobufSettings settings = ProtobufSettings.getInstance();
2321
List<String> includePaths = settings.getIncludePaths();
2422
for (String includePath : includePaths) {
2523
VirtualFile path = LocalFileSystem.getInstance().findFileByPath(includePath);

src/main/java/io/protostuff/jetbrains/plugin/settings/ProtobufSettings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.protostuff.jetbrains.plugin.settings;
22

33
import com.intellij.openapi.components.PersistentStateComponent;
4+
import com.intellij.openapi.components.ServiceManager;
45
import com.intellij.openapi.components.State;
56
import com.intellij.openapi.components.Storage;
6-
import com.intellij.openapi.project.Project;
77
import com.intellij.openapi.vfs.LocalFileSystem;
88
import com.intellij.openapi.vfs.VirtualFile;
99
import com.intellij.util.xmlb.XmlSerializerUtil;
@@ -18,8 +18,8 @@ public class ProtobufSettings implements PersistentStateComponent<ProtobufSettin
1818

1919
private List<String> includePaths = new ArrayList<>();
2020

21-
public static ProtobufSettings getInstance(Project project) {
22-
return project.getComponent(ProtobufSettings.class);
21+
public static ProtobufSettings getInstance() {
22+
return ServiceManager.getService(ProtobufSettings.class);
2323
}
2424

2525
@NotNull

src/main/java/io/protostuff/jetbrains/plugin/settings/ProtobufSettingsConfigurable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ProtobufSettingsConfigurable implements Configurable {
1919

2020
public ProtobufSettingsConfigurable(Project project) {
2121
this.project = project;
22-
this.settings = ProtobufSettings.getInstance(project);
22+
this.settings = ProtobufSettings.getInstance();
2323
}
2424

2525
@Nls

src/main/java/io/protostuff/jetbrains/plugin/settings/SettingsForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SettingsForm {
3737
* @param settings is null if settings dialog runs without a project.
3838
*/
3939
@SuppressWarnings("unchecked")
40-
public SettingsForm(Project project, @Nullable ProtobufSettings settings) {
40+
public SettingsForm(@Nullable Project project, @Nullable ProtobufSettings settings) {
4141
this.project = project;
4242
List<String> internalIncludePathList = new ArrayList<>();
4343
if (settings != null) {

src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@
102102
<component>
103103
<implementation-class>io.protostuff.jetbrains.plugin.ProtostuffPluginController</implementation-class>
104104
</component>
105-
<component>
106-
<implementation-class>io.protostuff.jetbrains.plugin.settings.ProtobufSettings</implementation-class>
107-
</component>
108105
<component>
109106
<interface-class>io.protostuff.jetbrains.plugin.reference.FieldReferenceProvider</interface-class>
110107
<implementation-class>io.protostuff.jetbrains.plugin.reference.FieldReferenceProviderImpl
@@ -165,6 +162,8 @@
165162
language="PROTO"
166163
implementationClass="io.protostuff.jetbrains.plugin.ProtoFoldingBuilder"/>
167164

165+
<applicationService serviceImplementation="io.protostuff.jetbrains.plugin.settings.ProtobufSettings"/>
166+
168167
<projectConfigurable instance="io.protostuff.jetbrains.plugin.settings.ProtobufSettingsConfigurable"/>
169168

170169
<annotator
@@ -215,7 +214,7 @@
215214

216215
<spellchecker.support
217216
language="PROTO"
218-
implementationClass="io.protostuff.jetbrains.plugin.spellchecker.ProtoSpellcheckingStrategy" />
217+
implementationClass="io.protostuff.jetbrains.plugin.spellchecker.ProtoSpellcheckingStrategy"/>
219218
</extensions>
220219

221220
<actions>

src/test/java/io/protostuff/jetbrains/plugin/navigation/GoToClassTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void testMultipleElements() throws Exception {
122122

123123
public void testGoToMessage_inCustomIncludePath() throws Exception {
124124
File includePathRoot = tempDir;
125-
ProtobufSettings settings = getProject().getComponent(ProtobufSettings.class);
125+
ProtobufSettings settings = ProtobufSettings.getInstance();
126126
settings.setIncludePaths(Collections.singletonList(includePathRoot.getAbsolutePath()));
127127
File proto = new File(tempDir.getPath() + "/test.proto");
128128
Writer writer = new BufferedWriter(new FileWriter(proto));
@@ -138,12 +138,8 @@ private ProtoPsiFileRoot addProto(String name, String text) {
138138
}
139139

140140
private ProtoType findType(final ProtoPsiFileRoot file, final String fullName) {
141-
return ApplicationManager.getApplication().runReadAction(new Computable<ProtoType>() {
142-
@Override
143-
public ProtoType compute() {
144-
return file.findType(fullName);
145-
}
146-
});
141+
return ApplicationManager.getApplication()
142+
.runReadAction((Computable<ProtoType>) () -> file.findType(fullName));
147143
}
148144

149145
private List<Object> getPopupElements(ChooseByNameModel model, String text, boolean checkboxState) {

0 commit comments

Comments
 (0)