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

Sql-Hint dont show autocomplete when having tab caracters and new line between alias and table #4712

Open
diegogvieira opened this issue Apr 26, 2017 · 6 comments

Comments

@diegogvieira
Copy link

diegogvieira commented Apr 26, 2017

When I use the following sentecen in sql mode:

select a. (here should show autocomplete)
from
table

a

Assuming between from and table there is a tab caracter (\t) or anything from unusual, it breaks the autocomplete, the autocomplete fails to bring the table columns.

I solved this by two changes:

The first is: I just update the previous word with a valid word

if (wordUpperCase !== CONS.ALIAS_KEYWORD
&& word !== ''
&& word !== ' '
&& word !== '\n'
&& word !== '\r\n')

The second is: replacing all tab caracters with space:

eachWord(lineText.replace(/[\t]+/, ' '), function(word) {

All this changes are located at: sql-hint.js, function findTableByAlias(alias, editor), line: 196

What do you guys think

@diegogvieira diegogvieira changed the title Sql-Hint dont autocomplete and tab caracterer and new line Sql-Hint dont show autocomplete when having tab caracters and new line between alias and table Apr 26, 2017
@marijnh
Copy link
Member

marijnh commented Apr 27, 2017

Does attached patch help?

@diegogvieira
Copy link
Author

diegogvieira commented Apr 27, 2017

You also needs to replace the previousWord logics. Because It was being updated with space, \n caracters and tabs. Here:

if (wordUpperCase !== CONS.ALIAS_KEYWORD
&& word !== ''
&& word !== ' '
&& word !== '\n'
&& word !== '\r\n')
previousWord = word;

previous word should ignore anything like spaces, tabs and newlines.

I also intend to modify the autocomplete which show columns from tables. When you press some key, it does not filter. When done, I will post changes.

@marijnh
Copy link
Member

marijnh commented Apr 28, 2017

You also needs to replace the previousWord logics.

Are you sure? They way I wrote eachWord, it shouldn't ever return a newline character or empty string.

@diegogvieira
Copy link
Author

I will do more tests until tomorrow, sorry for the delay.

@JannemanDev
Copy link

JannemanDev commented May 1, 2017

There are special testcases to be tested for example:
"SELECT o. FROM Plant p,offerte o"

"SELECT p. FROM Plant
p,offerte o"

"SELECT p. FROM Plant

p,offerte o"

After the point use ctrl-space.

In my test findings below code works best:

function eachWord(lineText, f) {    
    if (!lineText) return;    
    var excepted = /[,;]/g;    
    lineText=lineText.replace(excepted, ' ');    
    var words = lineText.split(/\s+/);    
    for (var i = 0; i < words.length; i++) {     
      if (words[i]) f(words[i]);    
    }  
  }
`

@diegogvieira
Copy link
Author

diegogvieira commented May 1, 2017

Code above Works better.

I found a situation where we may improve:

select a.col_A, b.
from	table1 a
			inner join
		(select table2.other_columns1 as outterColumn from table2) as b

In the situation above, pressing dot after b does not bring autocomplete. it should show b.outterColumn

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

No branches or pull requests

3 participants