Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect open-in-editor host option #281

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/client/src/components/assets/AssetDetails.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script setup lang="ts">
import { useTimeAgo } from '@vueuse/core'
import type { AssetInfo, CodeSnippet, ImageMeta } from '@vue/devtools-core'
import { callViteServerAction, openInEditor, useDevToolsState } from '@vue/devtools-core'
import { callViteServerAction, useDevToolsState } from '@vue/devtools-core'
import { VueButton, VueIcon, VTooltip as vTooltip } from '@vue/devtools-ui'
import { openInEditor } from '../../composables/open-in-editor'
const props = defineProps<{
modelValue: AssetInfo
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/components/graph/GraphDrawer.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { VueButton, VueDrawer, showVueNotification } from '@vue/devtools-ui'
import { openInEditor, useDevToolsState } from '@vue/devtools-core'
import { useDevToolsState } from '@vue/devtools-core'
import { openInEditor } from '../../composables/open-in-editor'
defineProps<{
top?: HTMLElement
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/components/pages/RoutesTable.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script setup lang="ts">
import { VueBadge } from '@vue/devtools-ui'
import type { RouteRecordNormalized } from 'vue-router'
import { openInEditor, useDevToolsState } from '@vue/devtools-core'
import { useDevToolsState } from '@vue/devtools-core'
import { openInEditor } from '../../composables/open-in-editor'
const props = defineProps<{
pages: RouteRecordNormalized[]
Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/composables/open-in-editor.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
import { openInEditor as _openInEditor, callViteServerAction } from '@vue/devtools-core'

const getOpenInEditorHost = callViteServerAction<string>('get-open-in-editor-host')
export const vueInspectorDetected = ref(false)

export const openInEditor = async (file: string) => {
const openInEditorHost = await getOpenInEditorHost()
return openInEditorHost ? _openInEditor(file, openInEditorHost) : _openInEditor(file)
}
2 changes: 1 addition & 1 deletion packages/client/src/pages/components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
inspectComponentInspector as inspectComponentInspectorAction,
onInspectorStateUpdated,
onInspectorTreeUpdated,
openInEditor,
scrollToComponent as scrollToComponentAction,
toggleComponentInspector as toggleComponentInspectorAction,
updateInspectorTreeId,
Expand All @@ -19,6 +18,7 @@ import { parse } from '@vue/devtools-kit'

import { VueIcon, VueInput, VTooltip as vTooltip } from '@vue/devtools-ui'
import { Pane, Splitpanes } from 'splitpanes'
import { openInEditor } from '../composables/open-in-editor'

const inspectorId = 'components'
const bridge = useDevToolsBridge()
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/bridge-events/devtools-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const editInspectorState = defineDevToolsAction('devtools:edit-inspector-
devtools.api.editInspectorState(payload)
})

export const openInEditor = defineDevToolsAction('devtools:open-in-editor', (devtools, file: string) => {
devtools.api.openInEditor({ file })
export const openInEditor = defineDevToolsAction('devtools:open-in-editor', (devtools, file: string, baseUrl?: string) => {
devtools.api.openInEditor({ file, baseUrl })
})

export const getInspectorTree = defineDevToolsAction('devtools:inspector-tree', async (devtools, payload) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools-kit/src/core/open-in-editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { target } from '@vue/devtools-shared'
import { devtoolsState } from '../../state'

export interface OpenInEditorOptions {
baseUrl?: string
file?: string
line?: number
column?: number
}

export function openInEditor(options: OpenInEditorOptions = {}) {
const { file, line = 0, column = 0 } = options
const { file, baseUrl = window.location.origin, line = 0, column = 0 } = options
if (file) {
const baseUrl = window.location.origin
if (devtoolsState.vitePluginDetected) {
target.__VUE_INSPECTOR__.openInEditor(baseUrl, file, line, column)
}
Expand Down
5 changes: 4 additions & 1 deletion packages/vite/src/modules/get-config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { defineViteServerAction } from '@vue/devtools-core'
import type { ResolvedConfig } from 'vite'

export function getViteConfig(config: ResolvedConfig) {
export function getViteConfig(config: ResolvedConfig, pluginOptions) {
defineViteServerAction('get-vite-root', () => {
return config.root
})
defineViteServerAction('get-open-in-editor-host', () => {
return pluginOptions.openInEditorHost
})
}
2 changes: 1 addition & 1 deletion packages/vite/src/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function VitePluginVueDevTools(options?: VitePluginVueDevToolsOpt

// vite client <-> server messaging
initViteServerContext(server)
getViteConfig(config)
getViteConfig(config, pluginOptions)
setupGraphModule({
rpc: inspect.api.rpc,
server,
Expand Down
Loading