Skip to content

Commit

Permalink
[nvim] add the universal TODO comment system
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitmel committed Dec 15, 2021
1 parent d5896b1 commit 686189e
Show file tree
Hide file tree
Showing 28 changed files with 156 additions and 8 deletions.
4 changes: 4 additions & 0 deletions nvim/after/syntax/awk.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('awkTodo')
syn clear awkTodo
execute 'syn match awkTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/c.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('cTodo')
syn clear cTodo
execute 'syn match cTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/cs.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('csTodo')
syn clear csTodo
execute 'syn match csTodo contained' dotfiles#todo_comments#get_pattern()
endif
7 changes: 7 additions & 0 deletions nvim/after/syntax/css.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if !hlexists('cssTodo') && hlexists('cssComment')
execute 'syn match cssTodo contained containedin=cssComment' dotfiles#todo_comments#get_pattern()
hi def link cssTodo Todo
elseif hlexists('cssTodo')
syn clear cssTodo
execute 'syn match cssTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/go.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('goTodo')
syn clear goTodo
execute 'syn match goTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/haskell.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('haskellTodo')
syn clear haskellTodo
execute 'syn match haskellTodo contained' dotfiles#todo_comments#get_pattern()
endif
7 changes: 7 additions & 0 deletions nvim/after/syntax/html.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if !hlexists('htmlTodo') && hlexists('htmlComment')
execute 'syn match htmlTodo contained containedin=htmlComment' dotfiles#todo_comments#get_pattern()
hi def link htmlTodo Todo
elseif hlexists('htmlTodo')
syn clear htmlTodo
execute 'syn match htmlTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/java.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('javaTodo')
syn clear javaTodo
execute 'syn match javaTodo contained' dotfiles#todo_comments#get_pattern()
endif
10 changes: 10 additions & 0 deletions nvim/after/syntax/javascript.vim
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
syntax sync minlines=500

if hlexists('javaScriptCommentTodo')
syn clear javaScriptCommentTodo
execute 'syn match javaScriptCommentTodo contained' dotfiles#todo_comments#get_pattern()
endif

if hlexists('jsCommentTodo')
syn clear jsCommentTodo
execute 'syn match jsCommentTodo contained' dotfiles#todo_comments#get_pattern()
endif
5 changes: 5 additions & 0 deletions nvim/after/syntax/json.vim
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
syntax match Comment +\/\/.\+$+

if hlexists('jsonCommentTodo')
syn clear jsonCommentTodo
execute 'syn match jsonCommentTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/jsonc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('jsonCommentTodo')
syn clear jsonCommentTodo
execute 'syn match jsonCommentTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/kotlin.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('ktTodo')
syn clear ktTodo
execute 'syn match ktTodo contained' dotfiles#todo_comments#get_pattern()
endif
8 changes: 8 additions & 0 deletions nvim/after/syntax/lua.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if hlexists('luaTodo')
syn clear luaTodo
execute 'syn match luaTodo contained' dotfiles#todo_comments#get_pattern()
endif
if hlexists('luaCommentTodo')
syn clear luaCommentTodo
execute 'syn match luaCommentTodo contained' dotfiles#todo_comments#get_pattern()
endif
7 changes: 5 additions & 2 deletions nvim/after/syntax/python.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
if b:current_syntax !=# 'python' | finish | endif

