diff options
author | Bram Moolenaar <Bram@vim.org> | 2007-05-05 18:27:07 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2007-05-05 18:27:07 +0000 |
commit | 83e138c6062947ab8ab8f09358a467ab74795630 (patch) | |
tree | 3f0b49d17be1acfe2f3f922756e1a58412fbeda6 /runtime/autoload | |
parent | c81e5e79a0f2f5c2ac1896fa51cbe47e2e2a8d97 (diff) | |
download | vim-git-83e138c6062947ab8ab8f09358a467ab74795630.tar.gz |
updated for version 7.1a
Diffstat (limited to 'runtime/autoload')
-rw-r--r-- | runtime/autoload/phpcomplete.vim | 182 | ||||
-rw-r--r-- | runtime/autoload/sqlcomplete.vim | 149 |
2 files changed, 230 insertions, 101 deletions
diff --git a/runtime/autoload/phpcomplete.vim b/runtime/autoload/phpcomplete.vim index 1dbabc3c0..e5d910e30 100644 --- a/runtime/autoload/phpcomplete.vim +++ b/runtime/autoload/phpcomplete.vim @@ -1,7 +1,7 @@ " Vim completion script " Language: PHP " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) -" Last Change: 2006 Apr 30 +" Last Change: 2006 May 9 " " TODO: " - Class aware completion: @@ -74,7 +74,7 @@ function! phpcomplete#CompletePHP(findstart, base) let file = getline(1, '$') call filter(file, \ 'v:val =~ "class\\s\\+[a-zA-Z_\\x7f-\\xff][a-zA-Z_0-9\\x7f-\\xff]*\\s*("') - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) let jfile = join(file, ' ') let int_values = split(jfile, 'class\s\+') let int_classes = {} @@ -85,33 +85,43 @@ function! phpcomplete#CompletePHP(findstart, base) endif endfor - " Prepare list of functions from tags file + " Prepare list of classes from tags file let ext_classes = {} - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) if fnames != '' exe 'silent! vimgrep /^'.a:base.'.*\tc\(\t\|$\)/j '.fnames let qflist = getqflist() - for field in qflist - " [:space:] thing: we don't have to be so strict when - " dealing with tags files - entries there were already - " checked by ctags. - let item = matchstr(field['text'], '^[^[:space:]]\+') - let ext_classes[item] = '' + if len(qflist) > 0 + for field in qflist + " [:space:] thing: we don't have to be so strict when + " dealing with tags files - entries there were already + " checked by ctags. + let item = matchstr(field['text'], '^[^[:space:]]\+') + let ext_classes[item] = '' + endfor + endif + endif + + " Prepare list of built in classes from g:php_builtin_functions + if !exists("g:php_omni_bi_classes") + let g:php_omni_bi_classes = {} + for i in keys(g:php_builtin_object_functions) + let g:php_omni_bi_classes[substitute(i, '::.*$', '', '')] = '' endfor endif - call extend(int_classes, ext_classes) + let classes = sort(keys(int_classes)) + let classes += sort(keys(ext_classes)) + let classes += sort(keys(g:php_omni_bi_classes)) - for m in sort(keys(int_classes)) + for m in classes if m =~ '^'.a:base call add(res, m) endif endfor - let int_list = res - let final_menu = [] - for i in int_list + for i in res let final_menu += [{'word':i, 'kind':'c'}] endfor @@ -138,6 +148,19 @@ function! phpcomplete#CompletePHP(findstart, base) let classlocation = '' endif + if classlocation == 'VIMPHP_BUILTINOBJECT' + + for object in keys(g:php_builtin_object_functions) + if object =~ '^'.classname + let res += [{'word':substitute(object, '.*::', '', ''), + \ 'info': g:php_builtin_object_functions[object]}] + endif + endfor + + return res + + endif + if filereadable(classlocation) let classfile = readfile(classlocation) let classcontent = '' @@ -154,7 +177,7 @@ function! phpcomplete#CompletePHP(findstart, base) " Functions declared with public keyword or without any " keyword are public let functions = filter(deepcopy(sccontent), - \ 'v:val =~ "^\\s*\\(public\\s\\*\\)\\?function"') + \ 'v:val =~ "^\\s*\\(static\\s\\+\\|public\\s\\+\\)*function"') let jfuncs = join(functions, ' ') let sfuncs = split(jfuncs, 'function\s\+') let c_functions = {} @@ -185,7 +208,6 @@ function! phpcomplete#CompletePHP(findstart, base) let all_values = {} call extend(all_values, c_functions) call extend(all_values, c_variables) - call extend(all_values, g:php_builtin_object_functions) for m in sort(keys(all_values)) if m =~ '^'.a:base && m !~ '::' @@ -244,23 +266,25 @@ function! phpcomplete#CompletePHP(findstart, base) " ctags has good support for PHP, use tags file for external " variables - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) let ext_vars = {} if fnames != '' let sbase = substitute(a:base, '^\$', '', '') exe 'silent! vimgrep /^'.sbase.'.*\tv\(\t\|$\)/j '.fnames let qflist = getqflist() - for field in qflist - let item = matchstr(field['text'], '^[^[:space:]]\+') - " Add -> if it is possible object declaration - let classname = '' - if field['text'] =~ item.'\s*=\s*new\s\+' - let item = item.'->' - let classname = matchstr(field['text'], - \ '=\s*new\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze') - endif - let ext_vars[adddollar.item] = classname - endfor + if len(qflist) > 0 + for field in qflist + let item = matchstr(field['text'], '^[^[:space:]]\+') + " Add -> if it is possible object declaration + let classname = '' + if field['text'] =~ item.'\s*=\s*new\s\+' + let item = item.'->' + let classname = matchstr(field['text'], + \ '=\s*new\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze') + endif + let ext_vars[adddollar.item] = classname + endfor + endif endif " Now we have all variables in int_vars dictionary @@ -270,7 +294,7 @@ function! phpcomplete#CompletePHP(findstart, base) let file = getline(1, '$') call filter(file, \ 'v:val =~ "function\\s\\+&\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z_0-9\\x7f-\\xff]*\\s*("') - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) let jfile = join(file, ' ') let int_values = split(jfile, 'function\s\+') let int_functions = {} @@ -287,14 +311,16 @@ function! phpcomplete#CompletePHP(findstart, base) if fnames != '' exe 'silent! vimgrep /^'.a:base.'.*\tf\(\t\|$\)/j '.fnames let qflist = getqflist() - for field in qflist - " File name - let item = matchstr(field['text'], '^[^[:space:]]\+') - let fname = matchstr(field['text'], '\t\zs\f\+\ze') - let prototype = matchstr(field['text'], - \ 'function\s\+&\?[^[:space:]]\+\s*(\s*\zs.\{-}\ze\s*)\s*{\?') - let ext_functions[item.'('] = prototype.') - '.fname - endfor + if len(qflist) > 0 + for field in qflist + " File name + let item = matchstr(field['text'], '^[^[:space:]]\+') + let fname = matchstr(field['text'], '\t\zs\f\+\ze') + let prototype = matchstr(field['text'], + \ 'function\s\+&\?[^[:space:]]\+\s*(\s*\zs.\{-}\ze\s*)\s*{\?') + let ext_functions[item.'('] = prototype.') - '.fname + endfor + endif endif let all_values = {} @@ -375,23 +401,25 @@ function! phpcomplete#CompletePHP(findstart, base) call extend(int_vars,g:php_builtin_vars) " ctags has support for PHP, use tags file for external variables - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) let ext_vars = {} if fnames != '' let sbase = substitute(a:base, '^\$', '', '') exe 'silent! vimgrep /^'.sbase.'.*\tv\(\t\|$\)/j '.fnames let qflist = getqflist() - for field in qflist - let item = '$'.matchstr(field['text'], '^[^[:space:]]\+') - let m_menu = '' - " Add -> if it is possible object declaration - if field['text'] =~ item.'\s*=\s*new\s\+' - let item = item.'->' - let m_menu = matchstr(field['text'], - \ '=\s*new\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze') - endif - let ext_vars[item] = m_menu - endfor + if len(qflist) > 0 + for field in qflist + let item = '$'.matchstr(field['text'], '^[^[:space:]]\+') + let m_menu = '' + " Add -> if it is possible object declaration + if field['text'] =~ item.'\s*=\s*new\s\+' + let item = item.'->' + let m_menu = matchstr(field['text'], + \ '=\s*new\s\+\zs[a-zA-Z_0-9\x7f-\xff]\+\ze') + endif + let ext_vars[item] = m_menu + endfor + endif endif call extend(int_vars, ext_vars) @@ -433,7 +461,7 @@ function! phpcomplete#CompletePHP(findstart, base) let file = getline(1, '$') call filter(file, \ 'v:val =~ "function\\s\\+&\\?[a-zA-Z_\\x7f-\\xff][a-zA-Z_0-9\\x7f-\\xff]*\\s*("') - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) let jfile = join(file, ' ') let int_values = split(jfile, 'function\s\+') let int_functions = {} @@ -450,14 +478,16 @@ function! phpcomplete#CompletePHP(findstart, base) if fnames != '' exe 'silent! vimgrep /^'.a:base.'.*\tf\(\t\|$\)/j '.fnames let qflist = getqflist() - for field in qflist - " File name - let item = matchstr(field['text'], '^[^[:space:]]\+') - let fname = matchstr(field['text'], '\t\zs\f\+\ze') - let prototype = matchstr(field['text'], - \ 'function\s\+&\?[^[:space:]]\+\s*(\s*\zs.\{-}\ze\s*)\s*{\?') - let ext_functions[item.'('] = prototype.') - '.fname - endfor + if len(qflist) > 0 + for field in qflist + " File name + let item = matchstr(field['text'], '^[^[:space:]]\+') + let fname = matchstr(field['text'], '\t\zs\f\+\ze') + let prototype = matchstr(field['text'], + \ 'function\s\+&\?[^[:space:]]\+\s*(\s*\zs.\{-}\ze\s*)\s*{\?') + let ext_functions[item.'('] = prototype.') - '.fname + endfor + endif endif " All functions @@ -480,15 +510,17 @@ function! phpcomplete#CompletePHP(findstart, base) endfor " Prepare list of constants from tags file - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) let ext_constants = {} if fnames != '' exe 'silent! vimgrep /^'.a:base.'.*\td\(\t\|$\)/j '.fnames let qflist = getqflist() - for field in qflist - let item = matchstr(field['text'], '^[^[:space:]]\+') - let ext_constants[item] = '' - endfor + if len(qflist) > 0 + for field in qflist + let item = matchstr(field['text'], '^[^[:space:]]\+') + let ext_constants[item] = '' + endfor + endif endif " All constants @@ -558,7 +590,7 @@ function! phpcomplete#GetClassName(scontext) " {{{ endwhile " OK, first way failed, now check tags file(s) - let fnames = join(map(tagfiles(), 'escape(v:val, " \\")')) + let fnames = join(map(tagfiles(), 'escape(v:val, " \\#%")')) exe 'silent! vimgrep /^'.object.'.*\$'.object.'.*=\s*new\s\+.*\tv\(\t\|$\)/j '.fnames let qflist = getqflist() if len(qflist) == 0 @@ -573,6 +605,17 @@ function! phpcomplete#GetClassName(scontext) " {{{ endfunction " }}} function! phpcomplete#GetClassLocation(classname) " {{{ + " Check classname may be name of built in object + if !exists("g:php_omni_bi_classes") + let g:php_omni_bi_classes = {} + for i in keys(g:php_builtin_object_functions) + let g:php_omni_bi_classes[substitute(i, '::.*$', '', '')] = '' + endfor + endif + if has_key(g:php_omni_bi_classes, a:classname) + return 'VIMPHP_BUILTINOBJECT' + endif + " Get class location for fname in tagfiles() let fhead = fnamemodify(fname, ":h") @@ -583,8 +626,12 @@ function! phpcomplete#GetClassLocation(classname) " {{{ let fname = escape(fname, " \\") exe 'silent! vimgrep /^'.a:classname.'.*\tc\(\t\|$\)/j '.fname let qflist = getqflist() - " As in GetClassName we can manage only one element - let classlocation = matchstr(qflist[0]['text'], '\t\zs\f\+\ze\t') + " As in GetClassName we can manage only one element if it exists + if len(qflist) > 0 + let classlocation = matchstr(qflist[0]['text'], '\t\zs\f\+\ze\t') + else + return '' + endif " And only one class location if classlocation != '' let classlocation = fhead.classlocation @@ -614,6 +661,7 @@ function! phpcomplete#GetClassContents(file, name) " {{{ else let extends_class = '' endif + call search('{') normal! % let classc = getline(cfline, ".") let classcontent = join(classc, "\n") diff --git a/runtime/autoload/sqlcomplete.vim b/runtime/autoload/sqlcomplete.vim index 146cf2133..c803932c2 100644 --- a/runtime/autoload/sqlcomplete.vim +++ b/runtime/autoload/sqlcomplete.vim @@ -1,8 +1,8 @@ " Vim OMNI completion script for SQL " Language: SQL " Maintainer: David Fishburn <fishburn@ianywhere.com> -" Version: 4.0 -" Last Change: Wed Apr 26 2006 3:00:06 PM +" Version: 5.0 +" Last Change: Mon Jun 05 2006 3:30:04 PM " Usage: For detailed help " ":help sql.txt" " or ":help ft-sql-omni" @@ -22,7 +22,7 @@ endif if exists('g:loaded_sql_completion') finish endif -let g:loaded_sql_completion = 40 +let g:loaded_sql_completion = 50 " Maintains filename of dictionary let s:sql_file_table = "" @@ -113,7 +113,7 @@ function! sqlcomplete#Complete(findstart, base) " If lastword has already been set for column completion " break from the loop, since we do not also want to pickup " a table name if it was also supplied. - if lastword != -1 && compl_type == 'column' + if lastword != -1 && compl_type == 'column' break endif " If column completion was specified stop at the "." if @@ -176,11 +176,19 @@ function! sqlcomplete#Complete(findstart, base) return [] endif + " Allow the user to override the dbext plugin to specify whether + " the owner/creator should be included in the list + let saved_dbext_show_owner = 1 + if exists('g:dbext_default_dict_show_owner') + let saved_dbext_show_owner = g:dbext_default_dict_show_owner + endif + let g:dbext_default_dict_show_owner = g:omni_sql_include_owner + + let compl_type_uc = substitute(compl_type, '\w\+', '\u&', '') if s:sql_file_{compl_type} == "" - let compl_type = substitute(compl_type, '\w\+', '\u&', '') - let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type) + let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type_uc) endif - let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type) + let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type_uc) if s:sql_file_{compl_type} != "" if filereadable(s:sql_file_{compl_type}) let compl_list = readfile(s:sql_file_{compl_type}) @@ -194,7 +202,9 @@ function! sqlcomplete#Complete(findstart, base) " endif endif endif - elseif compl_type == 'column' + + let g:dbext_default_dict_show_owner = saved_dbext_show_owner + elseif compl_type =~? 'column' " This type of completion relies upon the dbext.vim plugin if s:SQLCCheck4dbext() == -1 @@ -209,33 +219,88 @@ function! sqlcomplete#Complete(findstart, base) let base = s:save_prev_table endif - if base != "" - let compl_list = s:SQLCGetColumns(base, '') - let s:save_prev_table = base - let base = '' + let owner = '' + let column = '' + + if base =~ '\.' + " Check if the owner/creator has been specified + let owner = matchstr( base, '^\zs.*\ze\..*\..*' ) + let table = matchstr( base, '^\(.*\.\)\?\zs.*\ze\..*' ) + let column = matchstr( base, '.*\.\zs.*' ) + + " It is pretty well impossible to determine if the user + " has entered: + " owner.table + " table.column_prefix + " So there are a couple of things we can do to mitigate + " this issue. + " 1. Check if the dbext plugin has the option turned + " on to even allow owners + " 2. Based on 1, if the user is showing a table list + " and the DrillIntoTable (using <C-Right>) then + " this will be owner.table. In this case, we can + " check to see the table.column exists in the + " cached table list. If it does, then we have + " determined the user has actually chosen + " owner.table, not table.column_prefix. + let found = -1 + if g:omni_sql_include_owner == 1 && owner == '' + if filereadable(s:sql_file_table) + let tbl_list = readfile(s:sql_file_table) + let found = index( tbl_list, ((table != '')?(table.'.'):'').column) + endif + endif + " If the table.column was found in the table list, we can safely assume + " the owner was not provided and shift the items appropriately. + " OR + " If the user has indicated not to use table owners at all and + " the base ends in a '.' we know they are not providing a column + " name, so we can shift the items appropriately. + if found != -1 || (g:omni_sql_include_owner == 0 && base !~ '\.$') + let owner = table + let table = column + let column = '' + endif + else + let table = base endif - elseif compl_type == 'column_csv' - " This type of completion relies upon the dbext.vim plugin - if s:SQLCCheck4dbext() == -1 - return [] - endif + " Get anything after the . and consider this the table name + " If an owner has been specified, then we must consider the + " base to be a partial column name + " let base = matchstr( base, '^\(.*\.\)\?\zs.*' ) - if base == "" - " The last time we displayed a column list we stored - " the table name. If the user selects a column list - " without a table name of alias present, assume they want - " the previous column list displayed. - let base = s:save_prev_table - endif - - if base != "" - let compl_list = s:SQLCGetColumns(base, 'csv') + if table != "" let s:save_prev_table = base - " Join the column array into 1 single element array - " but make the columns column separated - let compl_list = [join(compl_list, ', ')] - let base = '' + let list_type = '' + + if compl_type == 'column_csv' + " Return one array element, with a comma separated + " list of values instead of multiple array entries + " for each column in the table. + let list_type = 'csv' + endif + + let compl_list = s:SQLCGetColumns(table, list_type) + if column != '' + " If no column prefix has been provided and the table + " name was provided, append it to each of the items + " returned. + let compl_list = map(compl_list, "table.'.'.v:val") + if owner != '' + " If an owner has been provided append it to each of the + " items returned. + let compl_list = map(compl_list, "owner.'.'.v:val") + endif + else + let base = '' + endif + + if compl_type == 'column_csv' + " Join the column array into 1 single element array + " but make the columns column separated + let compl_list = [join(compl_list, ', ')] + endif endif elseif compl_type == 'resetCache' " Reset all cached items @@ -256,7 +321,7 @@ function! sqlcomplete#Complete(findstart, base) if base != '' " Filter the list based on the first few characters the user " entered - let expr = 'v:val '.(g:omni_sql_ignorecase==1?'=~?':'=~#').' "^'.base.'"' + let expr = 'v:val '.(g:omni_sql_ignorecase==1?'=~?':'=~#').' "\\(^'.base.'\\|\\([^.]*\\)\\?'.base.'\\)"' let compl_list = filter(deepcopy(compl_list), expr) endif @@ -274,6 +339,8 @@ function! sqlcomplete#PreCacheSyntax(...) else let syn_group_arr = g:omni_sql_precache_syntax_groups endif + " For each group specified in the list, precache all + " the sytnax items. if !empty(syn_group_arr) for group_name in syn_group_arr call s:SQLCGetSyntaxList(group_name) @@ -444,9 +511,23 @@ function! s:SQLCAddAlias(table_name, table_alias, cols) return cols endfunction +function! s:SQLCGetObjectOwner(object) + " The owner regex matches a word at the start of the string which is + " followed by a dot, but doesn't include the dot in the result. + " ^ - from beginning of line + " "\? - ignore any quotes + " \zs - start the match now + " \w\+ - get owner name + " \ze - end the match + " "\? - ignore any quotes + " \. - must by followed by a . + let owner = matchstr( a:object, '^"\?\zs\w\+\ze"\?\.' ) + return owner +endfunction + function! s:SQLCGetColumns(table_name, list_type) - let table_name = matchstr(a:table_name, '^\w\+') - let table_name = matchstr(a:table_name, '^[a-zA-Z0-9_.]\+') + " Check if the table name was provided as part of the column name + let table_name = matchstr(a:table_name, '^[a-zA-Z0-9_]\+\ze\.\?') let table_cols = [] let table_alias = '' let move_to_top = 1 |