Skip to content

Commit 6a6f9e4

Browse files
committed
feat: add asAbsolutePath utility
1 parent 37e4f68 commit 6a6f9e4

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ComputedRef, MaybeRefOrGetter } from '@reactive-vscode/reactivity'
22
import { computed, toValue } from '@reactive-vscode/reactivity'
3-
import { extensionContext } from '../utils'
3+
import { asAbsolutePath } from '../utils/asAbsolutePath'
44

55
/**
66
* @category utilities
@@ -9,10 +9,5 @@ import { extensionContext } from '../utils'
99
export function useAbsolutePath(relativePath: MaybeRefOrGetter<string>, slient: true): ComputedRef<string | undefined>
1010
export function useAbsolutePath(relativePath: MaybeRefOrGetter<string>, slient?: false): ComputedRef<string>
1111
export function useAbsolutePath(relativePath: MaybeRefOrGetter<string>, slient = false) {
12-
return computed(() => {
13-
const extCtx = extensionContext.value
14-
if (!extCtx && !slient)
15-
throw new Error('Cannot get absolute path because the extension is not activated yet')
16-
return extCtx?.asAbsolutePath(toValue(relativePath))
17-
})
12+
return computed(() => asAbsolutePath(toValue(relativePath), slient))
1813
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { extensionContext } from '../utils'
2+
3+
/**
4+
* A shorthand for `vscode::ExtensionContext.asAbsolutePath`
5+
*/
6+
export function asAbsolutePath(relativePath: string, slient?: false): string
7+
export function asAbsolutePath(relativePath: string, slient?: boolean): string | undefined
8+
export function asAbsolutePath(relativePath: string, slient = false) {
9+
const extCtx = extensionContext.value
10+
if (!extCtx && !slient)
11+
throw new Error('Cannot get absolute path because the extension is not activated yet')
12+
return extCtx?.asAbsolutePath(relativePath)
13+
}

0 commit comments

Comments
 (0)