xialvjun / ts-sql-plugin

TypeScript Language Service Plugin for SQL with a tagged template strings SQL builder.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autocomplete broken on schemas in 0.8.1

darky opened this issue · comments

@xialvjun, do you know possible cause of this? Maybe something was missed on refactoring?

add some plugin config

{
// change it from string array to just one string(easy to write)
"command": "psql -c",

// pg | mysql | custom; 
// "pg" means schema_command = command + `copy (select table_schema, table_name, column_name from information_schema.columns WHERE table_schema=CURRENT_SCHEMA()) to stdout delimiter ','`
// "mysql" means schema_command = command + `SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME from information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE()`
// and you can custom your own schema_command
"schema_command": "pg",

// old version has default value mock "null", but it can not be used in mysql. Now we can custom it.
"mock": "0",

// change `sql.mock`'s logic:
// old: sql.mock = (obj: {mock: string, placeholder: string}) => ({ [symbol]: true, text: obj.placeholder, values: [] });
// new: sql.mock = <M extends string>(value: any) => value;
// change the old one to new one because: we add mock for compile time, not runtime. If we want custom runtime sql, use `sql.raw([just_any_string])`. If we want custom compile time sql but othe runtime sql, we can `sql.mock<'for update'>(sql.raw(['limit 10']))`
"tags.mock": "mock",
}

Then, after you add "schema_command": "pg",, you should get autocomplete.

But there indeed be some problem, I didn't get autocomplete after me add "schema_command": "pg",... But, even I'm using v0.7.1, I didn't get it too. I don't know why. Maybe there are some problem in my ide. Is there some ide comfig to use autocomplete in v0.7.1 ? I have disabled all extensions in my vscode.

I debuged into v0.7.1, found the template service works right. But my vscode only call getCompletionsAtPosition when I input punctuation like:

sql`
sql`select * from person where person.
sql``

It doesn't call getCompletionsAtPosition when I input sql`select * from pers.
So the matched query is always an empty string....
If I remove if (query), then the autocomplete is ok, but the autocomplete list is too many.

Don't know why my vscode call getCompletionsAtPosition at such a time... 😞

@xialvjun thanks! This settings helps me and autocomplete works again.
But here little regression, schemas missing now.
It's very strange situation with your autocomplete, I try to think about it too.

what do you mean by schemas missing now.
I think people may just want autocomplete of just this database, so I add WHERE table_schema=CURRENT_SCHEMA() in pg version of schema_command. If you want all schemas columns, set

"schema_command": "copy (select table_schema, table_name, column_name from information_schema.columns) to stdout delimiter ','"

@xialvjun thanks! This works! But little notice:
"schema_command": "psql -c \"copy (select table_schema, table_name, column_name from information_schema.columns) to stdout delimiter ','\""