Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
a52244ac
Commit
a52244ac
authored
Jun 07, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace radix trees by FTS tables for autocompletion
parent
0d695f4e
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
309 additions
and
218 deletions
+309
-218
shell/autocomplete.go
shell/autocomplete.go
+282
-210
shell/autocomplete_test.go
shell/autocomplete_test.go
+16
-4
shell/shell.go
shell/shell.go
+11
-4
No files found.
shell/autocomplete.go
View file @
a52244ac
This diff is collapsed.
Click to expand it.
shell/autocomplete_test.go
View file @
a52244ac
...
@@ -12,18 +12,30 @@ import (
...
@@ -12,18 +12,30 @@ import (
.
"github.com/gwenn/gosqlite/shell"
.
"github.com/gwenn/gosqlite/shell"
)
)
func
createCache
(
t
*
testing
.
T
)
*
CompletionCache
{
cc
,
err
:=
CreateCache
()
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
return
cc
}
func
TestPragmaNames
(
t
*
testing
.
T
)
{
func
TestPragmaNames
(
t
*
testing
.
T
)
{
pragmas
:=
CompletePragma
(
"fo"
)
cc
:=
createCache
(
t
)
pragmas
,
err
:=
cc
.
CompletePragma
(
"fo"
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
assert
.
Equalf
(
t
,
3
,
len
(
pragmas
),
"got %d pragmas; expected %d"
,
len
(
pragmas
),
3
)
assert
.
Equalf
(
t
,
3
,
len
(
pragmas
),
"got %d pragmas; expected %d"
,
len
(
pragmas
),
3
)
assert
.
Equal
(
t
,
[]
string
{
"foreign_key_check"
,
"foreign_key_list("
,
"foreign_keys"
},
pragmas
,
"unexpected pragmas"
)
assert
.
Equal
(
t
,
[]
string
{
"foreign_key_check"
,
"foreign_key_list("
,
"foreign_keys"
},
pragmas
,
"unexpected pragmas"
)
}
}
func
TestFuncNames
(
t
*
testing
.
T
)
{
func
TestFuncNames
(
t
*
testing
.
T
)
{
funcs
:=
CompleteFunc
(
"su"
)
cc
:=
createCache
(
t
)
funcs
,
err
:=
cc
.
CompleteFunc
(
"su"
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
assert
.
Equal
(
t
,
2
,
len
(
funcs
),
"got %d functions; expected %d"
,
len
(
funcs
),
2
)
assert
.
Equal
(
t
,
2
,
len
(
funcs
),
"got %d functions; expected %d"
,
len
(
funcs
),
2
)
assert
.
Equal
(
t
,
[]
string
{
"substr("
,
"sum("
},
funcs
,
"unexpected functions"
)
assert
.
Equal
(
t
,
[]
string
{
"substr("
,
"sum("
},
funcs
,
"unexpected functions"
)
}
}
func
TestCmdNames
(
t
*
testing
.
T
)
{
func
TestCmdNames
(
t
*
testing
.
T
)
{
cmds
:=
CompleteCmd
(
".h"
)
cc
:=
createCache
(
t
)
cmds
,
err
:=
cc
.
CompleteCmd
(
".h"
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
assert
.
Equal
(
t
,
2
,
len
(
cmds
),
"got %d commands; expected %d"
,
len
(
cmds
),
2
)
assert
.
Equal
(
t
,
2
,
len
(
cmds
),
"got %d commands; expected %d"
,
len
(
cmds
),
2
)
assert
.
Equal
(
t
,
[]
string
{
".headers"
,
".help"
},
cmds
,
"unexpected commands"
)
assert
.
Equal
(
t
,
[]
string
{
".headers"
,
".help"
},
cmds
,
"unexpected commands"
)
}
}
...
@@ -31,7 +43,7 @@ func TestCache(t *testing.T) {
...
@@ -31,7 +43,7 @@ func TestCache(t *testing.T) {
db
,
err
:=
sqlite
.
Open
(
":memory:"
)
db
,
err
:=
sqlite
.
Open
(
":memory:"
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
defer
db
.
Close
()
defer
db
.
Close
()
cc
:=
CreateCache
(
db
)
cc
:=
createCache
(
t
)
err
=
cc
.
Update
(
db
)
err
=
cc
.
Update
(
db
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
}
}
shell/shell.go
View file @
a52244ac
...
@@ -118,16 +118,18 @@ func catchInterrupt() {
...
@@ -118,16 +118,18 @@ func catchInterrupt() {
signal
.
Notify
(
ch
,
syscall
.
SIGINT
)
signal
.
Notify
(
ch
,
syscall
.
SIGINT
)
}
}
func
completion
(
line
string
,
pos
int
)
(
string
,
[]
string
,
string
)
{
func
completion
(
cc
*
shell
.
CompletionCache
,
line
string
,
pos
int
)
(
string
,
[]
string
,
string
)
{
if
isBlank
(
line
)
{
if
isBlank
(
line
)
{
return
line
[
:
pos
],
nil
,
line
[
pos
:
]
return
line
[
:
pos
],
nil
,
line
[
pos
:
]
}
}
prefix
:=
line
[
:
pos
]
prefix
:=
line
[
:
pos
]
var
err
error
var
matches
[]
string
var
matches
[]
string
if
isCommand
(
line
)
{
if
isCommand
(
line
)
{
i
:=
strings
.
LastIndex
(
prefix
,
" "
)
i
:=
strings
.
LastIndex
(
prefix
,
" "
)
if
i
==
-
1
{
if
i
==
-
1
{
matches
=
shell
.
CompleteCmd
(
prefix
)
matches
,
err
=
cc
.
CompleteCmd
(
prefix
)
check
(
err
)
if
len
(
matches
)
>
0
{
if
len
(
matches
)
>
0
{
prefix
=
""
prefix
=
""
}
}
...
@@ -135,7 +137,8 @@ func completion(line string, pos int) (string, []string, string) {
...
@@ -135,7 +137,8 @@ func completion(line string, pos int) (string, []string, string) {
}
else
{
}
else
{
fields
:=
strings
.
Fields
(
prefix
)
fields
:=
strings
.
Fields
(
prefix
)
if
strings
.
EqualFold
(
"PRAGMA"
,
fields
[
0
])
{
// TODO check pos
if
strings
.
EqualFold
(
"PRAGMA"
,
fields
[
0
])
{
// TODO check pos
matches
=
shell
.
CompletePragma
(
fields
[
1
])
matches
,
err
=
cc
.
CompletePragma
(
fields
[
1
])
check
(
err
)
}
}
}
}
return
prefix
,
matches
,
line
[
pos
:
]
return
prefix
,
matches
,
line
[
pos
:
]
...
@@ -156,7 +159,11 @@ func main() {
...
@@ -156,7 +159,11 @@ func main() {
}
}
state
.
Close
()
state
.
Close
()
}()
}()
state
.
SetWordCompleter
(
completion
)
completionCache
,
err
:=
shell
.
CreateCache
()
check
(
err
)
state
.
SetWordCompleter
(
func
(
line
string
,
pos
int
)
(
string
,
[]
string
,
string
)
{
return
completion
(
completionCache
,
line
,
pos
)
})
err
=
loadHistory
(
state
,
historyFileName
)
err
=
loadHistory
(
state
,
historyFileName
)
check
(
err
)
check
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment