Skip to content

Format autocomplete in more modern way, without much effort #674

@lumnn

Description

@lumnn

I didn't like the fact it had a lot of text in an entry, which at the same time didn't give quick feedback to user about what the completion is about.

So I started playing around with code, to improve this, and I got to this point:
peek 2018-08-09 11-44

I wanted to create a pull request, but the changes are done to the version that's different from master. Also that's probably one of my first Python lines in my life.

Here I attach format_competions_by_language function:

def format_completions_by_language(cplns, language, text_in_current_line, trigger):
    function = None if 'import ' in text_in_current_line else 'function'
    
    def get_symbol(t):
        symbols = {
            'variable': '🅥',
            'constant': '🅓',
            'namespace': '🅝',
            'keyword': '🅚',
            'function': '🅕',
            'class': '🅒',
            'interface': '🅘',
        }
        
        if language == "PHP" and trigger and (trigger.name == "php-complete-object-members" or trigger.name == "php-complete-static-members"):
            symbols['variable'] = '🅟'
            symbols['function'] = '🅜'

        return symbols[t] if t in symbols else t

    def get_name(t, n):
        if t == 'variable' and language == 'PHP':
            return '$'+n
        elif t == 'function':
            return n+'(…)'

        return n

    return [('%s %s' % (get_symbol(t), get_name(t, n,)), (n).replace("$", "") + ('($0)' if t == function else '')) for t, n in cplns]

Feel free to use this code and I'll be happy if it gets implemented into master

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions