From f1c40fbd6603d85d66c94965f1c329bd3c07d402 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Fri, 1 Aug 2025 15:32:37 +0300 Subject: Configured todo comments in nvim --- .config/nvim/after/queries/bash/highlights.scm | 7 -- .config/nvim/after/queries/go/injections.scm | 108 ------------------------- .config/nvim/after/queries/go/locals.scm | 15 ---- .config/nvim/lua/plugins/todo-comments.lua | 89 ++++++++------------ .config/nvim/queries/bash/highlights.scm | 7 ++ .config/nvim/queries/comment/highlights.scm | 60 ++++++++++++++ .config/nvim/queries/go/injections.scm | 108 +++++++++++++++++++++++++ .config/nvim/queries/go/locals.scm | 15 ++++ 8 files changed, 225 insertions(+), 184 deletions(-) delete mode 100644 .config/nvim/after/queries/bash/highlights.scm delete mode 100644 .config/nvim/after/queries/go/injections.scm delete mode 100644 .config/nvim/after/queries/go/locals.scm create mode 100644 .config/nvim/queries/bash/highlights.scm create mode 100644 .config/nvim/queries/comment/highlights.scm create mode 100644 .config/nvim/queries/go/injections.scm create mode 100644 .config/nvim/queries/go/locals.scm (limited to '.config') diff --git a/.config/nvim/after/queries/bash/highlights.scm b/.config/nvim/after/queries/bash/highlights.scm deleted file mode 100644 index b7e6b17..0000000 --- a/.config/nvim/after/queries/bash/highlights.scm +++ /dev/null @@ -1,7 +0,0 @@ -;extends - -; highlight `return` and `exit` like return statements in other languages with -; `@keyword.return` - -((word) @keyword.return - (#any-of? @keyword.return "return" "exit")) diff --git a/.config/nvim/after/queries/go/injections.scm b/.config/nvim/after/queries/go/injections.scm deleted file mode 100644 index 5d5affc..0000000 --- a/.config/nvim/after/queries/go/injections.scm +++ /dev/null @@ -1,108 +0,0 @@ -; extends - -; inject sql in single line strings -; e.g. db.GetContext(ctx, "SELECT * FROM users WHERE name = 'John'") - -((call_expression - (selector_expression - field: (field_identifier) @_field) - (argument_list - (interpreted_string_literal) @sql)) - (#any-of? @_field "Exec" "GetContext" "ExecContext" "SelectContext" "In" - "RebindNamed" "Rebind" "Query" "QueryRow" "QueryRowxContext" "NamedExec" "MustExec" "Get" "Queryx") - (#offset! @sql 0 1 0 -1)) - -; still buggy for nvim 0.10 -((call_expression - (selector_expression - field: (field_identifier) @_field (#any-of? @_field "Exec" "GetContext" "ExecContext" "SelectContext" "In" "RebindNamed" "Rebind" "Query" "QueryRow" "QueryRowxContext" "NamedExec" "MustExec" "Get" "Queryx")) - (argument_list - (interpreted_string_literal) @injection.content)) - (#offset! @injection.content 0 1 0 -1) - (#set! injection.language "sql")) - -; neovim nightly 0.10 -([ - (interpreted_string_literal) - (raw_string_literal) - ] @injection.content - (#match? @injection.content "(SELECT|select|INSERT|insert|UPDATE|update|DELETE|delete).+(FROM|from|INTO|into|VALUES|values|SET|set).*(WHERE|where|GROUP BY|group by)?") - (#offset! @injection.content 0 1 0 -1) -(#set! injection.language "sql")) - -; a general query injection -([ - (interpreted_string_literal) - (raw_string_literal) - ] @sql - (#match? @sql "(SELECT|select|INSERT|insert|UPDATE|update|DELETE|delete).+(FROM|from|INTO|into|VALUES|values|SET|set).*(WHERE|where|GROUP BY|group by)?") - (#offset! @sql 0 1 0 -1)) - -; ---------------------------------------------------------------- -; fallback keyword and comment based injection - -([ - (interpreted_string_literal) - (raw_string_literal) - ] @sql - (#contains? @sql "-- sql" "--sql" "ADD CONSTRAINT" "ALTER TABLE" "ALTER COLUMN" - "DATABASE" "FOREIGN KEY" "GROUP BY" "HAVING" "CREATE INDEX" "INSERT INTO" - "NOT NULL" "PRIMARY KEY" "UPDATE SET" "TRUNCATE TABLE" "LEFT JOIN" "add constraint" "alter table" "alter column" "database" "foreign key" "group by" "having" "create index" "insert into" - "not null" "primary key" "update set" "truncate table" "left join") - (#offset! @sql 0 1 0 -1)) - -; nvim 0.10 -([ - (interpreted_string_literal) - (raw_string_literal) - ] @injection.content - (#contains? @injection.content "-- sql" "--sql" "ADD CONSTRAINT" "ALTER TABLE" "ALTER COLUMN" - "DATABASE" "FOREIGN KEY" "GROUP BY" "HAVING" "CREATE INDEX" "INSERT INTO" - "NOT NULL" "PRIMARY KEY" "UPDATE SET" "TRUNCATE TABLE" "LEFT JOIN" "add constraint" "alter table" "alter column" "database" "foreign key" "group by" "having" "create index" "insert into" - "not null" "primary key" "update set" "truncate table" "left join") - (#offset! @injection.content 0 1 0 -1) - (#set! injection.language "sql")) - - -; should I use a more exhaustive list of keywords? -; "ADD" "ADD CONSTRAINT" "ALL" "ALTER" "AND" "ASC" "COLUMN" "CONSTRAINT" "CREATE" "DATABASE" "DELETE" "DESC" "DISTINCT" "DROP" "EXISTS" "FOREIGN KEY" "FROM" "JOIN" "GROUP BY" "HAVING" "IN" "INDEX" "INSERT INTO" "LIKE" "LIMIT" "NOT" "NOT NULL" "OR" "ORDER BY" "PRIMARY KEY" "SELECT" "SET" "TABLE" "TRUNCATE TABLE" "UNION" "UNIQUE" "UPDATE" "VALUES" "WHERE" - -; json - -((const_spec - name: (identifier) @_const - value: (expression_list (raw_string_literal) @json)) - (#lua-match? @_const ".*[J|j]son.*")) - -; jsonStr := `{"foo": "bar"}` - -((short_var_declaration - left: (expression_list - (identifier) @_var) - right: (expression_list - (raw_string_literal) @json)) - (#lua-match? @_var ".*[J|j]son.*") - (#offset! @json 0 1 0 -1)) - -; nvim 0.10 - -(const_spec - name: (identifier) - value: (expression_list (raw_string_literal) @injection.content - (#lua-match? @injection.content "^`[\n|\t| ]*\{.*\}[\n|\t| ]*`$") - (#offset! @injection.content 0 1 0 -1) - (#set! injection.language "json"))) - -(short_var_declaration - left: (expression_list (identifier)) - right: (expression_list (raw_string_literal) @injection.content) - (#lua-match? @injection.content "^`[\n|\t| ]*\{.*\}[\n|\t| ]*`$") - (#offset! @injection.content 0 1 0 -1) - (#set! injection.language "json")) - -(var_spec - name: (identifier) - value: (expression_list (raw_string_literal) @injection.content - (#lua-match? @injection.content "^`[\n|\t| ]*\{.*\}[\n|\t| ]*`$") - (#offset! @injection.content 0 1 0 -1) - (#set! injection.language "json"))) diff --git a/.config/nvim/after/queries/go/locals.scm b/.config/nvim/after/queries/go/locals.scm deleted file mode 100644 index 9232669..0000000 --- a/.config/nvim/after/queries/go/locals.scm +++ /dev/null @@ -1,15 +0,0 @@ -; extends - -(var_spec) @local.scope - -(field_declaration - name: (field_identifier) @local.definition.field) - -(method_elem - name: (field_identifier) @function.method.name - parameters: (parameter_list) @function.method.parameter_list) @local.interface.method.declaration - -(type_declaration - (type_spec - name: (type_identifier) @local.name - type: [(struct_type) (interface_type)] @local.type)) @local.start diff --git a/.config/nvim/lua/plugins/todo-comments.lua b/.config/nvim/lua/plugins/todo-comments.lua index 5518f03..25a6330 100644 --- a/.config/nvim/lua/plugins/todo-comments.lua +++ b/.config/nvim/lua/plugins/todo-comments.lua @@ -1,17 +1,19 @@ -- NORMAL: lorem ipsum --- T ODO: lorem ipsum --- F IX: lorem ipsum --- O PTIMIZE: lorem ipsum --- W ARN: lorem ipsum --- P ERF: lorem ipsum --- H ACK: lorem ipsum --- N OTE: lorem ipsum --- T EST: lorem ipsum --- U NSAFE: lorem ipsum --- T ODO(kyren223): lorem ipsum --- N OTE:(broken) lorem ipsum --- t odo!(a); --- t odo!(aaa); +-- TODO: lorem ipsum +-- FIX: lorem ipsum +-- OPTIMIZE: lorem ipsum +-- WARN: lorem ipsum +-- PERF: lorem ipsum +-- HACK: lorem ipsum +-- NOTE: lorem ipsum +-- TEST: lorem ipsum +-- UNSAFE: lorem ipsum +-- TODO(kyren223): lorem ipsum +-- NOTE:(broken) lorem ipsum +-- todo!(a); +-- todo!(aaa); +-- Test +-- TODO: blabla return { 'folke/todo-comments.nvim', @@ -25,7 +27,7 @@ return { layout = 'telescope', follow = true, hidden = true, - keywords = { 'TODO', 'FIX', 'FIXME', 'BUG', 'ISSUE', 'OPTIMIZE' }, + keywords = { 'TODO', 'WIP', 'FIX', 'FIXME', 'BUG', 'OPTIMIZE', 'SECURE' }, }) end, desc = '[S]earch [T]odos', @@ -43,55 +45,34 @@ return { }, }, opts = { - signs = false, -- show icons in the signs column - sign_priority = 8, -- sign priority + signs = false, keywords = { -- These are "todos" - TODO = { icon = ' ', color = 'info', alt = { 'todo' } }, - FIX = { icon = ' ', color = 'error', alt = { 'FIXME', 'BUG', 'ISSUE' } }, - OPTIMIZE = { icon = ' ', color = 'performance' }, + TODO = { icon = ' ', color = 'todo', alt = { 'WIP' } }, + FIX = { icon = ' ', color = 'error', alt = { 'FIXME', 'BUG' } }, + OPTMZE = { icon = ' ', color = 'perf', alt = { 'OPTIMIZE' } }, + SECURE = { icon = '󰣮 ', color = 'warning' }, -- These are "notes" - WARN = { icon = ' ', color = 'warning', alt = { 'WARNING' } }, - PERF = { icon = ' ', color = 'performance', alt = { 'PERFORMANCE' } }, - HACK = { icon = ' ', color = 'warning', alt = { 'SMELL', 'CODE SMELL', 'BAD', 'BAD PRACTICE' } }, - NOTE = { icon = ' ', color = 'hint', alt = { 'INFO' } }, - TEST = { icon = '󰙨 ', color = 'test', alt = { 'TESTING', 'PASSED', 'FAILED' } }, + NOTE = { icon = ' ', color = 'note', alt = { 'INFO', 'DOCS' } }, + TEST = { icon = '󰙨 ', color = 'note' }, + WARN = { icon = ' ', color = 'warning', alt = { 'WARNING', 'SECURITY' } }, + HACK = { icon = ' ', color = 'warning' }, + PERF = { icon = ' ', color = 'perf' }, UNSAFE = { icon = '󰍛 ', color = 'error', alt = { 'SAFETY' } }, }, - gui_style = { - fg = 'NONE', - bg = 'BOLD', - }, - merge_keywords = true, -- when true, custom keywords will be merged with the defaults - -- highlighting of the line containing the todo comment - -- * before: highlights before the keyword (typically comment characters) - -- * keyword: highlights of the keyword - -- * after: highlights after the keyword (todo text) highlight = { - multiline = true, - multiline_pattern = '^.', -- lua pattern to match the next multiline from the start of the matched keyword - multiline_context = 10, -- extra lines that will be re-evaluated when changing a line before = '', -- "fg" or "bg" or empty - keyword = 'wide', -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg) - after = 'fg', -- "fg" or "bg" or empty - pattern = { - [[.*<((KEYWORDS)%(\(.{-1,}\))?):]], - [[((KEYWORDS)!%(\(.{-}\))?)]], - }, -- pattern or table of patterns, used for highlighting (vim regex) + keyword = '', -- "wide" or empty + after = '', -- "fg" or empty + pattern = { [[.*<((KEYWORDS)%(\(.{-1,}\))?):]] }, -- vim regex comments_only = false, - max_line_len = 400, - exclude = {}, -- list of excluded filetypes }, - -- list of named colors where we try to extract the gui fg from the - -- list of highlight groups or use the hex color if hl not found as a fallback colors = { - default = { 'Identifier', '#7C3AED' }, - error = { 'DiagnosticError', 'ErrorMsg', '#DC2626' }, - warning = { 'DiagnosticWarn', 'WarningMsg', '#FBBF24' }, - info = { 'DiagnosticInfo', '#2563EB' }, - hint = { '#10B981' }, - test = { 'Identifier', '#FF00FF' }, - performance = { '#7C3AED' }, + todo = { '@comment.todo' }, + note = { '@comment.todo' }, + warning = { '@comment.warning' }, + error = { '@comment.error' }, + perf = { '@comment.perf' }, }, search = { command = 'rg', @@ -104,7 +85,7 @@ return { '--hidden', -- show todos in hidden directories and files '--follow', -- follow symlinks }, - search = { pattern = [[\b(KEYWORDS)(\([^\)]*\))?:]] }, + pattern = [[\b(KEYWORDS)\s*(\([^\)]*\))?\s*:]], }, }, } diff --git a/.config/nvim/queries/bash/highlights.scm b/.config/nvim/queries/bash/highlights.scm new file mode 100644 index 0000000..b7e6b17 --- /dev/null +++ b/.config/nvim/queries/bash/highlights.scm @@ -0,0 +1,7 @@ +;extends + +; highlight `return` and `exit` like return statements in other languages with +; `@keyword.return` + +((word) @keyword.return + (#any-of? @keyword.return "return" "exit")) diff --git a/.config/nvim/queries/comment/highlights.scm b/.config/nvim/queries/comment/highlights.scm new file mode 100644 index 0000000..133b405 --- /dev/null +++ b/.config/nvim/queries/comment/highlights.scm @@ -0,0 +1,60 @@ +((tag + (name) @comment.todo @nospell + ("(" @punctuation.bracket + (user) @constant + ")" @punctuation.bracket)? + ":" @punctuation.delimiter) + (#any-of? @comment.todo "TODO" "WIP")) + +("text" @comment.todo @nospell + (#any-of? @comment.todo "TODO" "WIP")) + +((tag + (name) @comment.note @nospell + ("(" @punctuation.bracket + (user) @constant + ")" @punctuation.bracket)? + ":" @punctuation.delimiter) + (#any-of? @comment.note "NOTE" "INFO" "DOCS" "TEST")) + +("text" @comment.note @nospell + (#any-of? @comment.note "NOTE" "INFO" "DOCS" "TEST")) + +((tag + (name) @comment.perf @nospell + ("(" @punctuation.bracket + (user) @constant + ")" @punctuation.bracket)? + ":" @punctuation.delimiter) + (#any-of? @comment.perf "PERF" "OPTIMIZE")) + +("text" @comment.perf @nospell + (#any-of? @comment.perf "PERF" "OPTIMIZE")) + +((tag + (name) @comment.warning @nospell + ("(" @punctuation.bracket + (user) @constant + ")" @punctuation.bracket)? + ":" @punctuation.delimiter) + (#any-of? @comment.warning "HACK" "WARNING" "WARN" "SECURITY" "SECURE")) + +("text" @comment.warning @nospell + (#any-of? @comment.warning "HACK" "WARNING" "WARN" "SECURITY" "SECURE")) + +((tag + (name) @comment.error @nospell + ("(" @punctuation.bracket + (user) @constant + ")" @punctuation.bracket)? + ":" @punctuation.delimiter) + (#any-of? @comment.error "FIXME" "FIX" "BUG" "ERROR" "UNSAFE" "SAFETY")) + +("text" @comment.error @nospell + (#any-of? @comment.error "FIXME" "FIX" "BUG" "ERROR" "UNSAFE" "SAFETY")) + +; Issue number (#123) +("text" @number + (#lua-match? @number "^#[0-9]+$")) + +(uri) @string.special.url @nospell diff --git a/.config/nvim/queries/go/injections.scm b/.config/nvim/queries/go/injections.scm new file mode 100644 index 0000000..5d5affc --- /dev/null +++ b/.config/nvim/queries/go/injections.scm @@ -0,0 +1,108 @@ +; extends + +; inject sql in single line strings +; e.g. db.GetContext(ctx, "SELECT * FROM users WHERE name = 'John'") + +((call_expression + (selector_expression + field: (field_identifier) @_field) + (argument_list + (interpreted_string_literal) @sql)) + (#any-of? @_field "Exec" "GetContext" "ExecContext" "SelectContext" "In" + "RebindNamed" "Rebind" "Query" "QueryRow" "QueryRowxContext" "NamedExec" "MustExec" "Get" "Queryx") + (#offset! @sql 0 1 0 -1)) + +; still buggy for nvim 0.10 +((call_expression + (selector_expression + field: (field_identifier) @_field (#any-of? @_field "Exec" "GetContext" "ExecContext" "SelectContext" "In" "RebindNamed" "Rebind" "Query" "QueryRow" "QueryRowxContext" "NamedExec" "MustExec" "Get" "Queryx")) + (argument_list + (interpreted_string_literal) @injection.content)) + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "sql")) + +; neovim nightly 0.10 +([ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + (#match? @injection.content "(SELECT|select|INSERT|insert|UPDATE|update|DELETE|delete).+(FROM|from|INTO|into|VALUES|values|SET|set).*(WHERE|where|GROUP BY|group by)?") + (#offset! @injection.content 0 1 0 -1) +(#set! injection.language "sql")) + +; a general query injection +([ + (interpreted_string_literal) + (raw_string_literal) + ] @sql + (#match? @sql "(SELECT|select|INSERT|insert|UPDATE|update|DELETE|delete).+(FROM|from|INTO|into|VALUES|values|SET|set).*(WHERE|where|GROUP BY|group by)?") + (#offset! @sql 0 1 0 -1)) + +; ---------------------------------------------------------------- +; fallback keyword and comment based injection + +([ + (interpreted_string_literal) + (raw_string_literal) + ] @sql + (#contains? @sql "-- sql" "--sql" "ADD CONSTRAINT" "ALTER TABLE" "ALTER COLUMN" + "DATABASE" "FOREIGN KEY" "GROUP BY" "HAVING" "CREATE INDEX" "INSERT INTO" + "NOT NULL" "PRIMARY KEY" "UPDATE SET" "TRUNCATE TABLE" "LEFT JOIN" "add constraint" "alter table" "alter column" "database" "foreign key" "group by" "having" "create index" "insert into" + "not null" "primary key" "update set" "truncate table" "left join") + (#offset! @sql 0 1 0 -1)) + +; nvim 0.10 +([ + (interpreted_string_literal) + (raw_string_literal) + ] @injection.content + (#contains? @injection.content "-- sql" "--sql" "ADD CONSTRAINT" "ALTER TABLE" "ALTER COLUMN" + "DATABASE" "FOREIGN KEY" "GROUP BY" "HAVING" "CREATE INDEX" "INSERT INTO" + "NOT NULL" "PRIMARY KEY" "UPDATE SET" "TRUNCATE TABLE" "LEFT JOIN" "add constraint" "alter table" "alter column" "database" "foreign key" "group by" "having" "create index" "insert into" + "not null" "primary key" "update set" "truncate table" "left join") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "sql")) + + +; should I use a more exhaustive list of keywords? +; "ADD" "ADD CONSTRAINT" "ALL" "ALTER" "AND" "ASC" "COLUMN" "CONSTRAINT" "CREATE" "DATABASE" "DELETE" "DESC" "DISTINCT" "DROP" "EXISTS" "FOREIGN KEY" "FROM" "JOIN" "GROUP BY" "HAVING" "IN" "INDEX" "INSERT INTO" "LIKE" "LIMIT" "NOT" "NOT NULL" "OR" "ORDER BY" "PRIMARY KEY" "SELECT" "SET" "TABLE" "TRUNCATE TABLE" "UNION" "UNIQUE" "UPDATE" "VALUES" "WHERE" + +; json + +((const_spec + name: (identifier) @_const + value: (expression_list (raw_string_literal) @json)) + (#lua-match? @_const ".*[J|j]son.*")) + +; jsonStr := `{"foo": "bar"}` + +((short_var_declaration + left: (expression_list + (identifier) @_var) + right: (expression_list + (raw_string_literal) @json)) + (#lua-match? @_var ".*[J|j]son.*") + (#offset! @json 0 1 0 -1)) + +; nvim 0.10 + +(const_spec + name: (identifier) + value: (expression_list (raw_string_literal) @injection.content + (#lua-match? @injection.content "^`[\n|\t| ]*\{.*\}[\n|\t| ]*`$") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "json"))) + +(short_var_declaration + left: (expression_list (identifier)) + right: (expression_list (raw_string_literal) @injection.content) + (#lua-match? @injection.content "^`[\n|\t| ]*\{.*\}[\n|\t| ]*`$") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "json")) + +(var_spec + name: (identifier) + value: (expression_list (raw_string_literal) @injection.content + (#lua-match? @injection.content "^`[\n|\t| ]*\{.*\}[\n|\t| ]*`$") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "json"))) diff --git a/.config/nvim/queries/go/locals.scm b/.config/nvim/queries/go/locals.scm new file mode 100644 index 0000000..9232669 --- /dev/null +++ b/.config/nvim/queries/go/locals.scm @@ -0,0 +1,15 @@ +; extends + +(var_spec) @local.scope + +(field_declaration + name: (field_identifier) @local.definition.field) + +(method_elem + name: (field_identifier) @function.method.name + parameters: (parameter_list) @function.method.parameter_list) @local.interface.method.declaration + +(type_declaration + (type_spec + name: (type_identifier) @local.name + type: [(struct_type) (interface_type)] @local.type)) @local.start -- cgit v1.3.1