Skip to content

Commit 4d77518

Browse files
committed
Comment * inserter by default IDEA framework
1 parent a53cb74 commit 4d77518

6 files changed

Lines changed: 58 additions & 21 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ task wrapper(type: Wrapper) {
7575
// Information about the plugin
7676

7777
// Plugin version number
78-
version '3.0pre5'
78+
version '3.0pre6'
7979

8080
intellij {
8181
version = '2017.3.1'

resources/META-INF/plugin.xml

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

6868
<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.MathematicaEnterInsideFunctionHandler"/>
6969
<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.MathematicaEnterAfterOperatorHandler"/>
70-
<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.CommentStarInsertEnterHandler"/>
70+
<!--<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.CommentStarInsertEnterHandler"/>-->
7171

7272
<liveTemplateContext implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaTemplateContextType"/>
7373
<defaultLiveTemplatesProvider implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaDefaultLiveTemplateProvider"/>

src/de/halirutan/mathematica/codeinsight/editoractions/MathematicaCommenter.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121

2222
package de.halirutan.mathematica.codeinsight.editoractions;
2323

24-
import com.intellij.lang.Commenter;
24+
import com.intellij.lang.CodeDocumentationAwareCommenter;
25+
import com.intellij.psi.PsiComment;
26+
import com.intellij.psi.tree.IElementType;
27+
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes;
2528
import org.jetbrains.annotations.Nullable;
2629

2730
/**
@@ -32,7 +35,7 @@
3235
*
3336
* @author patrick (3/22/13)
3437
*/
35-
public class MathematicaCommenter implements Commenter {
38+
public class MathematicaCommenter implements CodeDocumentationAwareCommenter {
3639
@Nullable
3740
@Override
3841
public String getLineCommentPrefix() {
@@ -65,12 +68,53 @@ public String getBlockCommentSuffix() {
6568
@Nullable
6669
@Override
6770
public String getCommentedBlockCommentPrefix() {
68-
return "*";
71+
return "-";
6972
}
7073

7174
@Nullable
7275
@Override
7376
public String getCommentedBlockCommentSuffix() {
77+
return "+";
78+
}
79+
80+
@Nullable
81+
@Override
82+
public IElementType getLineCommentTokenType() {
7483
return null;
7584
}
85+
86+
@Nullable
87+
@Override
88+
public IElementType getBlockCommentTokenType() {
89+
return MathematicaElementTypes.COMMENT;
90+
}
91+
92+
@Nullable
93+
@Override
94+
public IElementType getDocumentationCommentTokenType() {
95+
return MathematicaElementTypes.COMMENT;
96+
}
97+
98+
@Nullable
99+
@Override
100+
public String getDocumentationCommentPrefix() {
101+
return "(**";
102+
}
103+
104+
@Nullable
105+
@Override
106+
public String getDocumentationCommentLinePrefix() {
107+
return "*";
108+
}
109+
110+
@Nullable
111+
@Override
112+
public String getDocumentationCommentSuffix() {
113+
return "*)";
114+
}
115+
116+
@Override
117+
public boolean isDocumentationComment(PsiComment element) {
118+
return true;
119+
}
76120
}

src/de/halirutan/mathematica/codeinsight/editoractions/enter/CommentStarInsertEnterHandler.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate
2929
import com.intellij.openapi.actionSystem.CommonDataKeys
3030
import com.intellij.openapi.actionSystem.DataContext
3131
import com.intellij.openapi.editor.Editor
32-
import com.intellij.openapi.util.TextRange
3332
import com.intellij.psi.PsiComment
3433
import com.intellij.psi.PsiDocumentManager
3534
import com.intellij.psi.PsiFile
3635

3736
/**
37+
* @Note Currently unused!
3838
* Inserts a * in each new line of a multi-line comment
3939
* @author patrick (04.12.17).
4040
*/
@@ -54,19 +54,10 @@ class CommentStarInsertEnterHandler : MathematicaEnterHandler() {
5454
val document = editor.document
5555
val textLength = document.textLength
5656

57-
// The case that we opened a comment with (*|) and therefore the complete file is commented
58-
// We insert the missing *
59-
if (comment.textRange.endOffset == textLength && offset < textLength && document.getText(TextRange.create(offset, offset + 1)) == ")") {
60-
document.insertString(offset, " * \n *")
61-
caretModel.moveToOffset(offset + 3)
62-
psiDocManager.commitDocument(document)
63-
return EnterHandlerDelegate.Result.Stop
64-
}
65-
66-
6757
val lineNumber = document.getLineNumber(offset)
6858
val elementStartLine = document.getLineNumber(comment.textOffset)
6959
val elementEndLine = document.getLineNumber(comment.textOffset + comment.textLength)
60+
val lineStartOffset = document.getLineStartOffset(lineNumber)
7061

7162
val insertString: String
7263
val move: Int
@@ -77,6 +68,7 @@ class CommentStarInsertEnterHandler : MathematicaEnterHandler() {
7768
insertString = "* "
7869
move = 2
7970
}
71+
8072
document.insertString(offset, insertString)
8173
caretModel.moveToOffset(offset + move)
8274

src/de/halirutan/mathematica/codeinsight/folding/MathematicaFoldingOptionProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
public class MathematicaFoldingOptionProvider extends BeanConfigurable<MathematicaCodeFoldingSettingsImpl> implements CodeFoldingOptionsProvider {
3131
protected MathematicaFoldingOptionProvider() {
3232
super(MathematicaCodeFoldingSettingsImpl.getInstance());
33-
checkBox("CollapseNamedCharacters", "Collapse Mathematica Named Characters");
33+
final MathematicaCodeFoldingSettingsImpl settings = MathematicaCodeFoldingSettingsImpl.getInstance();
34+
checkBox("Collapse Mathematica Named Characters", settings::isCollapseNamedCharacters,
35+
settings::setCollapseNamedCharacters);
3436
}
3537

3638
}

src/de/halirutan/mathematica/codeinsight/spellcheck/MathematicaSpellCheck.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
package de.halirutan.mathematica.codeinsight.spellcheck;
2323

24-
import com.intellij.codeInspection.SuppressionUtil;
2524
import com.intellij.psi.PsiComment;
2625
import com.intellij.psi.PsiElement;
2726
import com.intellij.psi.PsiLanguageInjectionHost;
@@ -53,9 +52,9 @@ public Tokenizer getTokenizer(PsiElement element) {
5352
if (element instanceof Symbol) return new PsiIdentifierOwnerTokenizer();
5453
if (element instanceof MString) return TEXT_TOKENIZER;
5554
if (element instanceof PsiComment) {
56-
if (SuppressionUtil.isSuppressionComment(element)) {
57-
return EMPTY_TOKENIZER;
58-
}
55+
// if (SuppressionUtil.isSuppressionComment(element)) {
56+
// return EMPTY_TOKENIZER;
57+
// }
5958
return myCommentTokenizer;
6059
}
6160
return EMPTY_TOKENIZER;

0 commit comments

Comments
 (0)