Autocompletion across all opened files



  • N++ has autocomplete but it seems to be based on the content of the current file and the contents of the autoCompletion\LANG_TYPE.xml file for the given language of the current file. Writing in C++, I can think of times that autocompletion from all open files would be good - like a .cpp and .h file where I’m defining the function prototypes in the .h file and I’d like the names to autocomplete from the opened .cpp file.

    I haven’t looked at the N++ code base, but I’m assuming this is done with the Scintilla Autocompletion calls? I wonder if there is a way to augment the dynamic list via plugin? Has anyone thought of this too? Has anyone tried it?

    Cheers.



  • Afaik, you cannot modify the list npp uses on the fly but create your own list.
    I use this technique together with jedi for python.
    For C++ I ASSUME nppgtags might do what you want.



  • @Ekopalypse said in Autocompletion across all opened files:

    I use this technique together with jedi for python.

    Can you describe how you have Jedi integrated with N++ for autocompletion? I’m not familiar with Jedi so just did a quick search. Found npp_pyjedi, do you use that? Or is it custom with PythonScript?

    I already use TagLEET (modified) and TagsView (modified), but neither help autocomplete while typing, they just lookup tags already typed in the document.

    I see nppgtags has an autocomplete feature, but found the interface to TagLEET better to work with.

    Cheers.



  • @Michael-Vincent

    do you use that?

    No, the one I linked :-)

    Or is it custom with PythonScript?

    Yes, Jedi is a bunch of python modules which will be accessed
    by a python script plugin but for other languages it is the same I guess.
    There is a need to have an “external” process running which constantly parses
    your code and offers you the auto completion functionality.
    What I did is this

    def on_charadded(self, args):
        if self.is_python:
            c = args['ch']
    
            if c in ['.', ' ', '(']:
                pos = editor.getCurrentPos()
                if (editor.getCurLine().find('#') > -1 or
                    editor.getStyleAt(pos) in [3, 4, 6, 7]):
                    return
    
                source = editor.getText() + c
                line = editor.lineFromPosition(pos) + 1
                column = editor.getColumn(pos)
                script = jedi.Script(source, line, column, '')
    
                if c == '(':
                    self.show_calltip(script, pos)
                else:
                    if c == '.' and editor.callTipActive():
                        editor.callTipCancel()
                    self.autocomplete(script, pos)
    

    Whenever a charadded notification is sent I check if this is a python document and if it is
    act according to the added char. If it is a ( I call a calltip and in case it is a . I ask for completion.
    I could have done it for every single char but I don’t like to get a offer to autocomplete always.
    I mostly been interested in methods and attributes from classes etc…


Log in to reply