<commit_before>import React from 'react';
import AutocompleteProvider from './AutocompleteProvider';
import Q from 'q';
import Fuse from 'fuse.js';
import {TextualCompletion} from './Components';

const USER_REGEX = /@[^\s]*/g;

let instance = null;

export default class UserProvider extends AutocompleteProvider {
    constructor() {
        super(USER_REGEX, {
            keys: ['displayName', 'userId'],
        });
        this.users = [];
        this.fuse = new Fuse([], {
            keys: ['displayName', 'userId'],
        });
    }

    getCompletions(query: string, selection: {start: number, end: number}) {
        let completions = [];
        let {command, range} = this.getCurrentCommand(query, selection);
        if (command) {
            this.fuse.set(this.users);
            completions = this.fuse.search(command[0]).map(user => {
                return {
                    completion: user.userId,
                    component: (
                        <TextualCompletion
                            title={user.displayName || user.userId}
                            description={user.userId} />
                    ),
                    range
                };
            }).slice(0, 4);
        }
        return Q.when(completions);
    }

    getName() {
        return 'Users';
    }
<commit_msg>strip (IRC) displayname suffix from autocomplete<commit_after>import React from 'react';
import AutocompleteProvider from './AutocompleteProvider';
import Q from 'q';
import Fuse from 'fuse.js';
import {TextualCompletion} from './Components';

const USER_REGEX = /@[^\s]*/g;

let instance = null;

export default class UserProvider extends AutocompleteProvider {
    constructor() {
        super(USER_REGEX, {
            keys: ['name', 'userId'],
        });
        this.users = [];
        this.fuse = new Fuse([], {
            keys: ['name', 'userId'],
        });
    }

    getCompletions(query: string, selection: {start: number, end: number}) {
        let completions = [];
        let {command, range} = this.getCurrentCommand(query, selection);
        if (command) {
            this.fuse.set(this.users);
            completions = this.fuse.search(command[0]).map(user => {
                const displayName = (user.name || user.userId || '').replace(' (IRC)', ''); // FIXME when groups are done
                return {
                    completion: user.userId,
                    component: (
                        <TextualCompletion
                            title={displayName}
                            description={user.userId} />
                    ),
                    range
                };
            }).slice(0, 4);
        }
        return Q.when(completions);
    }

    getName() {
        return 'Users';
    }

{'fraction_non_alphanumeric': 0.12970261554998208, 'fraction_numerical': 0.002149767108563239, 'mean_word_length': 1.6768935762224353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '500619', 'n_tokens_mistral': 750, 'n_tokens_neox': 730, 'n_words': 173}