Skip to content
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
4 changes: 2 additions & 2 deletions packages/gunshi/src/plugin/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('plugin function', () => {

expect(simplePlugin.id).toBe('simple-plugin')
expect(simplePlugin.name).toBe('simple-plugin')
expect(simplePlugin.extension).toBeUndefined()
expect(simplePlugin.extension).toBeDefined()

// check that setup function is callable
const decorators = createDecorators()
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('plugin function', () => {
})
}
})
expect(testPlugin.extension).toBeUndefined()
expect(testPlugin.extension).toBeDefined()
})
})

Expand Down
8 changes: 7 additions & 1 deletion packages/gunshi/src/plugin/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import type {
} from '../types.ts'
import type { PluginContext } from './context.ts'

const NOOP_EXTENSION = () => {
return Object.create(null)
}

/**
* Plugin dependency definition
* @since v0.27.0
Expand Down Expand Up @@ -163,6 +167,7 @@ export function plugin(options: {
name?: string
dependencies?: (PluginDependency | string)[]
setup?: (ctx: Readonly<PluginContext<DefaultGunshiParams>>) => Awaitable<void>
onExtension?: OnPluginExtension<DefaultGunshiParams>
}): PluginWithoutExtension<DefaultGunshiParams['extensions']>

/**
Expand All @@ -184,7 +189,8 @@ export function plugin<
extension?: PluginExtension<E, DefaultGunshiParams>
onExtension?: OnPluginExtension<{ args: Args; extensions: { [K in I]?: E } }>
}): PluginWithExtension<E> | PluginWithoutExtension<DefaultGunshiParams['extensions']> {
const { id, name, setup, extension, onExtension, dependencies } = options
const { id, name, setup, onExtension, dependencies } = options
const extension = options.extension || (NOOP_EXTENSION as PluginExtension<E, DefaultGunshiParams>)

// create a wrapper function with properties
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
21 changes: 9 additions & 12 deletions packages/plugin-completion/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import { pluginId } from './types.ts'
import { quoteExec } from './utils.ts'

import type { Handler } from '@bombsh/tab'
import type { Args, Command, LazyCommand, PluginContext, PluginWithExtension } from '@gunshi/plugin'
import type { CompletionCommandContext, CompletionConfig, CompletionOptions } from './types.ts'
import type {
Args,
Command,
LazyCommand,
PluginContext,
PluginWithoutExtension
} from '@gunshi/plugin'
import type { CompletionConfig, CompletionOptions } from './types.ts'

export * from './types.ts'

Expand All @@ -27,9 +33,7 @@ const NOOP_HANDLER: Handler = () => {
/**
* completion plugin for gunshi
*/
export default function completion(
options: CompletionOptions = {}
): PluginWithExtension<CompletionCommandContext> {
export default function completion(options: CompletionOptions = {}): PluginWithoutExtension {
const config = options.config || {}
const completion = new Completion()

Expand Down Expand Up @@ -76,18 +80,11 @@ export default function completion(
ctx.decorateHeaderRenderer(async (_baseRenderer, _cmdCtx) => '')
},

// TODO(kazupon): type inference with plugin function type parameter
extension: (_ctx, _cmd): CompletionCommandContext => {
return {} as CompletionCommandContext
},

/**
* setup bombshell completion with `onExtension` hook
*/

onExtension: async (ctx, _cmd) => {
// TODO(kazupon): type inference with plugin function type parameter, more improvements!

// NOTE(kazupon): we should use plugin-i18n for completion localization, but it is not ready yet.
// const extensions = ctx.extensions as unknown as { [i18nPluginId]: I18nCommandContext }
// const i18n = extensions[i18nPluginId]
Expand Down