<commit_before>import _ = require('lodash');
import {CompositeDisposable, Subject, Observable, Scheduler} from "rx";
import Omni = require('../../omni-sharp-server/omni')
import SpacePen = require('atom-space-pen-views');
import Changes = require('../services/apply-changes');
import codeActionsView from "../views/code-actions-view";

class CodeAction implements OmniSharp.IFeature {
    private disposable: Rx.CompositeDisposable;

    private view: SpacePen.SelectListView;

    public activate() {
        this.disposable = new CompositeDisposable();

        this.disposable.add(Omni.addTextEditorCommand("omnisharp-atom:get-code-actions", () => {
            //store the editor that this was triggered by.
            var editor = atom.workspace.getActiveTextEditor();
            Omni.request(editor, client => client.getcodeactions(this.getRequest(client)))
                .subscribe(response => {
                    //pop ui to user.
                    this.view = codeActionsView({
                        items: response.CodeActions,
                        confirmed: (item) => {
                            var range = editor.getSelectedBufferRange();
                            Omni.request(editor, client => client.runcodeaction(this.getRequest(client, item.Identifier)))
                                .subscribe((response) => this.applyAllChanges(response.Changes));
                        }
                    }, editor);
                });
        }));

        this.disposable.add(Omni.switchActiveEditor((editor, cd) => {
            var cd = new CompositeDisposable();
            cd.add(Omni.listener.observeGetcodeactions
                .where(z => z.request.FileName === editor.getPath())
                .where(ctx => ctx.response.CodeActions.length > 0)
                .subscribe(({response, request}) => {
                    if (marker) {
                        marker.destroy();
                        marker = null;
                    }

                    var range = [[request.Line, 0], [request.Line, 0]];
                    marker = editor.markBufferRange(range);
                    editor.decorateMarker(marker, { type: "line-number", class: "quickfix" });
                }));

            var word, marker: Atom.Marker, subscription: Rx.Disposable;<commit_msg>Added guard to code action editor call, fixes #499<commit_after>import _ = require('lodash');
import {CompositeDisposable, Subject, Observable, Scheduler} from "rx";
import Omni = require('../../omni-sharp-server/omni')
import SpacePen = require('atom-space-pen-views');
import Changes = require('../services/apply-changes');
import codeActionsView from "../views/code-actions-view";

class CodeAction implements OmniSharp.IFeature {
    private disposable: Rx.CompositeDisposable;

    private view: SpacePen.SelectListView;

    public activate() {
        this.disposable = new CompositeDisposable();

        this.disposable.add(Omni.addTextEditorCommand("omnisharp-atom:get-code-actions", () => {
            //store the editor that this was triggered by.
            var editor = atom.workspace.getActiveTextEditor();
            Omni.request(editor, client => client.getcodeactions(this.getRequest(client)))
                .subscribe(response => {
                    //pop ui to user.
                    this.view = codeActionsView({
                        items: response.CodeActions,
                        confirmed: (item) => {
                            if (editor && !editor.isDestroyed()) {
                                var range = editor.getSelectedBufferRange();
                                Omni.request(editor, client => client.runcodeaction(this.getRequest(client, item.Identifier)))
                                    .subscribe((response) => this.applyAllChanges(response.Changes));
                            }
                        }
                    }, editor);
                });
        }));

        this.disposable.add(Omni.switchActiveEditor((editor, cd) => {
            var cd = new CompositeDisposable();
            cd.add(Omni.listener.observeGetcodeactions
                .where(z => z.request.FileName === editor.getPath())
                .where(ctx => ctx.response.CodeActions.length > 0)
                .subscribe(({response, request}) => {
                    if (marker) {
                        marker.destroy();
                        marker = null;
                    }

                    var range = [[request.Line, 0], [request.Line, 0]];
                    marker = editor.markBufferRange(range);
                    editor.decorateMarker(marker, { type: "line-number", class: "quickfix" });
                }));

            var word, marker: Atom.Marker, subscription: Rx.Disposable;
{'fraction_non_alphanumeric': 0.12107247591118558, 'fraction_numerical': 0.0018852115626309175, 'mean_word_length': 1.7761627906976745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7475671', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1136, 'n_words': 234}