comparison runtime/autoload/sqlcomplete.vim @ 840:2c885fab04e3 v7.0e06

updated for version 7.0e06
author vimboss
date Sat, 22 Apr 2006 22:33:57 +0000
parents 23f82b5d2814
children d3bbb5dd3913
comparison
equal deleted inserted replaced
839:1f3b1021f002 840:2c885fab04e3
1 " Vim completion script 1 " Vim completion script
2 " Language: SQL 2 " Language: SQL
3 " Maintainer: David Fishburn <fishburn@ianywhere.com> 3 " Maintainer: David Fishburn <fishburn@ianywhere.com>
4 " Version: 2.0 4 " Version: 3.0
5 " Last Change: Mon Apr 03 2006 10:21:36 PM 5 " Last Change: Thu Apr 20 2006 8:47:12 PM
6 6
7 " Set completion with CTRL-X CTRL-O to autoloaded function. 7 " Set completion with CTRL-X CTRL-O to autoloaded function.
8 " This check is in place in case this script is 8 " This check is in place in case this script is
9 " sourced directly instead of using the autoload feature. 9 " sourced directly instead of using the autoload feature.
10 if exists('&omnifunc') 10 if exists('&omnifunc')
16 endif 16 endif
17 17
18 if exists('g:loaded_sql_completion') 18 if exists('g:loaded_sql_completion')
19 finish 19 finish
20 endif 20 endif
21 let g:loaded_sql_completion = 1 21 let g:loaded_sql_completion = 30
22 22
23 " Maintains filename of dictionary 23 " Maintains filename of dictionary
24 let s:sql_file_table = "" 24 let s:sql_file_table = ""
25 let s:sql_file_procedure = "" 25 let s:sql_file_procedure = ""
26 let s:sql_file_view = "" 26 let s:sql_file_view = ""
58 \ 'sqlOption', 58 \ 'sqlOption',
59 \ 'sqlType', 59 \ 'sqlType',
60 \ 'sqlStatement' 60 \ 'sqlStatement'
61 \ ] 61 \ ]
62 endif 62 endif
63 " Set ignorecase to the ftplugin standard
64 if !exists('g:omni_sql_ignorecase')
65 let g:omni_sql_ignorecase = &ignorecase
66 endif
67 " During table completion, should the table list also
68 " include the owner name
69 if !exists('g:omni_sql_include_owner')
70 let g:omni_sql_include_owner = 0
71 if exists('g:loaded_dbext')
72 if g:loaded_dbext >= 300
73 " New to dbext 3.00, by default the table lists include the owner
74 " name of the table. This is used when determining how much of
75 " whatever has been typed should be replaced as part of the
76 " code replacement.
77 let g:omni_sql_include_owner = 1
78 endif
79 endif
80 endif
63 81
64 " This function is used for the 'omnifunc' option. 82 " This function is used for the 'omnifunc' option.
65 function! sqlcomplete#Complete(findstart, base) 83 function! sqlcomplete#Complete(findstart, base)
66 84
67 " Default to table name completion 85 " Default to table name completion
79 let start = col('.') - 1 97 let start = col('.') - 1
80 let lastword = -1 98 let lastword = -1
81 while start > 0 99 while start > 0
82 if line[start - 1] =~ '\w' 100 if line[start - 1] =~ '\w'
83 let start -= 1 101 let start -= 1
84 elseif line[start - 1] =~ '\.' && compl_type =~ 'column' 102 elseif line[start - 1] =~ '\.' &&
85 " If the completion type is column then assume we are looking 103 \ compl_type =~ 'column\|table\|view\|procedure'
86 " for column completion column_type can be either 104 " If lastword has already been set for column completion
87 " 'column' or 'column_csv' 105 " break from the loop, since we do not also want to pickup
88 if lastword == -1 && compl_type == 'column' 106 " a table name if it was also supplied.
89 " Do not replace the table name prefix or alias 107 if lastword != -1 && compl_type =~ 'column'
90 " if completing only a single column name 108 break
109 endif
110 " Assume we are looking for column completion
111 " column_type can be either 'column' or 'column_csv'
112 if lastword == -1 && compl_type =~ 'column'
91 let lastword = start 113 let lastword = start
114 endif
115 " If omni_sql_include_owner = 0, do not include the table
116 " name as part of the substitution, so break here
117 if lastword == -1 &&
118 \ compl_type =~ 'table\|view\|procedure' &&
119 \ g:omni_sql_include_owner == 0
120 let lastword = start
121 break
92 endif 122 endif
93 let start -= 1 123 let start -= 1
94 else 124 else
95 break 125 break
96 endif 126 endif
142 endif 172 endif
143 let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type) 173 let s:sql_file_{compl_type} = DB_getDictionaryName(compl_type)
144 if s:sql_file_{compl_type} != "" 174 if s:sql_file_{compl_type} != ""
145 if filereadable(s:sql_file_{compl_type}) 175 if filereadable(s:sql_file_{compl_type})
146 let compl_list = readfile(s:sql_file_{compl_type}) 176 let compl_list = readfile(s:sql_file_{compl_type})
177 " let dic_list = readfile(s:sql_file_{compl_type})
178 " if !empty(dic_list)
179 " for elem in dic_list
180 " let kind = (compl_type=='table'?'m':(compl_type=='procedure'?'f':'v'))
181 " let item = {'word':elem, 'menu':elem, 'kind':kind, 'info':compl_type}
182 " let compl_list += [item]
183 " endfor
184 " endif
147 endif 185 endif
148 endif 186 endif
149 elseif compl_type == 'column' 187 elseif compl_type == 'column'
150 188
151 " This type of completion relies upon the dbext.vim plugin 189 " This type of completion relies upon the dbext.vim plugin
201 endif 239 endif
202 240
203 if base != '' 241 if base != ''
204 " Filter the list based on the first few characters the user 242 " Filter the list based on the first few characters the user
205 " entered 243 " entered
206 let expr = 'v:val =~ "^'.base.'"' 244 let expr = 'v:val '.(g:omni_sql_ignorecase==1?'=~?':'=~#').' "^'.base.'"'
207 let compl_list = filter(copy(compl_list), expr) 245 let compl_list = filter(deepcopy(compl_list), expr)
208 endif 246 endif
209 247
210 if exists('b:sql_compl_savefunc') && b:sql_compl_savefunc != "" 248 if exists('b:sql_compl_savefunc') && b:sql_compl_savefunc != ""
211 let &omnifunc = b:sql_compl_savefunc 249 let &omnifunc = b:sql_compl_savefunc
212 endif 250 endif
295 let msg = "The dbext plugin must be loaded for dynamic SQL completion" 333 let msg = "The dbext plugin must be loaded for dynamic SQL completion"
296 call s:SQLCErrorMsg(msg) 334 call s:SQLCErrorMsg(msg)
297 " Leave time for the user to read the error message 335 " Leave time for the user to read the error message
298 :sleep 2 336 :sleep 2
299 return -1 337 return -1
300 elseif g:loaded_dbext < 210 338 elseif g:loaded_dbext < 300
301 let msg = "The dbext plugin must be at least version 2.10 " . 339 let msg = "The dbext plugin must be at least version 3.00 " .
302 \ " for dynamic SQL completion" 340 \ " for dynamic SQL completion"
303 call s:SQLCErrorMsg(msg) 341 call s:SQLCErrorMsg(msg)
304 " Leave time for the user to read the error message 342 " Leave time for the user to read the error message
305 :sleep 2 343 :sleep 2
306 return -1 344 return -1
361 let table_name = matchstr(a:table_name, '^\w\+') 399 let table_name = matchstr(a:table_name, '^\w\+')
362 let table_cols = [] 400 let table_cols = []
363 let table_alias = '' 401 let table_alias = ''
364 let move_to_top = 1 402 let move_to_top = 1
365 403
366 if g:loaded_dbext >= 210 404 if g:loaded_dbext >= 300
367 let saveSettingAlias = DB_listOption('use_tbl_alias') 405 let saveSettingAlias = DB_listOption('use_tbl_alias')
368 exec 'DBSetOption use_tbl_alias=n' 406 exec 'DBSetOption use_tbl_alias=n'
369 endif 407 endif
370 408
371 " Check if we have already cached the column list for this table 409 " Check if we have already cached the column list for this table
477 515
478 " Return to previous location 516 " Return to previous location
479 call cursor(curline, curcol) 517 call cursor(curline, curcol)
480 518
481 if found == 0 519 if found == 0
482 if g:loaded_dbext > 201 520 if g:loaded_dbext > 300
483 exec 'DBSetOption use_tbl_alias='.saveSettingAlias 521 exec 'DBSetOption use_tbl_alias='.saveSettingAlias
484 endif 522 endif
485 523
486 " Not a SQL statement, do not display a list 524 " Not a SQL statement, do not display a list
487 return [] 525 return []
500 let table_cols = split(table_cols_str) 538 let table_cols = split(table_cols_str)
501 endif 539 endif
502 540
503 endif 541 endif
504 542
505 if g:loaded_dbext > 201 543 if g:loaded_dbext > 300
506 exec 'DBSetOption use_tbl_alias='.saveSettingAlias 544 exec 'DBSetOption use_tbl_alias='.saveSettingAlias
507 endif 545 endif
508 546
509 if a:list_type == 'csv' && !empty(table_cols) 547 if a:list_type == 'csv' && !empty(table_cols)
510 let cols = join(table_cols, ', ') 548 let cols = join(table_cols, ', ')