Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full text search #414

Merged
merged 5 commits into from
Jun 6, 2017
Merged

Conversation

billyvg
Copy link

@billyvg billyvg commented Jun 5, 2017

I would like to have this feature so that autocomplete plugins (i.e. deoplete) can be supported. The workflow would be more streamlined this way.

Edit:
Here is the deoplete plugin

Billy Vong added 2 commits June 5, 2017 09:04
* Adds a new sqlite table that indexes modules names
* Adds `search` command to search for modules
Copy link
Collaborator

@trotzig trotzig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic, thanks @billyvg! I'm definitely going to start using this plugin.

I left a few comments inline. Feel free to address those that you see fit. When you're done, drop a line here and I'll merge.

@@ -192,6 +203,17 @@ export default class ExportsStorage {
reject(err);
return;
}

if (!additional) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to read the code a few times to understand what this boolean meant. A comment here could probably make things clearer. 🤔

@@ -52,6 +52,17 @@ export default class ExportsStorage {

this.db.run(
`
CREATE VIRTUAL TABLE exports_fts USING fts4(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a little why the virtual table is necessary here? I could see this being implemented using "simple" WHERE name LIKE 'foobar%' as well. The redundancy is probably okay, I'm asking more because I'm (passively) searching for alternatives to sqlite3. Multiple people have reported that it's hard to install (e.g. Galooshi/atom-import-js#15, Galooshi/atom-import-js#18) and it would be easier if there was a "pure" javascript alternative.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sqlite's full text search requires a virtual table and using full text search performs better than LIKE 'foo%'. I'm not too familiar with sqlite, but it's possible we don't need a separate table at all, but I figured this way I don't break anything.


if (!additional) {
this.db.run(
'INSERT INTO exports_fts VALUES (?, ?, ?, ?)',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fts is for full text search, right? I think it would be okay to spell that out instead of using the abbreviation.

return;
}
resolve(
rows.map(({ name, path, isDefault, packageName }) => ({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanted to DRY up things, you could introduce a normalization function (normalizeRowData?) and use it here and inside the get() method.

...defaultNames.map(name =>
this._insert({ name, pathToFile, isDefault: true, packageName })),
...defaultNames.map((defaultName: string | Object) => {
const defaultNameObj = typeof defaultName === 'string' ? { name: defaultName, additional: false } : defaultName;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks a little defensive. Can we make sure that we only pass in objects instead?

@@ -19,7 +19,6 @@ beforeEach(() => {
it('returns matching modules', () => findJsModulesFor(
new Configuration('./bar.js'),
'foo',
'./bar.js',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@trotzig
Copy link
Collaborator

trotzig commented Jun 6, 2017

Ready to go?

One thing that crossed my mind when looking at the deoplete plugin is that, since you're using the command-line tool directly, there's a dependency on a warm cache. If people use your plugin without also using vim-import-js (actively), the items they need won't be in import-js storage. If you wanted to fix that you could use a daemon importjs process to communicate. Or better yet, reuse the daemon process from vim-import-js. That way you'd make sure that the cache is in a better state when you autocomplete.

@billyvg
Copy link
Author

billyvg commented Jun 6, 2017

Should be good to go now!

For the deoplete plugin, I should probably call importjs#ExecCommand instead, yeah? (And also add a search function in vim-import-js)

// currently just casts `isDefault` to boolean
return rows.map(({ isDefault, ...other }) => ({
isDefault: !!isDefault,
...other,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@trotzig
Copy link
Collaborator

trotzig commented Jun 6, 2017

Yeah, that sounds like the right thing. You'd also have to add search to the list of commands in lib/daemon.js. That's the entry point for all interaction between vim-import-js and import-js.

@trotzig trotzig merged commit 093e6f7 into Galooshi:master Jun 6, 2017
@trotzig
Copy link
Collaborator

trotzig commented Jun 6, 2017

I plan on releasing this tomorrow after some manual testing locally. Thanks again for the contribution @billyvg!

@lencioni
Copy link
Collaborator

lencioni commented Jun 6, 2017

This is perfect timing. I was just chatting with @dabbott about using import-js with autocomplete. It would be great if it added the import after selecting the item from the autocomplete list.

@trotzig
Copy link
Collaborator

trotzig commented Jun 7, 2017

I'm very excited about this as well. If I read the source for the deoplete plugin right, I believe it did import the variable as well.

@billyvg
Copy link
Author

billyvg commented Jun 7, 2017

Yep the deoplete plugin will add the import statement - though there are some small annoying bugs with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants