codemirror / codemirror5

In-browser code editor (version 5, legacy)
http://codemirror.net/5/
MIT License
26.7k stars 4.96k forks source link

sql-hint with table columns cannot filter columns #6933

Closed yinyihui closed 1 year ago

yinyihui commented 2 years ago

Codemirror Version: 5.65.4 I try the sql-hint table option and define table columns. When i input . and codemirror hint the columns correctly, but next word triggers the keywords hint not filter the columns. 图片 图片 https://github.com/codemirror/codemirror5/blob/7f488eb5c12d71ea7ea75e286b7b9c029453a298/addon/hint/sql-hint.js#L267 I find the code here and it should detect that whether the input word is behind the dot(.), then to match the table columns which is on the left.

yinyihui commented 1 year ago

As long time no relpy, I tried myself to change the source code and it works well. Just add the code after the popup checker, it can works correctly. Origin: https://github.com/codemirror/codemirror5/blob/7f488eb5c12d71ea7ea75e286b7b9c029453a298/addon/hint/sql-hint.js#L275 if (search.charAt(0) == "." || search.charAt(0) == identifierQuote) { After change: if (search.charAt(0) == "." || search.charAt(0) == identifierQuote || editor.getTokenAt(Pos(cur.line, token.start)).string == "."|| editor.getTokenAt(Pos(cur.line, token.start)).string == identifierQuote) {

marijnh commented 1 year ago

I don't see this issue happening. When I type a.I, the SQL mode makes .I a single token, so the check at that line succeeds and nameCompletion is called.

yinyihui commented 1 year ago

I don't see this issue happening. When I type a.I, the SQL mode makes .I a single token, so the check at that line succeeds and nameCompletion is called.

Did you use the sql-hint with hitOption of "tables"?To filter the columns of the table, it will hint the options of sql mode keywords, builtIns and other defaults, such as "IN, INSERT". In my opinion, the table followed by dot(.) with "tables" option in hitOption should hint and filter within the table columns, not the keywords and so on.

marijnh commented 1 year ago

Yes, I did. Set up an example script that shows the issue if you want me to look into this.

yinyihui commented 1 year ago

Set the configuration as follows: { tabSize: 2, mode: "sql", theme: "lucario", lineNumbers: true, autoCloseBrackets: true, singleCursorHeightPerLine: false, hintOptions: { completeSingle: false, tables: { "a": ["ID", "BOND_ID", "PARTY_ID"] } } }, As these settings works, then type "a.", the columns pop up correctly. Continue typing the word "I", the hint dose not filter from the columns but show the sql keywords and other builtins, such as "IN, INSERT".

marijnh commented 1 year ago

Ah, there was some weird feature in the SQL mode that turned off tokenizing of dot-prefixed identifiers unless explicitly enabled, and using "sql" as mode (rather than a specific dialect) didn't turn that on. Patch d122e55c4818ef72e45939c4c06301bc36cb4a53 should fix that.

yinyihui commented 1 year ago

Thanks for the works, and best wishes!