Custom range for CodeCompletion

Niko Sams niko.sams at gmail.com
Mon Nov 24 19:11:54 UTC 2008


On Mon, Nov 24, 2008 at 12:22 PM, David Nolden <zwabel at googlemail.com> wrote:
> Hi! Good work, really. I was a bit worried about performance, but that
> shouldn't be a problem with your implementation. There's just one thing I
> don't understand: How to actually modify the completion-range or allowed text
> regexp, they're both const &  :-)
The signal is emitted by the CodeCompletionModel only when it needs a different
completion-range. This would usually happen in codeCompletionInvoked.

see this example:
void CodeCompletionModel::completionInvokedInternal(KTextEditor::View*
view, const KTextEditor::Range& range, InvocationType invocationType,
const KUrl& url)
{
  if (range.start().column() > 0) {
    KTextEditor::Range preRange(Cursor(range.start().line(),
range.start().column()-1),
                                Cursor(range.start().line(),
range.start().column()));
    kDebug() << view->document()->text(preRange);
    if (view->document()->text(preRange) == "$") {
      range.expandToRange(preRange);
      kDebug() << "setting new completion range" << range;
      emit modifyCompletionRange(range, QRegExp("^\\$(\\w*)"));
    }
  }

Do you think you way of emitting the signal is better - then I will change it.


> I'm also a bit worried about regressions, since this touched quite fragile
> code. So it needs thorough testing.
I wrote some simple unit-tests for the new code. Not included in the patch as
I don't know yet how to the linking correctly.

Niko




More information about the KDevelop-devel mailing list