[SERVER-4043] Tab completion does not work in mid-code Created: 09/Oct/11  Updated: 11/Jul/16  Resolved: 16/Nov/11

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: 2.1.0

Type: Bug Priority: Minor - P4
Reporter: Tad Marshall Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Tab completion in the shell seems to stop working after other code is already on the input line. It seems like this dates to the introduction of linenoise as a readline replacement.

MongoDB shell version: 2.1.0-pre-
> f=function(){} // define empty function
function () {
}
> f.toL<tab>ocaleString() // hit tab after "f.toL" and it completes (I added the ")")
function () {
}
> typeof f.toL<tab> // nothing, no completion
undefined
> g=f.toL<tab> // nothing, no completion

The behavior is the same in 1.9.1, 2.0.0 and the current code. This works in 1.8.4-rc1-pre- built from source today.

Tested in Ubuntu 11.04 with gnome terminal.



 Comments   
Comment by Tad Marshall [ 16/Nov/11 ]

Fixed by commit 9bef2fd11e1aa85581c41a7a9ac48ebfb94e7d63 (SERVER-4043 – fix tab completion in mid-code).

Comment by auto [ 16/Nov/11 ]

Author:

{u'login': u'', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-4043 – fix tab completion in mid-code

Add code to linenoise to do what readline was doing. When tab is
hit, we need to search backwards from the insertion point for a
break character (we're using " =+-/\\*?\"'`&<>;|@

{([])}

" for now)
and only pass the characters between that point and the cursor
position to the completion routine. When it gives us possible
completions, we need to insert them in place of the string we
extracted, which makes completion work when not at the left margin
and even when inside another expression. Linenoise was passing
the whole input line and substituting the replacement text for the
entire line.
Branch: master
https://github.com/mongodb/mongo/commit/9bef2fd11e1aa85581c41a7a9ac48ebfb94e7d63

Comment by Tad Marshall [ 27/Oct/11 ]

Pull request 110 got closed and I forget if Dwight closed it or I did. The problem wasn't with my fix which was and is good but with the incorrect way that I was issuing my pull requests. I was making each pull request against a commit that was based on my previous commits and the way GitHub works this caused each of my pull requests to include every previous change I had made. You can view the specific code changes for this bug at https://github.com/tadmarshall/mongo/commit/8d04e31d9e4d71af2f8630cf3d4cd28daeca5557 .

I can resubmit the pull request but because there is a call to refreshLine(), there is an interaction with my larger fix to SERVER-3771 in https://github.com/mongodb/mongo/pull/123 (I changed one of the call's arguments). If I create a new pull request for this bug fix, then it either requires pull request 123 to be applied first or there will be a merge conflict.

There is enough information in the earlier (closed) pull request (110) in the commit mentioned above that someone could hand-merge the code if they felt like it, or I can resubmit a pull request dependent on 123 or a variation that assumes that 123 will be rejected. Let me know what you'd like.

In any case, this is a significant bug (tab completion is broken at any location other than the start of a line) and the fix is available, so some version of the fix should get into the codebase.

Comment by Tad Marshall [ 10/Oct/11 ]

Pull request https://github.com/mongodb/mongo/pull/110 addresses this.

Comment by Tad Marshall [ 10/Oct/11 ]

readline was doing some processing that we weren't emulating in linenoise. It looks backwards in the input for a break character and only passes the portion of the buffer between the break character and the current position to the completion routine. So, when I type "g=f.toL<tab>", the 1.8.* readline code would pass "f.toL" to our command completion code, which it handled fine. The newer linenoise code was passing "g=f.toL" which fails. readline also inserts the completion text into the command line at the current position replacing the extracted portion. linenoise was taking the completion text as a full command line replacement. Doing what readline did should make the code work again.

Generated at Thu Feb 08 03:04:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.