KSyntaxHighlighting: Expose context in highlighting functions
Open, Needs TriagePublic

Description

The KSyntaxHighlighting framework has a function called

virtual void applyFormat(int offset, int length, const Format &format) = 0;

This function is called for all characters of text that is passed into highlightLine(text, state).

What applyFormat() is missing is a context object that can be used to obtain more information about the internal state of the syntax highlighting engine, in particular we need to know in which context are we are at the current location.

For instance, this context info is needed to obtain the currently available keyword lists for context-sensitive keyword completion (which we had in KTextEditor, but lost with the KSyntaxHighlighting transition). I.e., we want to add back a function QStringList Definition::keywordLists(void* context) const; or similar.

For this task, there is also a comment in src/lib/abstracthighlighter.h:

// TODO KF6: add an optional void* context argument that is passed through
// to the applyX() calls, so highlighters dealing with some form of line object
// (such as QSyntaxHighlighter or KTextEditor) can avoid some ugly hacks to have
// this context available in their applyX methods
dhaumann created this task.Nov 24 2019, 5:41 PM
vkrause moved this task from Backlog to Waiting on KF6 Branching on the KF6 board.Nov 25 2019, 9:35 PM

I miss what should be in that context object. If it is just something that should be passed around, I think the current code e.g. in KTextEditor is nicer the working on a void *.