Summary: | auto complete directly if only one available completion | ||
---|---|---|---|
Product: | [Applications] kdevelop | Reporter: | Robert Jonsson <rj> |
Component: | Code completion | Assignee: | kdevelop-bugs-null |
Status: | RESOLVED FIXED | ||
Severity: | wishlist | CC: | joerg |
Priority: | NOR | ||
Version: | git master | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Robert Jonsson
2003-07-09 14:49:23 UTC
*** Bug 63324 has been marked as a duplicate of this bug. *** I don't think this is such a good idea. We are completing on several different levels now, and autocompleting when you didn't intend would be bad. The only even partially sane way this would work is if the completion had been specifically narrowed by keying, but even then it is a bad idea. > I don't think this is such a good idea. We are completing on several
> different levels now, and autocompleting when you didn't intend would
> be bad.
Only do this if you press CTRL+space, eg. invoke the autocompletion by hand (To use your words: "The user *does intend* to autocomplete"). There should be no problem.
Example: class foo { void fooBarBaz();};
foo f; f.fooBar| <- now CTRL+space and the Baz appears immediately without an extra box, because there is only one entry and the developer very probably knows what he is doing/wants.
In other words: I think it is a good idea :)
Well, when you go being reasonable like that... I'll reopen, but this isn't going to happen for awhile because KTE doesn't make it easy to implement this. Thanks Dominik. An additional (and very good idea IMHO :) ) would be to hint that there is only one available completion. I've seen it done with tooltips in a windows IDE. E.g. you type your foo.doVeryIn and a tooltip appears above the cursor showing foo.doVeryInterestingStuff. When I hit the completion key, the text in the tooltip is used. This feature was also used when writing method implementations. The header with the method signature was already there, then in a .cpp file write: void Foo::doSomething( and a tooltip appears with the complete parameter list. Pressing the completion key fills the whole parameter list in and closes the brace. @Adam Trea: hm, what about if ( entryList.size() == 1 && invokedOnDemand ) { /* complete immediately*/ m_activeEditor->insertText(m_ccLine, m_ccColumn, entryList[0].text); } else if (entryList.size()) { /* as it was before */ } so you do not have to go the CompletionBox-way at all. Still missing is the bool "invokedOnDemand" :) This could be a parameter of void completeText(); maybe. @Jörg Rüppel: only one wish/bug per bug report. This has in general nothing to do with the original bug report, so please open another one :) I even believe that showing tooltips is not possible right now (that right?). Doh! Of course, the completion box doesn't need to be shown at all in this case. I'll let you complete the feature since you've obviously got the idea... CVS commit by dhaumann: fix bug 60987: auto complete directly if only one available completion Reviewed by Adam Treat. BUG: 60987 M +27 -2 cppcodecompletion.cpp 1.163 M +7 -1 cppcodecompletion.h 1.55 M +1 -1 cppsupportpart.cpp 1.290 --- kdevelop/languages/cpp/cppcodecompletion.cpp #1.162:1.163 @@ -860,5 +860,5 @@ QStringList CppCodeCompletion::evaluateE } -void CppCodeCompletion::completeText( ) +void CppCodeCompletion::completeText( bool invokedOnDemand /*= false*/ ) { kdDebug( 9007 ) << "CppCodeCompletion::completeText()" << endl; @@ -1230,5 +1230,30 @@ void CppCodeCompletion::completeText( ) } - if ( entryList.size() ) + QStringList trueMatches; + + if ( invokedOnDemand ) + { + // find matching words + QValueList<KTextEditor::CompletionEntry>::Iterator it; + for ( it = entryList.begin(); it != entryList.end(); ++it ) + { + if ( (*it).text.startsWith( word :) ) + { + trueMatches << (*it).text; + + // if more than one entry matches, abort immediately + if ( trueMatches.size() > 1 ) + break; + } + } + } + + if ( invokedOnDemand && trueMatches.size() == 1 ) + { + // there is only one entry -> complete immediately + m_activeEditor->insertText( m_ccLine, m_ccColumn, + trueMatches[0].right( trueMatches[0].length() - word.length() ) ); + } + else if ( entryList.size() ) { entryList = unique( entryList ); --- kdevelop/languages/cpp/cppcodecompletion.h #1.54:1.55 @@ -74,5 +74,11 @@ public: public slots: - void completeText(); + /** + * @param invokedOnDemand if true and there is exactly one matching entry + * complete the match immediately without showing the completion box. + * This is only true, when the users invokes the completion himself + * (eg presses the completion shortcut CTRL+space) + */ + void completeText( bool invokedOnDemand = false ); private slots: --- kdevelop/languages/cpp/cppsupportpart.cpp #1.289:1.290 @@ -1014,5 +1014,5 @@ void CppSupportPart::slotCompleteText() if ( !m_pCompletion ) return ; - m_pCompletion->completeText(); + m_pCompletion->completeText( true ); } yay, thanks! |