let s:saved_syntax = b:current_syntax
let s:restore_syn_case = trim(execute('syntax case', 'silent'))
unlet! b:current_syntax
Expand All @@ -20,3 +18,8 @@ syn region pythonSqlString start=/\v\C\z("""|''')\zs\_s*<(sql|SQL|SELECT|INSERT|

syn keyword pythonOperatorKeyword and in is not or
hi def link pythonOperatorKeyword Keyword

if hlexists('pythonTodo')
syn clear pythonTodo
execute 'syn match pythonTodo contained' dotfiles#todo_comments#get_pattern()
endif
18 changes: 12 additions & 6 deletions nvim/after/syntax/qf.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
if b:current_syntax !=# 'qf' | finish | endif
" Extension for <https://github.com/neovim/neovim/blob/v0.5.0/runtime/syntax/qf.vim>.

syn match qfLineNr "[^|]*" contained contains=qfError,qfWarning,qfInfo,qfNote
Expand All @@ -9,8 +8,15 @@ syn match qfError "error" contained
syn match qfWarning "warning" contained
syn match qfInfo "info" contained
syn match qfNote "note" contained
"
hi def link qfError LspDiagnosticsDefaultError
hi def link qfWarning LspDiagnosticsDefaultWarning
hi def link qfInfo LspDiagnosticsDefaultInformation
hi def link qfNote LspDiagnosticsDefaultHint

if has('nvim-0.6.0')
hi def link qfError DiagnosticError
hi def link qfWarning DiagnosticWarning
hi def link qfInfo DiagnosticInformation
hi def link qfNote DiagnosticHint
else
hi def link qfError LspDiagnosticsDefaultError
hi def link qfWarning LspDiagnosticsDefaultWarning
hi def link qfInfo LspDiagnosticsDefaultInformation
hi def link qfNote LspDiagnosticsDefaultHint
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/ruby.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('rubyTodo')
syn clear rubyTodo
execute 'syn match rubyTodo contained' dotfiles#todo_comments#get_pattern()
endif
5 changes: 5 additions & 0 deletions nvim/after/syntax/rust.vim
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
syn keyword rustOperatorKeyword as
hi def link rustOperatorKeyword Keyword

if hlexists('rustTodo')
syn clear rustTodo
execute 'syn match rustTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/sass.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('sassTodo')
syn clear sassTodo
execute 'syn match sassTodo contained' dotfiles#todo_comments#get_pattern()
endif
9 changes: 9 additions & 0 deletions nvim/after/syntax/scss.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
" The VIMRUNTIME syntax file sources the syntax files for SASS (from
" runtimepath, so it will load my todo-comment patch with it) and makes a few
" minor modifications to the rules to accomodate for SCSS, vim-polyglot defines
" an entirely separate file for SCSS with its own hlgroups, so this branch will
" only execute for vim-polyglot's syntax file.
if hlexists('scssTodo')
syn clear scssTodo
execute 'syn match scssTodo contained containedin=@comment' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/sh.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('shTodo')
syn clear shTodo
execute 'syn match shTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/sql.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('sqlTodo')
syn clear sqlTodo
execute 'syn match sqlTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/toml.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('tomlTodo')
syn clear tomlTodo
execute 'syn match tomlTodo contained' dotfiles#todo_comments#get_pattern()
endif
5 changes: 5 additions & 0 deletions nvim/after/syntax/typescript.vim
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
source <sfile>:h/javascript.vim

if hlexists('typescriptCommentTodo')
syn clear typescriptCommentTodo
execute 'syn match typescriptCommentTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/vim.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('vimTodo')
syn clear vimTodo
execute 'syn match vimTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/xml.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('xmlTodo')
syn clear xmlTodo
execute 'syn match xmlTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/yaml.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('yamlTodo')
syn clear yamlTodo
execute 'syn match yamlTodo contained' dotfiles#todo_comments#get_pattern()
endif
4 changes: 4 additions & 0 deletions nvim/after/syntax/zsh.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if hlexists('zshTodo')
syn clear zshTodo
execute 'syn match zshTodo contained' dotfiles#todo_comments#get_pattern()
endif
15 changes: 15 additions & 0 deletions nvim/autoload/dotfiles/todo_comments.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
" Helper file for the universal TODO comments system. It is used by files in
" `after/syntax/` to extend the built-in hlgroups to have somewhat unified
" lists of keywords.

" This rejected PEP has a semi-formal list of these markers: <https://www.python.org/dev/peps/pep-0350/#mnemonics>.
" "SAFETY" originates from Rust.
let g:dotfiles#todo_comments#keywords = ['TODO', 'NOTE', 'HACK', 'FIXME', 'XXX', 'BUG', 'SAFETY']

" The pattern idea was taken from <https://github.com/dmitmel/neovim/blob/e65b724451ba5f65dfcaf8f8c16afdd508db7359/runtime/syntax/sh.vim#L396-L400>
" and <https://github.com/wbthomason/dotfiles/blob/9134e87b00102cda07f875805f900775244067fe/neovim/.config/nvim/init.lua#L88>.
function! dotfiles#todo_comments#get_pattern() abort
let pat = '\V\C\<\%(' . join(map(g:dotfiles#todo_comments#keywords, { _, s -> escape(s, '\') }), '\|') . '\)\ze:\=\>'
let wrap_char = '/'
return wrap_char . escape(pat, wrap_char) . wrap_char
endfunction

0 comments on commit 686189e

Please sign in to comment.