Skip to content

Commit

Permalink
Merge pull request #25 from Saberos/master
Browse files Browse the repository at this point in the history
  • Loading branch information
JojOatXGME authored Jan 20, 2021
2 parents d332de0 + f8c88b6 commit 32cd831
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]
### Added
- Support line comment and block comment IDEA actions
## [0.3.0.4]
### Added
- Support for IDEA 2020.3
### Removed
- Support for IDEA 2019.3
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = org.nixos.idea
pluginName = NixIDEA
pluginVersion = 0.3.0.4
pluginVersion = 0.3.0.5
pluginSinceBuild = 201
pluginUntilBuild = 203.*
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/nixos/idea/lang/NixCommenter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.nixos.idea.lang;

import com.intellij.lang.Commenter;
import org.jetbrains.annotations.Nullable;

public class NixCommenter implements Commenter {
@Override
public @Nullable String getLineCommentPrefix() {
return "#";
}

@Override
public @Nullable String getBlockCommentPrefix() {
return "/*";
}

@Override
public @Nullable String getBlockCommentSuffix() {
return "*/";
}

@Override
public @Nullable String getCommentedBlockCommentPrefix() {
return null;
}

@Override
public @Nullable String getCommentedBlockCommentSuffix() {
return null;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
language="Nix"
implementationClass="org.nixos.idea.lang.NixBraceMatcher" />

<lang.commenter
language="Nix"
implementationClass="org.nixos.idea.lang.NixCommenter"/>

<projectConfigurable
groupId="build"
displayName="NixIDEA Settings"
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/nixos/idea/lang/NixCommenterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.nixos.idea.lang;

import com.intellij.codeInsight.generation.actions.CommentByBlockCommentAction;
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import org.nixos.idea.file.NixFileType;

public class NixCommenterTest extends BasePlatformTestCase {

public void testLineComment() {
myFixture.configureByText(NixFileType.INSTANCE, "<caret>services.nginx.enable = true;");

CommentByLineCommentAction commentAction = new CommentByLineCommentAction();
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
myFixture.checkResult("#services.nginx.enable = true;");
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
myFixture.checkResult("services.nginx.enable = true;");
}

public void testBlockComment() {
myFixture.configureByText(NixFileType.INSTANCE, "<selection><caret>services.nginx.enable = true;</selection>\n");

CommentByBlockCommentAction commentAction = new CommentByBlockCommentAction();
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
myFixture.checkResult("/*services.nginx.enable = true;*/\n");
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
myFixture.checkResult("services.nginx.enable = true;\n");
}
}

0 comments on commit 32cd831

Please sign in to comment.