summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config/nvim/after/ftplugin/go.lua1
-rw-r--r--.config/nvim/after/queries/go/injections.scm108
-rw-r--r--.config/nvim/after/queries/go/locals.scm15
-rw-r--r--.config/nvim/lazy-lock.json3
-rw-r--r--.config/nvim/lua/custom/plugins/go.lua9
5 files changed, 135 insertions, 1 deletions
diff --git a/.config/nvim/after/ftplugin/go.lua b/.config/nvim/after/ftplugin/go.lua
new file mode 100644
index 0000000..3436b9c
--- /dev/null
+++ b/.config/nvim/after/ftplugin/go.lua
@@ -0,0 +1 @@
+vim.opt_local.expandtab = false
diff --git a/.config/nvim/after/queries/go/injections.scm b/.config/nvim/after/queries/go/injections.scm
new file mode 100644
index 0000000..5d5affc
--- /dev/null
+++ b/.config/nvim/after/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/after/queries/go/locals.scm b/.config/nvim/after/queries/go/locals.scm
new file mode 100644
index 0000000..9232669
--- /dev/null
+++ b/.config/nvim/after/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
diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json
index 9b874bf..0756961 100644
--- a/.config/nvim/lazy-lock.json
+++ b/.config/nvim/lazy-lock.json
@@ -15,10 +15,11 @@
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
"edgy.nvim": { "branch": "main", "commit": "7e8dedc39abebe40c289b8012cc89b11c69aa7a0" },
"gitsigns.nvim": { "branch": "main", "commit": "863903631e676b33e8be2acb17512fdc1b80b4fb" },
+ "gopher.nvim": { "branch": "main", "commit": "f55c15ada8e02398000c04a96ef44d986cd01051" },
"harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" },
"helpview.nvim": { "branch": "main", "commit": "857aec1dab331252910da158ab6cbfbc65239c71" },
"indent-blankline.nvim": { "branch": "master", "commit": "18603eb949eba08300799f64027af11ef922283f" },
- "lazy.nvim": { "branch": "main", "commit": "460e1cd8f24e364d54543a4b0e83f6f4ec1f65fb" },
+ "lazy.nvim": { "branch": "main", "commit": "1159bdccd8910a0fd0914b24d6c3d186689023d9" },
"lazydev.nvim": { "branch": "main", "commit": "491452cf1ca6f029e90ad0d0368848fac717c6d2" },
"leap.nvim": { "branch": "main", "commit": "c6bfb191f1161fbabace1f36f578a20ac6c7642c" },
"lsp-progress.nvim": { "branch": "main", "commit": "d5f4d28efe75ce636bfbe271eb45f39689765aab" },
diff --git a/.config/nvim/lua/custom/plugins/go.lua b/.config/nvim/lua/custom/plugins/go.lua
new file mode 100644
index 0000000..4bbcc92
--- /dev/null
+++ b/.config/nvim/lua/custom/plugins/go.lua
@@ -0,0 +1,9 @@
+return {
+ 'olexsmir/gopher.nvim',
+ ft = 'go',
+ build = function()
+ vim.cmd.GoInstallDeps()
+ end,
+ ---@type gopher.Config
+ opts = {},
+}