From 56a726ddab952106df5037fc165cb0753e566887 Mon Sep 17 00:00:00 2001 From: Cosmin Popescu Date: Sat, 28 Feb 2015 19:50:29 +0100 Subject: [PATCH] added sw_delete_tmp option and improved autocomplete regexp patterns --- autoload/sw.vim | 24 ++++++++++++------------ autoload/sw/autocomplete.vim | 13 +++++++++++-- plugin/sw.vim | 4 ++++ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/autoload/sw.vim b/autoload/sw.vim index a50b676..ef75d6c 100644 --- a/autoload/sw.vim +++ b/autoload/sw.vim @@ -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() . ')"' 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() let idx = index(g:sw_async_ended, s:get_buff_unique_id()) if idx != -1 @@ -81,10 +90,7 @@ function! sw#async_end() let func = b:on_async_result execute "call " . func . "()" endif - - 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()) + call s:delete_tmp() endif endfunction @@ -96,10 +102,7 @@ function! sw#reset_current_command() if exists('b:async_on_progress') unlet b:async_on_progress endif - - 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()) + call s:delete_tmp() endfunction function! sw#kill_current_command() @@ -118,10 +121,7 @@ function! sw#kill_current_command() call sw#session#unset_buffer_variable('on_async_kill') execute "call " . func . "()" endif - - 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()) + call s:delete_tmp() endfunction function! sw#check_async_result() diff --git a/autoload/sw/autocomplete.vim b/autoload/sw/autocomplete.vim index 5e0879a..c561505 100644 --- a/autoload/sw/autocomplete.vim +++ b/autoload/sw/autocomplete.vim @@ -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_subquery = '\v#sq([0-9]+)#' let s:script_path = expand(':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) let sql = sw#get_sql_canonical(a:sql)[0] @@ -455,6 +455,9 @@ endfunction function! s:extract_subqueries(sql) let pattern = '\v\c(\([ \s\t]*select[^\(\)]+\))' 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 n = 0 let m = matchstr(s, pattern, '') @@ -538,7 +541,13 @@ function! s:get_subquery_fields(sql, subqueries) " get my_id, and then return the autocomplete with alias.my_id. " That's why we eliminate everything before the point " 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) elseif field == '*' " If the field is *, we need to get the tables of this subquery diff --git a/plugin/sw.vim b/plugin/sw.vim index 1c62ecb..72d9dab 100644 --- a/plugin/sw.vim +++ b/plugin/sw.vim @@ -152,6 +152,10 @@ if !exists('g:sw_tab_switches_between_bottom_panels') let g:sw_tab_switches_between_bottom_panels = 1 endif +if !exists('g:sw_delete_tmp') + let g:sw_delete_tmp = 1 +endif + "if !exists('g:sw_overwrite_current_command') " let g:sw_overwrite_current_command = 0 "endif -- GitLab