Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ITKEY_
Vim Sql Workbench
提交
22dc2167
V
Vim Sql Workbench
项目概览
ITKEY_
/
Vim Sql Workbench
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vim Sql Workbench
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
22dc2167
编写于
1月 12, 2015
作者:
P
POPESCU Adrian (EEAS-EXT)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed some autocomplete bugs
上级
ce8fef36
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
17 deletion
+31
-17
autoload/sw.vim
autoload/sw.vim
+5
-3
autoload/sw/autocomplete.vim
autoload/sw/autocomplete.vim
+23
-11
plugin/sw.vim
plugin/sw.vim
+3
-3
未找到文件。
autoload/sw.vim
浏览文件 @
22dc2167
...
...
@@ -253,12 +253,14 @@ function! sw#sql_split(sql, ...)
let
s
=
canon
[
0
]
let
matches
=
canon
[
1
]
let
s
=
substitute
(
s
,
'\V'
.
delimiter
,
'#SEPARATOR#'
,
'g'
)
for
_m
in
matches
let
i
=
items
(
_m
)
let
j
=
len
(
matches
)
-
1
while
j
>=
0
let
i
=
items
(
matches
[
j
])
let
m
=
'#'
.
i
[
0
][
0
]
.
'#'
let
x
=
substitute
(
i
[
0
][
1
],
"\\"
,
"\\\\\\"
,
'g'
)
let
s
=
substitute
(
s
,
m
,
x
,
'g'
)
endfor
let
j
=
j
-
1
endwhile
let
s
=
substitute
(
s
,
'#NEWLINE#'
,
"\n"
,
'g'
)
let
s
=
substitute
(
s
,
'#ESCAPEDDOUBLEQUOTE#'
,
"\\\\\""
,
'g'
)
let
s
=
substitute
(
s
,
'#ESCAPEDSINGLEQUOTE#'
,
"\\\\'"
,
'g'
)
...
...
autoload/sw/autocomplete.vim
浏览文件 @
22dc2167
...
...
@@ -22,6 +22,18 @@ 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
(
'<sfile>:p:h'
)
.
'/../../'
let
s:pattern_expressions
=
'\v\c\(([\s\t ]*select)@![^\)]{-}\)'
function
!
s:eliminate_sql_comments
(
sql
)
let
sql
=
sw
#get_sql_canonical
(
a:sql
)[
0
]
let
sql
=
substitute
(
sql
,
'\v--.{-}#NEWLINE#'
,
'#NEWLINE#'
,
'g'
)
let
sql
=
substitute
(
sql
,
'\v--.{-}$'
,
''
,
'g'
)
let
sql
=
substitute
(
sql
,
'\v\/\*.{-}\*\/'
,
''
,
'g'
)
let
sql
=
substitute
(
sql
,
'#NEWLINE#'
,
' '
,
'g'
)
return
sql
endfunction
if
exists
(
'g:sw_plugin_path'
)
" This is for cygwin. If we are under cygwin, the sqlworkbench will be a
" windows application, and vim will work with linux paths
...
...
@@ -43,11 +55,13 @@ endfunction
function
!
sw
#autocomplete#extract_current_sql
()
let
sql
=
sw
#sqlwindow#extract_current_sql
(
1
)
let
_sql
=
s:eliminate_sql_comments
(
sql
)
let
_sql
=
substitute
(
_sql
,
s:pattern_expressions
,
'#values#'
,
'g'
)
" Check to see that we are not in a subquery
let
pattern
=
'\v\c(\([ \t\s]*select[^\(]*#cursor#).*\)'
if
sql
=~
pattern
if
_
sql
=~
pattern
" If we are in a subquery, search where it begins.
let
l
=
matchlist
(
sql
,
pattern
,
'g'
)
let
l
=
matchlist
(
sql
,
'\v\c(\([ \s\t]*select([^s]|s[^e]|se[^l]|sel[^e]|sele[^c]|selec[^t]|select[^\s \t])*#cursor#)'
,
'g'
)
if
(
len
(
l
)
>=
1
)
" Get the start and end of the subquery
let
start
=
sw
#index_of
(
sql
,
l
[
1
])
...
...
@@ -265,6 +279,7 @@ function! sw#autocomplete#perform(findstart, base)
elseif
b:autocomplete_type
==
'select'
||
b:autocomplete_type
==
'update'
" If a select, first get its tables
let
tables
=
s:get_tables
(
sql
,
[])
echomsg
string
(
tables
)
" If we returned an empty string, then no autocomplete
if
string
(
tables
)
==
""
return
[]
...
...
@@ -414,7 +429,7 @@ endfunction
function
!
s:extract_subqueries
(
sql
)
let
pattern
=
'\v\c(\([ \s\t]*select[^\(\)]+\))'
let
s
=
substitute
(
a:sql
,
'\v\c\(([\s\t ]*select)@![^\)]{-}\)'
,
'#values#'
,
'g'
)
let
s
=
substitute
(
a:sql
,
s:pattern_expressions
,
'#values#'
,
'g'
)
let
matches
=
[]
let
n
=
0
let
m
=
matchstr
(
s
,
pattern
,
''
)
...
...
@@ -441,11 +456,7 @@ function! s:get_fields_part(sql)
endfunction
function
!
s:get_tables_part
(
sql
)
let
sql
=
sw
#get_sql_canonical
(
a:sql
)[
0
]
let
sql
=
substitute
(
sql
,
'\v--.{-}#NEWLINE#'
,
'#NEWLINE#'
,
'g'
)
let
sql
=
substitute
(
sql
,
'\v--.{-}$'
,
''
,
'g'
)
let
sql
=
substitute
(
sql
,
'\v\/\*.{-}\*\/'
,
''
,
'g'
)
let
sql
=
substitute
(
sql
,
'#NEWLINE#'
,
' '
,
'g'
)
let
sql
=
s:eliminate_sql_comments
(
a:sql
)
let
_subqueries
=
s:extract_subqueries
(
sql
)
let
sql
=
_subqueries
[
0
]
let
subqueries
=
_subqueries
[
1
]
...
...
@@ -486,11 +497,12 @@ function! s:canonize_from(from)
endfunction
function
!
s:get_subquery_fields
(
sql
,
subqueries
)
let
sql
=
substitute
(
a:sql
,
'\V#values#'
,
'()'
,
'g'
)
" If we have a subquery, we just extract the fields out of it. We don't
" care about tables and other stuff. It will probably be identified by an
" alias, and we want to return alias.fields
" Split the fields part by the comma
let
fields
=
split
(
s:get_fields_part
(
a:
sql
),
','
)
let
fields
=
split
(
s:get_fields_part
(
sql
),
','
)
let
result
=
[]
for
field
in
fields
" First we trim the field
...
...
@@ -511,7 +523,7 @@ function! s:get_subquery_fields(sql, subqueries)
" get_tables_part function to consider the query as a select
" query, and not update query
call
sw
#session#set_buffer_variable
(
'subquery'
,
1
)
let
_tmp
=
s:get_tables
(
a:
sql
,
a:subqueries
)
let
_tmp
=
s:get_tables
(
sql
,
a:subqueries
)
for
row
in
_tmp
if
(
has_key
(
row
,
'fields'
))
for
f
in
row
[
'fields'
]
...
...
@@ -531,7 +543,7 @@ function! s:get_subquery_fields(sql, subqueries)
endfor
else
" Otherwise, get the from part of this subquery
let
_r
=
s:get_tables_part
(
a:
sql
)
let
_r
=
s:get_tables_part
(
sql
)
let
from
=
_r
[
0
]
let
subqueries
=
_r
[
1
]
+
a:subqueries
let
from
=
s:canonize_from
(
from
)
...
...
plugin/sw.vim
浏览文件 @
22dc2167
...
...
@@ -17,9 +17,9 @@
"
"============================================================================"
if
exists
(
'g:loaded_vim_sql_workbench'
)
||
v
:
version
<
700
finish
endif
"
if exists('g:loaded_vim_sql_workbench') || v:version < 700
"
finish
"
endif
let
g:loaded_vim_sql_workbench
=
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录