diff --git a/autoload/SpaceVim/layers/lang/sql.vim b/autoload/SpaceVim/layers/lang/sql.vim index c3d8190e7..970d4d929 100644 --- a/autoload/SpaceVim/layers/lang/sql.vim +++ b/autoload/SpaceVim/layers/lang/sql.vim @@ -20,10 +20,16 @@ " " 1. `enabled_formater`: set the default formatter for sql, default is ['sqlfmtorg'] " https://github.com/sql-formatter-org/sql-formatter +" you can also use `sqlformat` which is from https://github.com/andialbrecht/sqlparse " 2. `sql_formatter_command`: Set the command of sql-formatter. " 3. `sql_dialect`: set the SQL dialect, default is basic sql. " 4. `sql_formatter_config`: set the path of config path. default is empty " string. +" 5. `sqlformat_cmd`: set the command for sqlformat. +" 6. `sqlformat_output_encode`: set the output encoding of sqlformat, default +" is `utf-8`. If you are using window, maybe need to change this option to +" `cp936`. +" " if exists('s:enabled_formater') @@ -34,6 +40,8 @@ let s:enabled_formater = ['sqlfmtorg'] let s:sql_formatter_command = 'sql-formatter' let s:sql_dialect = 'sql' let s:sql_formatter_config = '' +let s:sqlformat_cmd = 'sqlformat' +let s:sqlformat_output_encode = 'utf-8' function! SpaceVim#layers#lang#sql#plugins() abort let plugins = [] @@ -46,6 +54,8 @@ function! SpaceVim#layers#lang#sql#set_variable(opt) abort let s:sql_formatter_command = get(a:opt, 'sql_formatter_command', s:sql_formatter_command) let s:sql_dialect = get(a:opt, 'sql_dialect', s:sql_dialect) let s:sql_formatter_config = get(a:opt, 'sql_formatter_config', s:sql_formatter_config) + let s:sqlformat_cmd = get(a:opt, 'sqlformat_cmd', s:sqlformat_cmd) + let s:sqlformat_output_encode = get(a:opt, 'sqlformat_output_encode', s:sqlformat_output_encode) endfunction function! SpaceVim#layers#lang#sql#config() abort @@ -60,6 +70,12 @@ function! SpaceVim#layers#lang#sql#config() abort \ 'args': ['-l', s:sql_dialect,] + argv, \ 'stdin': 1, \ } + let g:neoformat_sql_sqlformat = { + \ 'exe': s:sqlformat_cmd, + \ 'args': ['--reindent', '-'], + \ 'output_encode': s:sqlformat_output_encode, + \ 'stdin': 1, + \ } endfunction function! SpaceVim#layers#lang#sql#health() abort diff --git a/bundle/neoformat/autoload/neoformat.vim b/bundle/neoformat/autoload/neoformat.vim index 885d3b505..829f83c19 100644 --- a/bundle/neoformat/autoload/neoformat.vim +++ b/bundle/neoformat/autoload/neoformat.vim @@ -130,6 +130,10 @@ function! s:neoformat(bang, user_input, start_line, end_line) abort call s:deletelines(len(new_buffer), line('$')) + if cmd.output_encode != 'utf-8' + let new_buffer = map(new_buffer, 'iconv(v:val, "cp936", "utf-8")') + endif + call setline(1, new_buffer) call add(formatters_changed, cmd.name) @@ -239,6 +243,7 @@ endfunction function! s:generate_cmd(definition, filetype) abort let executable = get(a:definition, 'exe', '') + let output_encode = get(a:definition, 'output_encode', 'utf-8') if executable == '' call neoformat#utils#log('no exe field in definition') return {} @@ -309,6 +314,7 @@ function! s:generate_cmd(definition, filetype) abort return { \ 'exe': fullcmd, \ 'stdin': using_stdin, + \ 'output_encode' : output_encode, \ 'stderr_log': stderr_log, \ 'name': a:definition.exe, \ 'replace': get(a:definition, 'replace', 0), diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 7be86b5ca..43760966a 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -5186,11 +5186,18 @@ add following snippet to your |SpaceVim-options| file. OPTIONS 1. `enabled_formater`: set the default formatter for sql, default is - ['sqlfmtorg'] https://github.com/sql-formatter-org/sql-formatter + ['sqlfmtorg'] https://github.com/sql-formatter-org/sql-formatter you can + also use `sqlformat` which is from + https://github.com/andialbrecht/sqlparse 2. `sql_formatter_command`: Set the command of sql-formatter. 3. `sql_dialect`: set the SQL dialect, default is basic sql. 4. `sql_formatter_config`: set the path of config path. default is empty string. + 5. `sqlformat_cmd`: set the command for sqlformat. + 6. `sqlformat_output_encode`: set the output encoding of sqlformat, default +is `utf-8`. If you are using window, maybe need to change this option to +`cp936`. + ==============================================================================