2020-02-06 12:10:29 +00:00
|
|
|
<script>
|
2020-07-15 18:09:09 +00:00
|
|
|
import { GlButton, GlTabs, GlTab, GlLink, GlBadge } from '@gitlab/ui';
|
2020-06-04 15:08:21 +00:00
|
|
|
import DocLine from './doc_line.vue';
|
2020-02-06 12:10:29 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-04-24 18:09:46 +00:00
|
|
|
GlButton,
|
2020-07-15 18:09:09 +00:00
|
|
|
GlTabs,
|
|
|
|
GlTab,
|
|
|
|
GlLink,
|
|
|
|
GlBadge,
|
2020-06-04 15:08:21 +00:00
|
|
|
DocLine,
|
2020-02-06 12:10:29 +00:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
position: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-03-24 18:07:55 +00:00
|
|
|
definitionPathPrefix: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-04-24 18:09:46 +00:00
|
|
|
blobPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-02-06 12:10:29 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
offsetLeft: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2020-07-13 12:09:18 +00:00
|
|
|
isCurrentDefinition() {
|
|
|
|
return this.data.definitionLineNumber - 1 === this.position.lineIndex;
|
|
|
|
},
|
2020-02-06 12:10:29 +00:00
|
|
|
positionStyles() {
|
|
|
|
return {
|
|
|
|
left: `${this.position.x - this.offsetLeft}px`,
|
|
|
|
top: `${this.position.y + this.position.height}px`,
|
|
|
|
};
|
|
|
|
},
|
2020-03-24 18:07:55 +00:00
|
|
|
definitionPath() {
|
2020-04-24 18:09:46 +00:00
|
|
|
if (!this.data.definition_path) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isDefinitionCurrentBlob) {
|
2020-07-13 12:09:18 +00:00
|
|
|
return `#L${this.data.definitionLineNumber}`;
|
2020-04-24 18:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return `${this.definitionPathPrefix}/${this.data.definition_path}`;
|
|
|
|
},
|
|
|
|
isDefinitionCurrentBlob() {
|
|
|
|
return this.data.definition_path.indexOf(this.blobPath) === 0;
|
2020-03-24 18:07:55 +00:00
|
|
|
},
|
2020-07-15 18:09:09 +00:00
|
|
|
references() {
|
|
|
|
return this.data.references || [];
|
|
|
|
},
|
2020-02-06 12:10:29 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
position: {
|
|
|
|
handler() {
|
|
|
|
this.$nextTick(() => this.updateOffsetLeft());
|
|
|
|
},
|
|
|
|
deep: true,
|
|
|
|
immediate: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateOffsetLeft() {
|
|
|
|
this.offsetLeft = Math.max(
|
|
|
|
0,
|
|
|
|
this.$el.offsetLeft + this.$el.offsetWidth - window.innerWidth + 20,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
colorScheme: gon?.user_color_scheme,
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
:style="positionStyles"
|
|
|
|
class="popover code-navigation-popover popover-font-size-normal gl-popover bs-popover-bottom show"
|
|
|
|
>
|
|
|
|
<div :style="{ left: `${offsetLeft}px` }" class="arrow"></div>
|
2020-07-15 18:09:09 +00:00
|
|
|
<gl-tabs nav-class="gl-hidden" content-class="gl-py-0">
|
|
|
|
<gl-tab :title="__('Definition')">
|
|
|
|
<div class="overflow-auto code-navigation-popover-container">
|
|
|
|
<div
|
|
|
|
v-for="(hover, index) in data.hover"
|
|
|
|
:key="index"
|
|
|
|
:class="{ 'border-bottom': index !== data.hover.length - 1 }"
|
|
|
|
>
|
|
|
|
<pre
|
|
|
|
v-if="hover.language"
|
|
|
|
ref="code-output"
|
|
|
|
:class="$options.colorScheme"
|
|
|
|
class="border-0 bg-transparent m-0 code highlight text-wrap"
|
|
|
|
><doc-line v-for="(tokens, tokenIndex) in hover.tokens" :key="tokenIndex" :language="hover.language" :tokens="tokens"/></pre>
|
|
|
|
<p v-else ref="doc-output" class="p-3 m-0">
|
|
|
|
{{ hover.value }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="definitionPath || isCurrentDefinition" class="popover-body border-top">
|
|
|
|
<span v-if="isCurrentDefinition" class="gl-font-weight-bold gl-font-base">
|
|
|
|
{{ s__('CodeIntelligence|This is the definition') }}
|
|
|
|
</span>
|
|
|
|
<gl-button
|
|
|
|
v-else
|
|
|
|
:href="definitionPath"
|
|
|
|
:target="isDefinitionCurrentBlob ? null : '_blank'"
|
|
|
|
class="w-100"
|
|
|
|
variant="default"
|
|
|
|
data-testid="go-to-definition-btn"
|
|
|
|
>
|
|
|
|
{{ __('Go to definition') }}
|
|
|
|
</gl-button>
|
|
|
|
</div>
|
|
|
|
</gl-tab>
|
|
|
|
<gl-tab data-testid="references-tab" class="py-2">
|
|
|
|
<template #title>
|
|
|
|
{{ __('References') }}
|
|
|
|
<gl-badge size="sm" class="gl-tab-counter-badge">{{ references.length }}</gl-badge>
|
|
|
|
</template>
|
|
|
|
<template v-if="references.length">
|
|
|
|
<div v-for="(reference, index) in references" :key="index" class="gl-dropdown-item">
|
|
|
|
<gl-link
|
|
|
|
:href="`${definitionPathPrefix}/${reference.path}`"
|
|
|
|
class="dropdown-item"
|
|
|
|
data-testid="reference-link"
|
|
|
|
>
|
|
|
|
{{ reference.path }}
|
|
|
|
</gl-link>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<p v-else class="gl-my-4 gl-px-4">
|
|
|
|
{{ s__('CodeNavigation|No references found') }}
|
2020-07-13 12:09:18 +00:00
|
|
|
</p>
|
2020-07-15 18:09:09 +00:00
|
|
|
</gl-tab>
|
|
|
|
</gl-tabs>
|
2020-02-06 12:10:29 +00:00
|
|
|
</div>
|
|
|
|
</template>
|