Hi vim-dev, First-time contributor here! I've got two patches for what I believe to be two separate issues in Java syntax highlighting.
I tried pinging Claudio, who's listed as the maintainer for them, but he hasn't responded to either of my emails, so per contributing.md I'm opening this up to the list. Thanks, Sam ---------- Forwarded message --------- From: Sam Lijin <[email protected]> Date: Wed, Jan 3, 2018 at 4:31 PM Subject: Vim Java Syntax Patch To: <[email protected]> Hi Claudio, I recently fixed - what I believe to be - two issues with Vim's native Java syntax highlighting rules. The first is that the javaAnnotation syntax group improperly includes, by virtue of wildcard regex matches, all arguments provided to a Java annotation, which can cause weird issues like a javaParenError (if one of the annotation arguments is a string which contains a closing parenthesis). The second is that the javaDocTags syntax region improperly includes javaCommentStar, which results in inline Javadoc tags highlighting any leading asterisks as part of the tag, rather than as a Java comment delimiter. Attached please find two patches which, I believe, are appropriate fixes for these issues. Please let me know if you agree or not. Thanks, Sam -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
From e2455268b8b89317f7f749d816d2f5c1aa0eb5f6 Mon Sep 17 00:00:00 2001 From: Samuel Lijin <[email protected]> Date: Wed, 3 Jan 2018 16:14:21 -0800 Subject: [PATCH] Fix javaCommentStar highlighting If there is a line break in an inline Javadoc tag, the asterisk that starts the line after the line break is currently highlighted as if it were part of the corresponding javaDocTags syntax region. This should not be the case; said asterisk should be highlighted as a javaCommentStar. To fix this, we simply modify the definition of the javaDocTags syntax region to include javaCommentStar syntax matches. --- runtime/syntax/java.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/syntax/java.vim b/runtime/syntax/java.vim index 89320597f..201a45552 100644 --- a/runtime/syntax/java.vim +++ b/runtime/syntax/java.vim @@ -157,7 +157,7 @@ if !exists("java_ignore_javadoc") && main_syntax != 'jsp' syn region javaDocComment start="/\*\*" end="\*/" keepend contains=javaCommentTitle,@javaHtml,javaDocTags,javaDocSeeTag,javaTodo,@Spell syn region javaCommentTitle contained matchgroup=javaDocComment start="/\*\*" matchgroup=javaCommentTitle keepend end="\.$" end="\.[ \t\r<&]"me=e-1 end="[^{]@"me=s-2,he=s-1 end="\*/"me=s-1,he=s-1 contains=@javaHtml,javaCommentStar,javaTodo,@Spell,javaDocTags,javaDocSeeTag - syn region javaDocTags contained start="{@\(code\|link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}" + syn region javaDocTags contained start="{@\(code\|link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}" contains=javaCommentStar syn match javaDocTags contained "@\(param\|exception\|throws\|since\)\s\+\S\+" contains=javaDocParam syn match javaDocParam contained "\s\S\+" syn match javaDocTags contained "@\(version\|author\|return\|deprecated\|serial\|serialField\|serialData\)\>" -- 2.15.1.620.gb9897f4670-goog
From f349a4a682485e57c0b1cbe339509cc64d3b2a87 Mon Sep 17 00:00:00 2001 From: Samuel Lijin <[email protected]> Date: Tue, 2 Jan 2018 13:53:30 -0800 Subject: [PATCH] Exclude args from javaAnnotation syntax group Currently the javaAnnotation syntax group includes all arguments supplied to a Java annotation, which can cause quirky behavior. For example, in the following Java code snippet: ```java @Metadata(todo = "Revise after releasing v6.0 (maybe v6.1?)") String foo = "bar"; ``` The last parenthesis on the @Metadata line is matched as a javaParenError, because the javaAnnotation regex identifies the ) inside the string as the closing parenthesis for the annotation. This is a consequence of the javaAnnotation regex itself being insufficiently expressive enough to capture the full range of arguments that can be supplied to a Java annotation. By removing the annotation arguments from the javaAnnotation syntax group, we tell Vim to use normal syntax matching on annotation arguments, which incidentally also resolves issues like those described above. --- runtime/syntax/java.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/syntax/java.vim b/runtime/syntax/java.vim index 89320597f..418a77182 100644 --- a/runtime/syntax/java.vim +++ b/runtime/syntax/java.vim @@ -54,7 +54,7 @@ syn match javaTypedef "\.\s*\<class\>"ms=s+1 syn keyword javaClassDecl enum syn match javaClassDecl "^class\>" syn match javaClassDecl "[^.]\s*\<class\>"ms=s+1 -syn match javaAnnotation "@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>\(([^)]*)\)\=" contains=javaString +syn match javaAnnotation "@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>" syn match javaClassDecl "@interface\>" syn keyword javaBranch break continue nextgroup=javaUserLabelRef skipwhite syn match javaUserLabelRef "\k\+" contained -- 2.15.1.620.gb9897f4670-goog
