<commit_before>// Inspiration : https://atom.io/packages/ide-haskell
// and https://atom.io/packages/ide-flow
// https://atom.io/packages/atom-typescript
import {Models} from "omnisharp-client";
import {CompositeDisposable, Observable, Disposable} from "rx";
import {Omni} from "../server/omni";
import {TooltipView} from "../views/tooltip-view";
const $ : JQueryStatic = require("jquery");
const escape = require("escape-html");

class TypeLookup implements IFeature {
    private disposable: Rx.CompositeDisposable;

    public activate() {
        /* tslint:disable:no-string-literal */
        this.disposable = new CompositeDisposable();
        this.disposable.add(Omni.switchActiveEditor((editor, cd) => {
            // subscribe for tooltips
            // inspiration : https://github.com/chaika2013/ide-haskell
            const editorView = $(atom.views.getView(editor));
            const tooltip = editor["__omniTooltip"] = new Tooltip(editorView, editor);
            cd.add(tooltip);

            cd.add(editor.onDidDestroy(() => {
                editor["__omniTooltip"] = null;
                cd.dispose();
            }));
        }));

        this.disposable.add(Omni.addTextEditorCommand("omnisharp-atom:type-lookup", () => {
            Omni.activeEditor.first().subscribe(editor => {
                const tooltip = <Tooltip>editor["__omniTooltip"];
                tooltip.showExpressionTypeOnCommand();
            });
        }));
        /* tslint:enable:no-string-literal */
    }

    public dispose() {
        this.disposable.dispose();
    }

    public required = false;
    public title = "Tooltip Lookup";
    public description = "Adds hover tooltips to the editor, also has a keybind";
}

class Tooltip implements Rx.Disposable {
    private exprTypeTooltip: TooltipView = null;
    private keydown: Rx.Observable<KeyboardEvent>;
    private keydownSubscription: Rx.IDisposable;
    private rawView: any;
    private disposable: Rx.CompositeDisposable;

    constructor(private editorView: JQuery, private editor: Atom.TextEditor) {
        this.rawView = editorView[0];

        const cd = this.disposable = new CompositeDisposable();

        const scroll = this.getFromShadowDom(editorView, ".scroll-view");
        if (!scroll[0]) return;

        // to debounce mousemove event"s firing for some reason on some machines
        let lastExprTypeBufferPt: any;

        const mousemove = Observable.fromEvent<MouseEvent>(scroll[0], "mousemove");
        const mouseout = Observable.fromEvent<MouseEvent>(scroll[0], "mouseout");
        this.keydown = Observable.fromEvent<KeyboardEvent>(scroll[0], "keydown");

        cd.add(mousemove.map(event => {
            const pixelPt = this.pixelPositionFromMouseEvent(editorView, event);
            const screenPt = editor.screenPositionForPixelPosition(pixelPt);
            const bufferPt = editor.bufferPositionForScreenPosition(screenPt);
            if (lastExprTypeBufferPt && lastExprTypeBufferPt.isEqual(bufferPt) && this.exprTypeTooltip)
                return null;

            lastExprTypeBufferPt = bufferPt;
            return { bufferPt, event };
        })
            .where(z => !!z)
            .tapOnNext(() => this.hideExpressionType())
            .debounce(200)
            .where(x => this.checkPosition(x.bufferPt))
            .tapOnNext(() => this.subcribeKeyDown())
            .subscribe(({bufferPt, event}) => {
                this.showExpressionTypeOnMouseOver(event, bufferPt);
            }));

        cd.add(mouseout.subscribe((e) => this.hideExpressionType()));
<commit_msg>Updated lookup to not take to much time when dealing with mouseover events, to avoids some lage with selecting text<commit_after>// Inspiration : https://atom.io/packages/ide-haskell
// and https://atom.io/packages/ide-flow
// https://atom.io/packages/atom-typescript
import {Models} from "omnisharp-client";
import {CompositeDisposable, Observable, Disposable, Scheduler} from "rx";
import {Omni} from "../server/omni";
import {TooltipView} from "../views/tooltip-view";
const $: JQueryStatic = require("jquery");
const escape = require("escape-html");

class TypeLookup implements IFeature {
    private disposable: Rx.CompositeDisposable;

    public activate() {
        /* tslint:disable:no-string-literal */
        this.disposable = new CompositeDisposable();
        this.disposable.add(Omni.switchActiveEditor((editor, cd) => {
            // subscribe for tooltips
            // inspiration : https://github.com/chaika2013/ide-haskell
            const editorView = $(atom.views.getView(editor));
            const tooltip = editor["__omniTooltip"] = new Tooltip(editorView, editor);
            cd.add(tooltip);

            cd.add(editor.onDidDestroy(() => {
                editor["__omniTooltip"] = null;
                cd.dispose();
            }));
        }));

        this.disposable.add(Omni.addTextEditorCommand("omnisharp-atom:type-lookup", () => {
            Omni.activeEditor.first().subscribe(editor => {
                const tooltip = <Tooltip>editor["__omniTooltip"];
                tooltip.showExpressionTypeOnCommand();
            });
        }));
        /* tslint:enable:no-string-literal */
    }

    public dispose() {
        this.disposable.dispose();
    }

    public required = false;
    public title = "Tooltip Lookup";
    public description = "Adds hover tooltips to the editor, also has a keybind";
}

class Tooltip implements Rx.Disposable {
    private exprTypeTooltip: TooltipView = null;
    private keydown: Rx.Observable<KeyboardEvent>;
    private keydownSubscription: Rx.IDisposable;
    private rawView: any;
    private disposable: Rx.CompositeDisposable;

    constructor(private editorView: JQuery, private editor: Atom.TextEditor) {
        this.rawView = editorView[0];

        const cd = this.disposable = new CompositeDisposable();

        const scroll = this.getFromShadowDom(editorView, ".scroll-view");
        if (!scroll[0]) return;

        // to debounce mousemove event"s firing for some reason on some machines
        let lastExprTypeBufferPt: any;

        const mousemove = Observable.fromEvent<MouseEvent>(scroll[0], "mousemove");
        const mouseout = Observable.fromEvent<MouseEvent>(scroll[0], "mouseout");
        this.keydown = Observable.fromEvent<KeyboardEvent>(scroll[0], "keydown");

        cd.add(mousemove
            .observeOn(Scheduler.async)
            .buffer(mousemove.throttle(400), () => Observable.timer(400))
            .map(events => {
                for (const event of events.reverse()) {
                    console.log(event);
                    const pixelPt = this.pixelPositionFromMouseEvent(editorView, event);
                    const screenPt = editor.screenPositionForPixelPosition(pixelPt);
                    const bufferPt = editor.bufferPositionForScreenPosition(screenPt);
                    if (lastExprTypeBufferPt && lastExprTypeBufferPt.isEqual(bufferPt) && this.exprTypeTooltip)
                        continue;

                    lastExprTypeBufferPt = bufferPt;
                    return { bufferPt, event };
                }
            })
            .where(z => !!z)
            .tapOnNext(() => this.hideExpressionType())
            .where(x => this.checkPosition(x.bufferPt))
            .tapOnNext(() => this.subcribeKeyDown())
            .subscribe(({bufferPt, event}) => {
                this.showExpressionTypeOnMouseOver(event, bufferPt);
            }));

        cd.add(mouseout.subscribe((e) => this.hideExpressionType()));

{'fraction_non_alphanumeric': 0.12321899736147757, 'fraction_numerical': 0.003562005277044855, 'mean_word_length': 2.5860927152317883, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 36, 'https://': 8, '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': '5249326', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2035, 'n_words': 418}