提交 56a726dd 编写于 作者: C Cosmin Popescu

added sw_delete_tmp option and improved autocomplete regexp patterns

上级 1cb395b2
...@@ -70,6 +70,15 @@ function! s:get_wake_vim_cmd() ...@@ -70,6 +70,15 @@ function! s:get_wake_vim_cmd()
return s:wake_vim_cmd . ' --remote-expr "sw#got_async_result(' . s:get_buff_unique_id() . ')"' return s:wake_vim_cmd . ' --remote-expr "sw#got_async_result(' . s:get_buff_unique_id() . ')"'
endfunction endfunction
function! s:delete_tmp()
if (g:sw_delete_tmp)
call delete(g:sw_tmp . '/' . s:input_file())
call delete(g:sw_tmp . '/' . s:output_file())
call delete(g:sw_tmp . '/' . s:async_input_file())
endif
endfunction
function! sw#async_end() function! sw#async_end()
let idx = index(g:sw_async_ended, s:get_buff_unique_id()) let idx = index(g:sw_async_ended, s:get_buff_unique_id())
if idx != -1 if idx != -1
...@@ -81,10 +90,7 @@ function! sw#async_end() ...@@ -81,10 +90,7 @@ function! sw#async_end()
let func = b:on_async_result let func = b:on_async_result
execute "call " . func . "()" execute "call " . func . "()"
endif endif
call s:delete_tmp()
call delete(g:sw_tmp . '/' . s:input_file())
call delete(g:sw_tmp . '/' . s:output_file())
call delete(g:sw_tmp . '/' . s:async_input_file())
endif endif
endfunction endfunction
...@@ -96,10 +102,7 @@ function! sw#reset_current_command() ...@@ -96,10 +102,7 @@ function! sw#reset_current_command()
if exists('b:async_on_progress') if exists('b:async_on_progress')
unlet b:async_on_progress unlet b:async_on_progress
endif endif
call s:delete_tmp()
call delete(g:sw_tmp . '/' . s:input_file())
call delete(g:sw_tmp . '/' . s:output_file())
call delete(g:sw_tmp . '/' . s:async_input_file())
endfunction endfunction
function! sw#kill_current_command() function! sw#kill_current_command()
...@@ -118,10 +121,7 @@ function! sw#kill_current_command() ...@@ -118,10 +121,7 @@ function! sw#kill_current_command()
call sw#session#unset_buffer_variable('on_async_kill') call sw#session#unset_buffer_variable('on_async_kill')
execute "call " . func . "()" execute "call " . func . "()"
endif endif
call s:delete_tmp()
call delete(g:sw_tmp . '/' . s:input_file())
call delete(g:sw_tmp . '/' . s:output_file())
call delete(g:sw_tmp . '/' . s:async_input_file())
endfunction endfunction
function! sw#check_async_result() function! sw#check_async_result()
......
...@@ -22,7 +22,7 @@ let s:pattern_identifier = '\v' . s:_pattern_identifier ...@@ -22,7 +22,7 @@ let s:pattern_identifier = '\v' . s:_pattern_identifier
let s:pattern_reserved_word = '\v\c<(inner|outer|right|left|join|as|using|where|group|order|and|or|not)>' let s:pattern_reserved_word = '\v\c<(inner|outer|right|left|join|as|using|where|group|order|and|or|not)>'
let s:pattern_subquery = '\v#sq([0-9]+)#' let s:pattern_subquery = '\v#sq([0-9]+)#'
let s:script_path = expand('<sfile>:p:h') . '/../../' let s:script_path = expand('<sfile>:p:h') . '/../../'
let s:pattern_expressions = '\v\c\(([\s\t ]*select)@![^\)]{-}\)' let s:pattern_expressions = '\v\c\(([\s\t ]*select)@![^\(\)]{-}\)'
function! s:eliminate_sql_comments(sql) function! s:eliminate_sql_comments(sql)
let sql = sw#get_sql_canonical(a:sql)[0] let sql = sw#get_sql_canonical(a:sql)[0]
...@@ -455,6 +455,9 @@ endfunction ...@@ -455,6 +455,9 @@ endfunction
function! s:extract_subqueries(sql) function! s:extract_subqueries(sql)
let pattern = '\v\c(\([ \s\t]*select[^\(\)]+\))' let pattern = '\v\c(\([ \s\t]*select[^\(\)]+\))'
let s = substitute(a:sql, s:pattern_expressions, '#values#', 'g') let s = substitute(a:sql, s:pattern_expressions, '#values#', 'g')
while s =~ s:pattern_expressions
let s = substitute(s, s:pattern_expressions, '#values#', 'g')
endwhile
let matches = [] let matches = []
let n = 0 let n = 0
let m = matchstr(s, pattern, '') let m = matchstr(s, pattern, '')
...@@ -538,7 +541,13 @@ function! s:get_subquery_fields(sql, subqueries) ...@@ -538,7 +541,13 @@ function! s:get_subquery_fields(sql, subqueries)
" get my_id, and then return the autocomplete with alias.my_id. " get my_id, and then return the autocomplete with alias.my_id.
" That's why we eliminate everything before the point " That's why we eliminate everything before the point
" If the field does not contain *, we just get the last identifier " If the field does not contain *, we just get the last identifier
let f = matchstr(field, '\v([^ \t\s]+)$') if field =~ '\v\.'
let f = matchstr(field, '\v([^\.]+)$')
elseif field =~ '\v[ ]'
let f = matchstr(field, '\v([^ ]+)$')
else
let f = field
endif
call add(result, f) call add(result, f)
elseif field == '*' elseif field == '*'
" If the field is *, we need to get the tables of this subquery " If the field is *, we need to get the tables of this subquery
......
...@@ -152,6 +152,10 @@ if !exists('g:sw_tab_switches_between_bottom_panels') ...@@ -152,6 +152,10 @@ if !exists('g:sw_tab_switches_between_bottom_panels')
let g:sw_tab_switches_between_bottom_panels = 1 let g:sw_tab_switches_between_bottom_panels = 1
endif endif
if !exists('g:sw_delete_tmp')
let g:sw_delete_tmp = 1
endif
"if !exists('g:sw_overwrite_current_command') "if !exists('g:sw_overwrite_current_command')
" let g:sw_overwrite_current_command = 0 " let g:sw_overwrite_current_command = 0
"endif "endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册