Welcome to mirror list, hosted at ThFree Co, Russian Federation.

actions.js « store « code_navigation « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb6d30c775d4109f145f09698222ccf523937957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import api from '~/api';
import { __ } from '~/locale';
import createFlash from '~/flash';
import * as types from './mutation_types';
import { getCurrentHoverElement, setCurrentHoverElement, addInteractionClass } from '../utils';

export default {
  setInitialData({ commit }, data) {
    commit(types.SET_INITIAL_DATA, data);
  },
  requestDataError({ commit }) {
    commit(types.REQUEST_DATA_ERROR);
    createFlash(__('An error occurred loading code navigation'));
  },
  fetchData({ commit, dispatch, state }) {
    commit(types.REQUEST_DATA);

    api
      .lsifData(state.projectPath, state.commitId, state.blobPath)
      .then(({ data }) => {
        const normalizedData = data.reduce((acc, d) => {
          if (d.hover) {
            acc[`${d.start_line}:${d.start_char}`] = d;
            addInteractionClass(d);
          }
          return acc;
        }, {});

        commit(types.REQUEST_DATA_SUCCESS, normalizedData);
      })
      .catch(() => dispatch('requestDataError'));
  },
  showDefinition({ commit, state }, { target: el }) {
    let definition;
    let position;

    if (!state.data) return;

    const isCurrentElementPopoverOpen = el.classList.contains('hll');

    if (getCurrentHoverElement()) {
      getCurrentHoverElement().classList.remove('hll');
    }

    if (el.classList.contains('js-code-navigation') && !isCurrentElementPopoverOpen) {
      const { lineIndex, charIndex } = el.dataset;

      position = {
        x: el.offsetLeft,
        y: el.offsetTop,
        height: el.offsetHeight,
      };
      definition = state.data[`${lineIndex}:${charIndex}`];

      el.classList.add('hll');

      setCurrentHoverElement(el);
    }

    commit(types.SET_CURRENT_DEFINITION, { definition, position });
  },
};