mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
indents(sql): initial support (#4857)
* indents(sql): initial support * indents(sql): fix queries and lua style
This commit is contained in:
parent
9bef726044
commit
dae928b3bb
9 changed files with 86 additions and 0 deletions
27
queries/sql/indents.scm
Normal file
27
queries/sql/indents.scm
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
[
|
||||||
|
(select)
|
||||||
|
(cte)
|
||||||
|
(column_definitions)
|
||||||
|
(case)
|
||||||
|
(subquery)
|
||||||
|
(insert)
|
||||||
|
] @indent.begin
|
||||||
|
|
||||||
|
|
||||||
|
(compound_statement
|
||||||
|
(keyword_begin)
|
||||||
|
) @indent.begin
|
||||||
|
|
||||||
|
(column_definitions ")" @indent.branch)
|
||||||
|
|
||||||
|
(subquery ")" @indent.branch)
|
||||||
|
|
||||||
|
(cte ")" @indent.branch)
|
||||||
|
|
||||||
|
[
|
||||||
|
(keyword_end)
|
||||||
|
(keyword_values)
|
||||||
|
(keyword_into)
|
||||||
|
] @indent.branch
|
||||||
|
|
||||||
|
(keyword_end) @indent.end
|
||||||
8
tests/indent/sql/case.sql
Normal file
8
tests/indent/sql/case.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
select
|
||||||
|
case
|
||||||
|
when a = 1 then '1'
|
||||||
|
when a = 2 then '2'
|
||||||
|
when a = 3 then '3'
|
||||||
|
else '0'
|
||||||
|
end as stmt1
|
||||||
|
from tab;
|
||||||
3
tests/indent/sql/compound.sql
Normal file
3
tests/indent/sql/compound.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
begin
|
||||||
|
create table foo (bar int);
|
||||||
|
end;
|
||||||
4
tests/indent/sql/create.sql
Normal file
4
tests/indent/sql/create.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
create table my_table (
|
||||||
|
id bigint,
|
||||||
|
date date
|
||||||
|
);
|
||||||
7
tests/indent/sql/cte.sql
Normal file
7
tests/indent/sql/cte.sql
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
with data as (
|
||||||
|
select
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
from tab
|
||||||
|
)
|
||||||
|
select * from data;
|
||||||
5
tests/indent/sql/insert.sql
Normal file
5
tests/indent/sql/insert.sql
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
insert into mytable
|
||||||
|
(column1, column2)
|
||||||
|
values
|
||||||
|
('john', 123),
|
||||||
|
('jane', 124);
|
||||||
4
tests/indent/sql/select.sql
Normal file
4
tests/indent/sql/select.sql
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
select
|
||||||
|
a,
|
||||||
|
b
|
||||||
|
from tab;
|
||||||
9
tests/indent/sql/subquery.sql
Normal file
9
tests/indent/sql/subquery.sql
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
select
|
||||||
|
id
|
||||||
|
from foo
|
||||||
|
where id < (
|
||||||
|
select
|
||||||
|
id
|
||||||
|
from bar
|
||||||
|
limit 1
|
||||||
|
);
|
||||||
19
tests/indent/sql_spec.lua
Normal file
19
tests/indent/sql_spec.lua
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
local Runner = require("tests.indent.common").Runner
|
||||||
|
--local XFAIL = require("tests.indent.common").XFAIL
|
||||||
|
|
||||||
|
local run = Runner:new(it, "tests/indent/sql", {
|
||||||
|
tabstop = 4,
|
||||||
|
shiftwidth = 4,
|
||||||
|
softtabstop = 0,
|
||||||
|
expandtab = true,
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("indent SQL:", function()
|
||||||
|
describe("whole file:", function()
|
||||||
|
run:whole_file(".", {
|
||||||
|
expected_failures = {},
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe("new line:", function() end)
|
||||||
|
end)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue