File tree Expand file tree Collapse file tree 4 files changed +17
-21
lines changed Expand file tree Collapse file tree 4 files changed +17
-21
lines changed Original file line number Diff line number Diff line change 33" Description: Autoloaded functions for SQL formatting
44
55function ! sqlformat#Format (startline, endline) abort
6- " Ensure Python3 is available
76 if ! has (' python3' )
87 echohl ErrorMsg
98 echomsg ' SQLFormat requires Neovim with +python3 support'
109 echohl None
1110 return
1211 endif
1312
14- " Get the selected lines
1513 let l: lines = getline (a: startline , a: endline )
1614 let l: input = join (l: lines , ' \n' )
1715
18- " Call Python script to format SQL
1916 python3 << EOF
2017import vim
2118from sqlformat import format_sql
2219input_sql = vim .eval (' l:input' )
23- indent = int (vim .eval (' g:sqlformat_indent' ))
24- keyword_case = vim .eval (' g:sqlformat_keyword_case' )
25- formatted = format_sql (input_sql, indent , keyword_case)
20+ formatted = format_sql (input_sql)
2621vim .command (' let l:formatted = ' + repr (formatted))
2722EOF
2823
29- " Replace buffer content with formatted SQL
3024 let l: formatted_lines = split (l: formatted , ' \n' )
3125 call setline (a: startline , l: formatted_lines )
3226endfunction
Original file line number Diff line number Diff line change 1+ -- Author: anvndev
2+ -- File: lua/sqlformat.lua
3+ return {
4+ setup = function ()
5+ -- Plugin is loaded via plugin/sqlformat.vim, so no additional Lua setup is needed
6+ end ,
7+ }
Original file line number Diff line number Diff line change 11" Author: Anvndev
2- " Description: SQL formatting plugin for Neovim using sqlparse
2+ " File: plugin/sqlformat.vim
3+ " Description: SQL formatting plugin for Neovim
34
45if exists (' g:loaded_sqlformat' )
56 finish
67endif
78let g: loaded_sqlformat = 1
89
9- " Default settings
10- let g: sqlformat_indent = get (g: , ' sqlformat_indent' , 2 )
11- let g: sqlformat_keyword_case = get (g: , ' sqlformat_keyword_case' , ' upper' )
12-
13- " Define command
1410command ! -range =% SQLFormat call sqlformat#Format (<line1> , <line2> )
15-
16- " Keybinding (optional, customizable by user)
1711nnoremap <silent> <leader> sf :SQLFormat<CR>
Original file line number Diff line number Diff line change 99#
1010# The above copyright notice and this permission notice shall be included in all
1111# copies or substantial portions of the Software.
12+ # File: python/sqlformat.py
13+
1214import sqlparse
1315
14- def format_sql (sql , indent , keyword_case ):
16+
17+ def format_sql (sql ):
1518 """
16- Format SQL code using sqlparse .
19+ Format SQL code with fixed style: 2-space indent, uppercase keywords .
1720
1821 Args:
1922 sql (str): SQL code to format
20- indent (int): Number of spaces for indentation
21- keyword_case (str): 'upper', 'lower', or None for keyword case
2223 Returns:
2324 str: Formatted SQL
2425 """
2526 return sqlparse .format (
2627 sql ,
2728 reindent = True ,
28- indent_width = indent ,
29- keyword_case = keyword_case ,
29+ indent_width = 2 ,
30+ keyword_case = 'upper' ,
3031 wrap_after = 80
3132 )
You can’t perform that action at this time.
0 commit comments