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
cli: add basic context insensitive tab completion for the CLI #45186
base: master
Are you sure you want to change the base?
Conversation
Alright, I'm having some trouble adding the dependency I want to vendor... Any tips? I've added the package to gopkg.toml/gopkg.lock, and I've made a commit in |
|
Awesome, thanks! |
c209ba9
to
917847c
Compare
I was able to get tab suggestions to work when there were multiple completions, but only on linux (not in this PR). Does it make sense to merge something that would only add the feature on linux not mac? |
If you don't mind I'd prefer that hackathon PRs do not get merged until they go the full cycle of review (and after we iron out the most glaring UX issues). |
Yes of course -- I've been polishing up for review. I just wanted to know what the philosophy was on differing support on different OS's. (also, not saying this is ready to be merged -- theres most likely lots of room for improvement). |
It's OK if a feature doesn't work in environment X while it works fine on environment Y; however consider:
Considering that macOS is a pretty popular dev platform, that means you might want to either work on the user messaging (a copious release note) or iterate on the code a bit more. |
That makes sense.
We can spend some more time, but attempts to sidestep the libedit bug on mac haven't led to much success. |
This PR adds basic context insensitive tab completion for the CLI. It maintains a store of keywords, variables and identifiers and uses these to match against unfinished tokens in the input stream. Release note (cli change): Add basic tab completion for the SQL CLI.
cc @knz can you take a look at this and estimate what it would need added if we wanted to get this into 20.1? (if it should be included at all) |
Sorry for dropping the ball on this. Let's pick it back up in a month from now. |
@knz out of curiosity, what makes it too late in the cycle? is this risky? |
Yes there is risk.
In an ideal world we'd operate as follows:
Of these latter steps, steps (1) - (4) are the required polish for the feature as-presented. Only step (5) can be seen as an architectural step further towards a more feature-complete tab completion and thus could be pushed to a v2. |
Thanks @knz! Let's push this to early 20.2 then! |
I don't have the bandwidth right now to fix all of these comments, but @RichardJCai had an idea: as a starting step, would it be useful to just have tab completion of our keywords? |
That certainly would be a step forward. Maybe a PM would have an educated opinion? |
Yes, I think that would be valuable as an intermediary step. It would be great to build toward full tab completion. |
Any movement on this would be great but my humble opinion is that keywords are the thing I need tab completion on the least because as a developer using the sql console I already know them all and they're usually a lot shorter than table names. |
Might be reviving this or maybe reviving it using https://microsoft.github.io/language-server-protocol/ for breather week. |
87606: sql: new heuristic-based completion engine r=rytaft,ZhouXing19 a=knz This PR extends the server-side completion logic available under SHOW COMPLETIONS. Fixes #37355. Intended for use together with #86457. The statement now returns 5 columns: completion, category, description, start, end. This change is backward-compatible with the CLI code in previous versions, which was not checking the number of columns. It works roughly as follows: 1. first the input is scanned into a token array. 2. then the token array is translated to a *sketch*: a string with the same length as the token array, where each character corresponds to an input token and an extra character indicating where the completion was requested. 3. then the completion rules are applied in sequence. Each rule inspects the sketch (and/or the token sequence) and decides whether to do nothing (skip to next rule), or to run some SQL which will return a batch of completion candidates. Each method operates exclusively on the token sequence, and does not require the overall SQL syntax to be valid or complete. Also, the completion engine executes in a streaming fashion, so that there is no need to accumulate all the completion candidates in RAM before returning them to the client. This prevents excessive memory usage server-side, and offers the client an option to cancel the search once enough suggestions have been received. Code organization: - new package `sql/compengine`: the core completion engine, also where sketches are computed. Suggested reading: `api.go` in the new package. - new package `sql/comprules`: the actual completion methods/heuristics, where sketches are mapped into SQL queries that provide the completion candidates. Suggested reading: the test cases under `testdata`. Some more words about sketches: For example, `SHOW COMPLETIONS AT OFFSET 10 FOR 'select myc from sc.mytable;'` produces the sketch `"ii'ii.i;"` where `i` indicates an identifier-like token and `'` indicates the cursor position. The purpose of the sketch is to simplify the pattern matching performed by the completion heuristics, and enables the application of regular expressions on the token sequence. For example, a heuristic to complete schema-qualified relations in the current database, or a database-qualified relation, would use the regexp `[^.;]i\.(['_]|i')`: an identifier not following a period or a semicolon, followed by a period, followed by the completion cursor (with the cursor either directly after the period or on an identifier after the period). Supersedes #45186. 93158: dev: fix bep temporary dir path r=rickystewart a=healthy-pod Release note: None Epic: none Co-authored-by: Raphael 'kena' Poss <knz@thaumogen.net> Co-authored-by: healthy-pod <ahmad@cockroachlabs.com>
This PR adds basic context insensitive tab completion for
the CLI. It maintains a store of keywords, variables
and identifiers and uses these to match against unfinished
tokens in the input stream.
Work with @Azhng
Release note (cli change): Add basic tab completion for the SQL CLI.