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
Hide 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 (
.
"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
)
{
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
.
Equal
(
t
,
[]
string
{
"foreign_key_check"
,
"foreign_key_list("
,
"foreign_keys"
},
pragmas
,
"unexpected pragmas"
)
}
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
,
[]
string
{
"substr("
,
"sum("
},
funcs
,
"unexpected functions"
)
}
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
,
[]
string
{
".headers"
,
".help"
},
cmds
,
"unexpected commands"
)
}
...
...
@@ -31,7 +43,7 @@ func TestCache(t *testing.T) {
db
,
err
:=
sqlite
.
Open
(
":memory:"
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
defer
db
.
Close
()
cc
:=
CreateCache
(
db
)
cc
:=
createCache
(
t
)
err
=
cc
.
Update
(
db
)
assert
.
Tf
(
t
,
err
==
nil
,
"%v"
,
err
)
}
shell/shell.go
View file @
a52244ac
...
...
@@ -118,16 +118,18 @@ func catchInterrupt() {
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
)
{
return
line
[
:
pos
],
nil
,
line
[
pos
:
]
}
prefix
:=
line
[
:
pos
]
var
err
error
var
matches
[]
string
if
isCommand
(
line
)
{
i
:=
strings
.
LastIndex
(
prefix
,
" "
)
if
i
==
-
1
{
matches
=
shell
.
CompleteCmd
(
prefix
)
matches
,
err
=
cc
.
CompleteCmd
(
prefix
)
check
(
err
)
if
len
(
matches
)
>
0
{
prefix
=
""
}
...
...
@@ -135,7 +137,8 @@ func completion(line string, pos int) (string, []string, string) {
}
else
{
fields
:=
strings
.
Fields
(
prefix
)
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
:
]
...
...
@@ -156,7 +159,11 @@ func main() {
}
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
)
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