Skip to content

Commit

Permalink
Comment * inserter by default IDEA framework
Browse files Browse the repository at this point in the history
  • Loading branch information
halirutan committed Dec 26, 2017
1 parent a53cb74 commit 4d77518
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ task wrapper(type: Wrapper) {
// Information about the plugin

// Plugin version number
version '3.0pre5'
version '3.0pre6'

intellij {
version = '2017.3.1'
Expand Down
2 changes: 1 addition & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.MathematicaEnterInsideFunctionHandler"/>
<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.MathematicaEnterAfterOperatorHandler"/>
<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.CommentStarInsertEnterHandler"/>
<!--<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.CommentStarInsertEnterHandler"/>-->

<liveTemplateContext implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaTemplateContextType"/>
<defaultLiveTemplatesProvider implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaDefaultLiveTemplateProvider"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

package de.halirutan.mathematica.codeinsight.editoractions;

import com.intellij.lang.Commenter;
import com.intellij.lang.CodeDocumentationAwareCommenter;
import com.intellij.psi.PsiComment;
import com.intellij.psi.tree.IElementType;
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -32,7 +35,7 @@
*
* @author patrick (3/22/13)
*/
public class MathematicaCommenter implements Commenter {
public class MathematicaCommenter implements CodeDocumentationAwareCommenter {
@Nullable
@Override
public String getLineCommentPrefix() {
Expand Down Expand Up @@ -65,12 +68,53 @@ public String getBlockCommentSuffix() {
@Nullable
@Override
public String getCommentedBlockCommentPrefix() {
return "*";
return "-";
}

@Nullable
@Override
public String getCommentedBlockCommentSuffix() {
return "+";
}

@Nullable
@Override
public IElementType getLineCommentTokenType() {
return null;
}

@Nullable
@Override
public IElementType getBlockCommentTokenType() {
return MathematicaElementTypes.COMMENT;
}

@Nullable
@Override
public IElementType getDocumentationCommentTokenType() {
return MathematicaElementTypes.COMMENT;
}

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

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

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

@Override
public boolean isDocumentationComment(PsiComment element) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import com.intellij.codeInsight.editorActions.enter.EnterHandlerDelegate
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiFile

/**
* @Note Currently unused!
* Inserts a * in each new line of a multi-line comment
* @author patrick (04.12.17).
*/
Expand All @@ -54,19 +54,10 @@ class CommentStarInsertEnterHandler : MathematicaEnterHandler() {
val document = editor.document
val textLength = document.textLength

// The case that we opened a comment with (*|) and therefore the complete file is commented
// We insert the missing *
if (comment.textRange.endOffset == textLength && offset < textLength && document.getText(TextRange.create(offset, offset + 1)) == ")") {
document.insertString(offset, " * \n *")
caretModel.moveToOffset(offset + 3)
psiDocManager.commitDocument(document)
return EnterHandlerDelegate.Result.Stop
}


val lineNumber = document.getLineNumber(offset)
val elementStartLine = document.getLineNumber(comment.textOffset)
val elementEndLine = document.getLineNumber(comment.textOffset + comment.textLength)
val lineStartOffset = document.getLineStartOffset(lineNumber)

val insertString: String
val move: Int
Expand All @@ -77,6 +68,7 @@ class CommentStarInsertEnterHandler : MathematicaEnterHandler() {
insertString = "* "
move = 2
}

document.insertString(offset, insertString)
caretModel.moveToOffset(offset + move)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
public class MathematicaFoldingOptionProvider extends BeanConfigurable<MathematicaCodeFoldingSettingsImpl> implements CodeFoldingOptionsProvider {
protected MathematicaFoldingOptionProvider() {
super(MathematicaCodeFoldingSettingsImpl.getInstance());
checkBox("CollapseNamedCharacters", "Collapse Mathematica Named Characters");
final MathematicaCodeFoldingSettingsImpl settings = MathematicaCodeFoldingSettingsImpl.getInstance();
checkBox("Collapse Mathematica Named Characters", settings::isCollapseNamedCharacters,
settings::setCollapseNamedCharacters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

package de.halirutan.mathematica.codeinsight.spellcheck;

import com.intellij.codeInspection.SuppressionUtil;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLanguageInjectionHost;
Expand Down Expand Up @@ -53,9 +52,9 @@ public Tokenizer getTokenizer(PsiElement element) {
if (element instanceof Symbol) return new PsiIdentifierOwnerTokenizer();
if (element instanceof MString) return TEXT_TOKENIZER;
if (element instanceof PsiComment) {
if (SuppressionUtil.isSuppressionComment(element)) {
return EMPTY_TOKENIZER;
}
// if (SuppressionUtil.isSuppressionComment(element)) {
// return EMPTY_TOKENIZER;
// }
return myCommentTokenizer;
}
return EMPTY_TOKENIZER;
Expand Down

0 comments on commit 4d77518

Please sign in to comment.