Skip to content

Commit bf1c923

Browse files
committed
Some adjustments after review
- Use consistent option names in settings - Introduce StoragePaths - Remove comma in changelog entry - Remove unused NOTIFICATION_GROUP_KEY - Fix some formatting
1 parent 68d26f1 commit bf1c923

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ hs_err_pid*
2424
**/.gradle
2525
build
2626

27-
src/gen
27+
src/gen

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Added
66

7-
- Support for code formatting, via external commands ([#80](https://github.com/NixOS/nix-idea/pull/80))
7+
- Support for code formatting via external commands ([#80](https://github.com/NixOS/nix-idea/pull/80))
88

99
### Changed
1010

src/main/java/org/nixos/idea/lang/NixLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class NixLanguage extends Language {
66
public static final NixLanguage INSTANCE = new NixLanguage();
77
public static final String NOTIFICATION_GROUP_ID = "NixIDEA";
8-
public static final String NOTIFICATION_GROUP_KEY = "notification.group.nixidea";
8+
99
private NixLanguage() {
1010
super("Nix");
1111
}

src/main/java/org/nixos/idea/lsp/NixLspSettings.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
import com.intellij.openapi.components.State;
77
import com.intellij.openapi.components.Storage;
88
import org.jetbrains.annotations.NotNull;
9+
import org.nixos.idea.settings.NixStoragePaths;
910

1011
import java.util.ArrayDeque;
1112
import java.util.Collection;
1213
import java.util.Collections;
1314
import java.util.Deque;
1415

15-
@State(name = "NixLspSettings", storages = @Storage(value = "nix-idea-tools.xml", roamingType = RoamingType.DISABLED))
16+
@State(name = "NixLspSettings", storages = @Storage(value = NixStoragePaths.TOOLS, roamingType = RoamingType.DISABLED))
1617
public final class NixLspSettings implements PersistentStateComponent<NixLspSettings.State> {
1718

18-
// TODO: Use RoamingType.LOCAL with 2024.1
19-
2019
// Documentation:
2120
// https://plugins.jetbrains.com/docs/intellij/persisting-state-of-components.html
2221

src/main/java/org/nixos/idea/settings/NixExternalFormatterSettings.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
import java.util.Collections;
1313
import java.util.Deque;
1414

15-
@State(name = "NixExternalFormatterSettings", storages = @Storage(value = "nix-idea-ext-fmt.xml", roamingType = RoamingType.DISABLED))
15+
@State(name = "NixExternalFormatterSettings", storages = @Storage(value = NixStoragePaths.TOOLS, roamingType = RoamingType.DISABLED))
1616
public final class NixExternalFormatterSettings implements PersistentStateComponent<NixExternalFormatterSettings.State> {
1717

18-
// TODO: Use RoamingType.LOCAL with 2024.1
19-
2018
// Documentation:
2119
// https://plugins.jetbrains.com/docs/intellij/persisting-state-of-components.html
2220

@@ -29,28 +27,28 @@ public final class NixExternalFormatterSettings implements PersistentStateCompon
2927
}
3028

3129
public boolean isFormatEnabled() {
32-
return myState.formatEnabled;
30+
return myState.enabled;
3331
}
3432

3533
public void setFormatEnabled(boolean enabled) {
36-
myState.formatEnabled = enabled;
34+
myState.enabled = enabled;
3735
}
3836

3937
public @NotNull String getFormatCommand() {
40-
return myState.formatCommand;
38+
return myState.command;
4139
}
4240

4341
public void setFormatCommand(@NotNull String command) {
44-
myState.formatCommand = command;
42+
myState.command = command;
4543
addFormatCommandToHistory(command);
4644
}
4745

4846
public @NotNull Collection<String> getCommandHistory() {
49-
return Collections.unmodifiableCollection(myState.formatCommandHistory);
47+
return Collections.unmodifiableCollection(myState.history);
5048
}
5149

5250
private void addFormatCommandToHistory(@NotNull String command) {
53-
Deque<String> history = myState.formatCommandHistory;
51+
Deque<String> history = myState.history;
5452
history.remove(command);
5553
history.addFirst(command);
5654
while (history.size() > MAX_HISTORY_SIZE) {
@@ -71,8 +69,8 @@ public void loadState(@NotNull State state) {
7169
}
7270

7371
static final class State {
74-
public boolean formatEnabled = false;
75-
public @NotNull String formatCommand = "";
76-
public Deque<String> formatCommandHistory = new ArrayDeque<>();
72+
public boolean enabled = false;
73+
public @NotNull String command = "";
74+
public Deque<String> history = new ArrayDeque<>();
7775
}
7876
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.nixos.idea.settings;
2+
3+
import com.intellij.openapi.components.RoamingType;
4+
import com.intellij.openapi.components.Storage;
5+
6+
/**
7+
* Constants to be used for {@link Storage#value()}.
8+
*/
9+
public final class NixStoragePaths {
10+
11+
/**
12+
* Location and configuration of external tools.
13+
* The settings in the file are considered system dependent.
14+
* This constant must be used with {@link RoamingType#DISABLED}.
15+
* TODO: Use RoamingType.LOCAL with 2024.1
16+
*/
17+
public static final String TOOLS = "nix-idea-tools.xml";
18+
19+
private NixStoragePaths() {} // Cannot be instantiated
20+
21+
}

0 commit comments

Comments
 (0)