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.
Details
- Reviewers
mwolff - Group Reviewers
KDevelop - Commits
- R32:e86c5a7211db: Clang CodeCompletion: No auto-completion for numbers
Tested manually.
Diff Detail
- Repository
- R32 KDevelop
- Branch
- no_auto_completion_for_numbers (branched from master)
- Lint
No Linters Available - Unit
No Unit Test Coverage - Build Status
Buildable 7014 Build 7032: arc lint + arc unit
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.
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; ?
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.
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 |