feat: include Type definitions in command palette's dynamic commands
extractVaultTypes now also reads entries where isA === 'Type' and adds their title, so "New <Type>" commands appear as soon as a Type is defined — not only after an instance of that type exists. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,12 @@ export function pluralizeType(type: string): string {
|
||||
export function extractVaultTypes(entries: VaultEntry[]): string[] {
|
||||
const typeSet = new Set<string>()
|
||||
for (const e of entries) {
|
||||
if (e.isA && e.isA !== 'Type' && !e.trashed) typeSet.add(e.isA)
|
||||
if (e.trashed) continue
|
||||
if (e.isA === 'Type' && e.title) {
|
||||
typeSet.add(e.title)
|
||||
} else if (e.isA && e.isA !== 'Type') {
|
||||
typeSet.add(e.isA)
|
||||
}
|
||||
}
|
||||
if (typeSet.size === 0) return DEFAULT_TYPES
|
||||
return Array.from(typeSet).sort()
|
||||
|
||||
@@ -192,6 +192,33 @@ describe('extractVaultTypes', () => {
|
||||
] as never[]
|
||||
expect(extractVaultTypes(entries)).toEqual(['Event', 'Person', 'Project', 'Note'])
|
||||
})
|
||||
|
||||
it('includes types from Type definition entries', () => {
|
||||
const entries = [
|
||||
{ path: '/book.md', title: 'Book', isA: 'Type', trashed: false },
|
||||
] as never[]
|
||||
const types = extractVaultTypes(entries)
|
||||
expect(types).toContain('Book')
|
||||
})
|
||||
|
||||
it('includes types from both definitions and instances', () => {
|
||||
const entries = [
|
||||
{ path: '/book.md', title: 'Book', isA: 'Type', trashed: false },
|
||||
{ path: '/hp.md', title: 'Harry Potter', isA: 'Book', trashed: false },
|
||||
{ path: '/person.md', title: 'Person', isA: 'Type', trashed: false },
|
||||
] as never[]
|
||||
const types = extractVaultTypes(entries)
|
||||
expect(types).toContain('Book')
|
||||
expect(types).toContain('Person')
|
||||
expect(types).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('excludes trashed Type definition entries', () => {
|
||||
const entries = [
|
||||
{ path: '/book.md', title: 'Book', isA: 'Type', trashed: true },
|
||||
] as never[]
|
||||
expect(extractVaultTypes(entries)).toEqual(['Event', 'Person', 'Project', 'Note'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('groupSortKey', () => {
|
||||
|
||||
Reference in New Issue
Block a user