Clang CodeCompletion: No auto-completion for numbers
ClosedPublic

Authored by thomassc on Jan 2 2019, 12:27 PM.

Details

Summary

When typing a number, code-completion is undesirable in my opinion, since most likely no completion item applies and it only distracts, obstructs the view, or is triggered accidentally. Thus, this patch prevents code completion from automatically getting triggered for numbers. It does not cover all cases (code completion will still show something for floating-point numbers that start with a dot, such as .1f) but should cover the most common cases. Manual completion with Ctrl+Space is still possible.

Test Plan

Tested manually.

Diff Detail

Repository
R32 KDevelop
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
thomassc created this revision.Jan 2 2019, 12:27 PM
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptJan 2 2019, 12:27 PM
thomassc requested review of this revision.Jan 2 2019, 12:27 PM
brauch added a subscriber: brauch.Jan 2 2019, 1:18 PM

Hmm, maybe the better way to achieve this effect would be to disable *automatic* invocation of completion after numbers? I already noticed that this is mostly undesirable, too. This is probably something you don't want to fix in the Clang plugin, but in KTextEditor instead ...

As far as I can tell, the changed function is indeed responsible to determine whether to do *automatic* invocation of KDevelop's completion. Manual invocation by the user is still possible by pressing Ctrl+Space. The automatic word completion by KTextEditor, on the other hand, still works for numbers after this change. But it is far less intrusive since it only shows up after typing a few digits and if there are matching other numbers in the same file. So the probability that it offers useful completions is likely much higher, and I'd personally leave that one as it is.

mwolff added a subscriber: mwolff.Jan 10 2019, 2:39 PM

Hm I agree that this is better than the status quo, and also think it's the right place to do it. But what about completion after typing "foo1" ? Then we still want to show completion. The only case when we don't want to do it, if the word at the cursor is a number. So can you change that code to do that maybe?

E.g. something like if (... || view->document()->wordAt(position).value(0).isDigit()) return false; ?

mwolff requested changes to this revision.Jan 10 2019, 2:39 PM
This revision now requires changes to proceed.Jan 10 2019, 2:39 PM

You are right, this should be changed. I was under the wrong impression that the original diff worked since it still showed the completion when typing something like "foo1" from the beginning. But actually, if "foo" is already there before and one starts typing at "1", then it failed.

thomassc updated this revision to Diff 49338.Jan 12 2019, 4:04 PM

Update according to Milian's comment

mwolff accepted this revision.Jan 13 2019, 1:20 PM

I prefer to use AAA, but otherwise lgtm. do you have commit rights, or do you want me to submit this for you?

plugins/clang/codecompletion/model.cpp
198

const auto

This revision is now accepted and ready to land.Jan 13 2019, 1:20 PM
thomassc updated this revision to Diff 49394.Jan 13 2019, 4:05 PM

QString --> const auto

thomassc marked an inline comment as done.Jan 13 2019, 4:06 PM

I don't think that I have commit rights. Feel free to commit.

thomassc updated this revision to Diff 49395.Jan 13 2019, 4:07 PM

QString --> const auto (for real)

This revision was automatically updated to reflect the committed changes.