4

All,

I'm using QScintilla to syntax-highlight and autocomplete my domain specific language (DSL).

I wrote a custom lexer by re-implementing (QsciLexerCustom) and I'm trying to use the auto-completion. My problem is that the auto-completion doesn't work like I want. I'd like my custom lexer to work like the QsciLexerPython. That is, if i add 'toto.titi.tata' to the api, when i type 'toto.' in my qscintilla editor, it suggests me 'titi.tata'. As of now, it is suggesting me toto.titi.tata. :(

I tried to add 'autoCompletionWordSeparators' to my lexer but it is not working. How can i make my custom lexer auto-complete work like the QsciLexerPython? Thanks a lot !

Lexer = customlexer(self.text)
api = QsciAPIs(Lexer)
api.add('toto.titi.tata')
api.prepare()
Lexer.setAPIs(api)
self.text.setLexer(Lexer)

class lexer(QsciLexerCustom):
    def __init__(self, parent):
        QsciLexerCustom.__init__(self, parent)

    def autoCompletionWordSeparators(self):
        return ['.']
  • This doesn't answer the question, but I have implemented autocomplete for a custom lexer in QScintilla, but I had to also create a custom parser to find classes and function definitions in the code. Using SendScintilla(), you can easily use the low-level Scintilla api calls through QScintilla to show the autocomplete box, however filling it up requires that custom parser. – user0934 May 24 '16 at 17:29
  • This might also help: http://qscintilla.com/ – K.Mulier Jan 24 '17 at 21:50

1 Answers1

2

The current QScintilla APIs provide no way to do this.

The main obstacle is that many of the virtual methods you need to reimplement in a QsciLexerCustom subclass aren't public. This is why the code in your example doesn't work - your autoCompletionWordSeparators method is ignored when the lexer is set, and the base-class method from QsciLexer is called instead (which returns an empty list).

You might also think you could use QsciScintilla.setAutoCompletionWordSeparators to work around this, but alas, this only works if no lexer has been set!

The only way to solve this issue is to either implement auto-completion yourself (which is doable, but a lot of work), or make a feature request on the Qscintilla mailing list to get the necessary virtual methods added to the public API for QsciLexerCustom.

The methods in question are listed here (the names are shown in bold black, rather than as a link).

ekhumoro
  • 115,249
  • 20
  • 229
  • 336