-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Line Comment
-Action
#42
Comments
You can use the normal commenting shortcut Strg+/ or over the context menu (theoretically). Or what do you mean by command? |
Maybe another plugin that does not differentiate between batch and another file type...
Probably because these Actions have to be added when creating a plugin. |
|
I too have these menu items, but they don't do anything -- or actually behave like |
Hi all, I know it's been 2 years since this issue was raised but just wanted to give an update. I have some experience with IntelliJ language plugin development and I did some debugging today on this particular issue. It turns out that this plugin does not define a PsiFile type for Batch scripts so when IntelliJ executes the "Toggle Line Comment" action, it "calculates" that the PsiFile type for the .bat file must be "plain text" and so it essentially does nothing except move the cursor down when you execute the line comment action. To verify this, you can set a debug point at the @Nullable
private static Commenter findCommenter(@NotNull Editor editor, @NotNull PsiFile file, final int line) {
final FileType fileType = file.getFileType();
if (fileType instanceof AbstractFileType) {
return ((AbstractFileType)fileType).getCommenter();
}
final Language lineStartLanguage = getLineStartLanguage(editor, file, line);
final Language lineEndLanguage = getLineEndLanguage(file, editor, line);
return CommentByBlockCommentHandler.getCommenter(file, editor, lineStartLanguage, lineEndLanguage);
} and you will see that You can see where the PsiFile gets detected from by setting a debug point on this line: private static void iterateOverCarets(@NotNull final Project project,
@NotNull final Editor hostEditor,
@NotNull final MultiCaretCodeInsightActionHandler handler) {
PsiFile hostFile = PsiDocumentManager.getInstance(project).getPsiFile(hostEditor.getDocument());
... To fix this, you would need to follow the plugin documentation starting from this section to register a new Batch PsiFile: https://plugins.jetbrains.com/docs/intellij/lexer-and-parser-definition.html#define-a-root-file public class BatchFile extends PsiFileBase {
... etc. I attempted to take a stab at it but it's more involved than I initially thought since you would also need a Parser class as defined in the previous section of the documentation here: https://plugins.jetbrains.com/docs/intellij/grammar-and-parser.html Tbh though, I'm not sure if it's worth it - I had installed this plugin for syntax highlighting but I realized during my testing that IntelliJ by default automatically highlights batch & cmd files, and it also has advanced capabilities around commenting and auto-completing commands. The syntax highlighting in this plugin is prettier than theirs, but when the IntelliJ team themselves are already providing highlighting support for batch files (and will likely continue to update it in the future), then it doesn't really make sense to duplicate their work. I think a better route would be to contact the IntelliJ team on their slack (https://jetbrains-platform.slack.com/) and see if we can configure this plugin to augment the native functionality they are already providing since they do not provide batch run configs or batch file icons. (I am very aware that writing a working Flex file for a language takes many days of testing, so I do understand if the plugin author isn't willing to replace it in favor of IntelliJ's native highlighting) Last but not least, if a junit test had been added for the commenting functionality before it was merged to master, it would have caught this issue immediately. You can add this Junit test (copied straight from the plugin docs) into this repo and you will see that it fails due to the aforementioned reasons above: package org.intellij.lang.batch.editor;
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
import org.intellij.lang.batch.fileTypes.BatchFileType;
import org.junit.Test;
public class BatchCommenterTest extends BasePlatformTestCase {
@Test
public void testCommenter() {
myFixture.configureByText(BatchFileType.BATCH_FILE_TYPE, "<caret>echo hi");
CommentByLineCommentAction commentAction = new CommentByLineCommentAction();
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
myFixture.checkResult("rem echo hi");
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
myFixture.checkResult("echo hi");
}
} |
Ctrl+/ line comment doesn't work for me in GoLand 2022.1.4 😣 |
@takanuva15 is there no way to listen to the keybinding and just insert a rem on the currently selected line(s)? This should not be that hard, I get the "proper" way of doing it is complex but having to implement a full language file seems overkill. |
@smaudet I don't have hands-on experience hard-wiring a keybinding like that, but I think it could be possible if you were to follow the steps here from the IntelliJ SDK docs and assign a keyboard shortcut to In terms of defining a language file, IntelliJ has an opinionated framework for how to implement custom languages. If a developer follows that framework correctly, they're able to tap into the full power of the IntelliJ language engine to do things like commenting, autocomplete, error-checking, etc. with only a few lines of code. This avoids the need for any manual "hacks" that could take longer than just using the framework's natural injection points. (Note: this is not a refutation of anything you said, this is just a point to make based on my experience with developing a custom language plugin) |
@takanuva15 fair enough, perhaps the correct approach then would be to remove any language parsing from this plugin and just have one that does run configurations? I don't touch batch files often, but its a common enough thing to want to run a script/batch file and be able to both run and edit the code. I am/was happy with IntelliJ's default syntax/comment support, only thing missing was run config... |
@smaudet Yes that should be possible. However, there is also a run configuration type called "Shell Script" within IntelliJ - have you tried using that to configure/run your batch scripts? |
any update? thx. |
Would be nice to have a
REM
-Line Comment
-Command.The text was updated successfully, but these errors were encountered: