-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the commenter and live templates to FSH
- Loading branch information
Showing
4 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/main/java/ch/qligier/jetbrains/plugin/fss/fsh/FshCommenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2024 Quentin Ligier. Use of this source code is governed by the MIT license. | ||
|
||
package ch.qligier.jetbrains.plugin.fss.fsh; | ||
|
||
import com.intellij.lang.Commenter; | ||
import org.jspecify.annotations.Nullable; | ||
|
||
/** | ||
* Defines the support for "Comment with Line Comment" and "Comment with Block Comment" actions in the FSH language. | ||
* | ||
* @author Quentin Ligier | ||
* @see <a href="https://plugins.jetbrains.com/docs/intellij/additional-minor-features.html#comment-code">Comment | ||
* Code</a> | ||
* @see <a href="https://plugins.jetbrains.com/docs/intellij/commenter.html">Commenter</a> | ||
**/ | ||
public class FshCommenter implements Commenter { | ||
|
||
public static final String LINE_COMMENT_PREFIX = "//"; | ||
public static final String BLOCK_COMMENT_PREFIX = "/*"; | ||
public static final String BLOCK_COMMENT_SUFFIX = "*/"; | ||
|
||
public FshCommenter() { | ||
super(); | ||
System.out.println("FshCommenter built"); | ||
} | ||
|
||
/** | ||
* Returns the string that prefixes a line comment in the language, or null if the language doesn't support line | ||
* comments. If the language supports several prefixes for line comments, only one of them (the most recommended to | ||
* use) is returned. Use {@link #getLineCommentPrefixes()} to get all supported line comment prefixes. | ||
* | ||
* @return the line comment text, or null. | ||
*/ | ||
@Override | ||
public @Nullable String getLineCommentPrefix() { | ||
System.out.println("FshCommenter getLineCommentPrefix"); | ||
return LINE_COMMENT_PREFIX; | ||
} | ||
|
||
/** | ||
* Returns the string which marks the beginning of a block comment in the language, or null if the language doesn't | ||
* support block comments. | ||
* | ||
* @return the block comment start text, or null. | ||
*/ | ||
@Override | ||
public @Nullable String getBlockCommentPrefix() { | ||
System.out.println("FshCommenter getBlockCommentPrefix"); | ||
return BLOCK_COMMENT_PREFIX; | ||
} | ||
|
||
/** | ||
* Returns the string which marks the end of a block comment in the language, or null if the language doesn't | ||
* support block comments. | ||
* | ||
* @return the block comment end text, or null. | ||
*/ | ||
@Override | ||
public @Nullable String getBlockCommentSuffix() { | ||
System.out.println("FshCommenter getBlockCommentSuffix"); | ||
return BLOCK_COMMENT_SUFFIX; | ||
} | ||
|
||
/** | ||
* Returns the string which marks the commented beginning of a block comment in the language, or null if the | ||
* language doesn't support block comments. | ||
* | ||
* @return the commented block comment start text, or null. | ||
*/ | ||
@Override | ||
public @Nullable String getCommentedBlockCommentPrefix() { | ||
System.out.println("FshCommenter getCommentedBlockCommentPrefix"); | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the string which marks the commented end of a block comment in the language, or null if the language | ||
* doesn't support block comments. | ||
* | ||
* @return the commented block comment end text, or null. | ||
*/ | ||
@Override | ||
public @Nullable String getCommentedBlockCommentSuffix() { | ||
System.out.println("FshCommenter getCommentedBlockCommentSuffix"); | ||
return null; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/ch/qligier/jetbrains/plugin/fss/fsh/FshTemplateContextType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2024 Quentin Ligier. Use of this source code is governed by the MIT license. | ||
|
||
package ch.qligier.jetbrains.plugin.fss.fsh; | ||
|
||
import com.intellij.codeInsight.template.TemplateActionContext; | ||
import com.intellij.codeInsight.template.TemplateContextType; | ||
import org.jspecify.annotations.NonNull; | ||
|
||
/** | ||
* A TemplateContextType tells the IntelliJ Platform where the Live Template is applicable: FSH files. | ||
* | ||
* @author Quentin Ligier | ||
* @see <a | ||
* href="https://plugins.jetbrains.com/docs/intellij/template-support.html#implement-templatecontexttype">Implement | ||
* TemplateContextType</a> | ||
**/ | ||
public class FshTemplateContextType extends TemplateContextType { | ||
|
||
protected FshTemplateContextType() { | ||
super("FSH"); | ||
} | ||
|
||
@Override | ||
public boolean isInContext(@NonNull final TemplateActionContext templateActionContext) { | ||
return templateActionContext.getFile().getName().endsWith(".fsh"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!-- | ||
~ Copyright 2024 Quentin Ligier. Use of this source code is governed by the MIT license. | ||
--> | ||
<templateSet group="FSH"> | ||
<template name="profile" | ||
value="Profile: $NAME$ Parent: $PARENT$ Id: $ID$ Title: "$TITLE$" Description: "$DESCRIPTION$" * $RULE$" | ||
description="Create a new Profile" | ||
toReformat="false" | ||
toShortenFQNames="true"> | ||
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true"/> | ||
<variable name="PARENT" expression="" defaultValue="" alwaysStopAt="true"/> | ||
<variable name="ID" | ||
expression="regularExpression(lowercaseAndDash(NAME), "_", "-")" | ||
defaultValue="" | ||
alwaysStopAt="true"/> | ||
<variable name="TITLE" expression="NAME" defaultValue="" alwaysStopAt="true"/> | ||
<variable name="DESCRIPTION" expression="" defaultValue="" alwaysStopAt="true"/> | ||
<variable name="RULE" expression="" defaultValue="" alwaysStopAt="true"/> | ||
<context> | ||
<option name="FSH" value="true"/> | ||
</context> | ||
</template> | ||
|
||
<template name="alias" | ||
value="Alias: $$$NAME$ = $URN$" | ||
description="Create a new Alias" | ||
toReformat="false" | ||
toShortenFQNames="true"> | ||
<variable name="NAME" expression="" defaultValue="" alwaysStopAt="true"/> | ||
<variable name="URN" expression="" defaultValue="" alwaysStopAt="true"/> | ||
<context> | ||
<option name="FSH" value="true"/> | ||
</context> | ||
</template> | ||
</templateSet> |