Skip to content

Match more docstrings #141

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions syntax/swift.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ syntax keyword swiftMarker contained MARK
" In comment identifiers
function! s:CommentKeywordMatch(keyword)
execute "syntax match swiftDocString \"\\v^\\s*-\\s*". a:keyword . "\\W\"hs=s+1,he=e-1 contained"
" Same as above but in lines that start with /// or * (in /*...*/ comments)
execute "syntax match swiftDocString \"\\v(^\\s*(\\/\\/\\/|\\*)?\\s*-\\s*)@<=". a:keyword ."\\W\"he=e-1 contained"
endfunction

syntax case ignore

" Match parameters in strings like ` - parameter foo: definiton`
syntax match swiftDocStringParam "\v(^\s*(\/\/\/|\*)?\s*-\s*parameter\s*)@<=\w+" contained
" Match the parameter in lines like ' - param foo: definiton'. This is useful when
" ' - Parameters:' is used in the doc string, with each parameter on a new
" line
syntax match swiftDocStringParam "\v(^\s*(\/\/\/|\*)?\s*-\s)@<=\w+:"he=e-1 contained
" Match inline code in comments
syntax region swiftDocStringInlineCode start=/`/hs=e+1 end=/`/he=s-1 contained

call s:CommentKeywordMatch("attention")
call s:CommentKeywordMatch("author")
call s:CommentKeywordMatch("authors")
Expand All @@ -33,6 +44,7 @@ call s:CommentKeywordMatch("important")
call s:CommentKeywordMatch("invariant")
call s:CommentKeywordMatch("note")
call s:CommentKeywordMatch("parameter")
call s:CommentKeywordMatch("parameters")
call s:CommentKeywordMatch("postcondition")
call s:CommentKeywordMatch("precondition")
call s:CommentKeywordMatch("remark")
Expand Down Expand Up @@ -254,14 +266,16 @@ syntax keyword swiftPreprocessor

" Comment patterns
syntax match swiftComment "\v\/\/.*$"
\ contains=swiftTodos,swiftDocString,swiftMarker,@Spell oneline
\ contains=swiftTodos,swiftDocString,swiftDocStringParam,swiftDocStringInlineCode,swiftMarker,@Spell oneline
syntax region swiftComment start="/\*" end="\*/"
\ contains=swiftTodos,swiftDocString,swiftMarker,@Spell fold
\ contains=swiftTodos,swiftDocString,swiftDocStringParam,swiftDocStringInlineCode,swiftMarker,@Spell fold


" Set highlights
highlight default link swiftTodos Todo
highlight default link swiftDocString String
highlight default link swiftDocStringParam SpecialComment
highlight default link swiftDocStringInlineCode SpecialComment
highlight default link swiftShebang Comment
highlight default link swiftComment Comment
highlight default link swiftMarker Comment
Expand Down