Is there any way to detect if end-of-line comments are supported?
Given an arbitrary PsiFile I would like to know if the file/language/filetype at the current cursor location supports end-of-line comments or not. E.g. in Java code a comment may be placed at the end of the line, whereas in a properties file a comment must start at the beginning of the line. Is there some possibility to get this through either Language, FileType, or whatever else?
Please sign in to leave a comment.
Hello Dmitry,
I don't want to know if line comments are supported at all, but if a
line comment may be placed at the end of a line. E.g. line comments are
supported in a properties file, but it is not allowed to write something
like that:
key = value # some comment
Instead you have to write:
\# some comment
key = value
Both are line comments, and I would like to know that the first form is
invalid.
Dmitry Jemerov wrote:
>> Given an arbitrary PsiFile I would like to know if the
>> file/language/filetype at the current cursor location supports
>> end-of-line comments or not. E.g. in Java code a comment may be placed
>> at the end of the line, whereas in a properties file a comment must
>> start at the beginning of the line. Is there some possibility to get
>> this through either Language, FileType, or whatever else?
--
Martin Fuhrer
Fuhrer Engineering AG
http://www.fuhrer.com
Hello Martin,
Commenter.getLineCommentPrefix() != null
To get a commenter from a language, use Language.getCommenter() in Selena
and LanguageCommenters.INSTANCE.forLanguage() in Diana.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"