mirror of
https://github.com/kunkunsh/kunkun-ext-zed.git
synced 2025-04-03 17:56:46 +00:00
init with a zed sqlite parsing POC
This commit is contained in:
commit
bb0cab9d2b
177
.gitignore
vendored
Normal file
177
.gitignore
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Caches
|
||||
|
||||
.cache
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Runtime data
|
||||
|
||||
pids
|
||||
_.pid
|
||||
_.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
extensions_support/
|
||||
|
57
CHANGELOG.md
Normal file
57
CHANGELOG.md
Normal file
@ -0,0 +1,57 @@
|
||||
# template-ext-worker
|
||||
|
||||
## 0.0.10
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.1.5
|
||||
|
||||
## 0.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.1.4
|
||||
|
||||
## 0.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.1.2
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.1.1
|
||||
|
||||
## 0.0.6
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.1.0
|
||||
|
||||
## 0.0.5
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.0.53
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.0.48
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @kksh/api@0.0.47
|
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Kunkun Zed Extension
|
||||
|
||||
## Features
|
||||
|
||||
- Open recent zed projects
|
30
build.ts
Normal file
30
build.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { watch } from "fs"
|
||||
import { join } from "path"
|
||||
import { refreshTemplateWorkerCommand } from "@kksh/api/dev"
|
||||
import { $ } from "bun"
|
||||
|
||||
const entrypoints = ["./src/index.ts"]
|
||||
|
||||
async function build() {
|
||||
try {
|
||||
for (const entrypoint of entrypoints) {
|
||||
await $`bun build --minify --target=browser --outdir=./dist ${entrypoint}`
|
||||
}
|
||||
if (Bun.argv.includes("dev")) {
|
||||
await refreshTemplateWorkerCommand()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
const srcDir = join(import.meta.dir, "src")
|
||||
|
||||
await build()
|
||||
|
||||
if (Bun.argv.includes("dev")) {
|
||||
console.log(`Watching ${srcDir} for changes...`)
|
||||
watch(srcDir, { recursive: true }, async (event, filename) => {
|
||||
await build()
|
||||
})
|
||||
}
|
0
deno-src/index.ts
Normal file
0
deno-src/index.ts
Normal file
25
deno-src/main.ts
Normal file
25
deno-src/main.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { DatabaseSync } from "node:sqlite";
|
||||
import * as v from "@valibot/valibot";
|
||||
|
||||
const db = new DatabaseSync(
|
||||
"/Users/hk/Library/Application Support/Zed/db/0-stable/db.sqlite"
|
||||
);
|
||||
|
||||
const result = db
|
||||
.prepare("SELECT * FROM workspaces WHERE local_paths IS NOT NULL;")
|
||||
.all() as Array<{ local_paths: Uint8Array }>;
|
||||
|
||||
// Skip the first 16 bytes (8 bytes version + 8 bytes length) and decode only the path
|
||||
console.log(
|
||||
result.map((r) => new TextDecoder().decode(r.local_paths.slice(16)))
|
||||
);
|
||||
|
||||
// If you want to see the raw bytes for debugging
|
||||
// console.log("Raw bytes:");
|
||||
// console.log(
|
||||
// result.map((r) =>
|
||||
// Array.from(r.local_paths.slice(0, 16))
|
||||
// .map((b) => b.toString(16).padStart(2, "0"))
|
||||
// .join(" ")
|
||||
// )
|
||||
// );
|
9
deno.json
Normal file
9
deno.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"tasks": {
|
||||
"dev": "deno run --watch main.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@std/assert": "jsr:@std/assert@1",
|
||||
"@valibot/valibot": "jsr:@valibot/valibot@^0.42.1"
|
||||
}
|
||||
}
|
9
dev.ts
Normal file
9
dev.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import db from "/Users/hk/Library/Application Support/Zed/db/0-stable/db.sqlite" with { "type": "sqlite" };
|
||||
|
||||
const query = db.query("SELECT * FROM workspaces WHERE local_paths IS NOT NULL;");
|
||||
|
||||
for (const row of query) {
|
||||
console.log(row.local_paths);
|
||||
console.log(new TextDecoder().decode(row.local_paths));
|
||||
}
|
||||
|
48
package.json
Normal file
48
package.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"$schema": "https://schema.kunkun.sh",
|
||||
"name": "kunkun-ext-zed",
|
||||
"version": "0.0.10",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"kunkun": {
|
||||
"name": "TODO: Extension Display Name",
|
||||
"shortDescription": "A Worker Extension Template",
|
||||
"longDescription": "A Worker Extension Template",
|
||||
"identifier": "kunkun-ext-zed",
|
||||
"permissions": [
|
||||
"fetch:all",
|
||||
"clipboard:read-all"
|
||||
],
|
||||
"demoImages": [],
|
||||
"icon": {
|
||||
"type": "iconify",
|
||||
"value": "material-symbols:extension"
|
||||
},
|
||||
"customUiCmds": [],
|
||||
"templateUiCmds": [
|
||||
{
|
||||
"name": "TODO: Template Command Display Name",
|
||||
"main": "dist/index.js",
|
||||
"cmds": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "bun build.ts dev",
|
||||
"build": "bun build.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@kksh/api": "0.1.5",
|
||||
"i18next": "^23.15.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"files": [
|
||||
"./dist",
|
||||
".gitignore"
|
||||
]
|
||||
}
|
5
src/i18n/en.ts
Normal file
5
src/i18n/en.ts
Normal file
@ -0,0 +1,5 @@
|
||||
const en = {
|
||||
welcome: "Welcome to Kunkun"
|
||||
}
|
||||
export default en
|
||||
export type Translation = typeof en
|
20
src/i18n/index.ts
Normal file
20
src/i18n/index.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import i18next from "i18next"
|
||||
import en, { type Translation } from "./en"
|
||||
import zh from "./zh"
|
||||
|
||||
export function setupI18n(language: "en" | "zh" = "en") {
|
||||
i18next.init({
|
||||
resources: {
|
||||
en: {
|
||||
translation: en
|
||||
},
|
||||
zh: {
|
||||
translation: zh
|
||||
}
|
||||
},
|
||||
lng: language, // default language
|
||||
fallbackLng: "en"
|
||||
})
|
||||
}
|
||||
|
||||
export const t = (key: keyof Translation, options?: any) => i18next.t(key, options)
|
5
src/i18n/zh.ts
Normal file
5
src/i18n/zh.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import type { Translation } from "./en"
|
||||
|
||||
export default {
|
||||
welcome: "欢迎来到Kunkun"
|
||||
} satisfies Translation
|
125
src/index.ts
Normal file
125
src/index.ts
Normal file
@ -0,0 +1,125 @@
|
||||
import {
|
||||
Action,
|
||||
app,
|
||||
expose,
|
||||
Form,
|
||||
fs,
|
||||
Icon,
|
||||
IconEnum,
|
||||
List,
|
||||
path,
|
||||
shell,
|
||||
TemplateUiCommand,
|
||||
toast,
|
||||
ui
|
||||
} from "@kksh/api/ui/template"
|
||||
|
||||
class ExtensionTemplate extends TemplateUiCommand {
|
||||
async onFormSubmit(value: Record<string, any>): Promise<void> {
|
||||
console.log("Form submitted", value)
|
||||
toast.success(`Form submitted: ${JSON.stringify(value)}`)
|
||||
}
|
||||
async load() {
|
||||
// setupI18n(await app.language())
|
||||
// console.log(t("welcome"))
|
||||
|
||||
return ui.setSearchBarPlaceholder("Enter a search term, and press enter to search").then(() => {
|
||||
return ui.render(
|
||||
new List.List({
|
||||
sections: [
|
||||
new List.Section({
|
||||
title: "Section 1",
|
||||
items: [
|
||||
new List.Item({
|
||||
title: "Hello, World!",
|
||||
value: "Section 1 Hello, World!",
|
||||
icon: new Icon({ type: IconEnum.Iconify, value: "gg:hello" })
|
||||
}),
|
||||
new List.Item({ title: "Hello, World 2!", value: "Section 1 Hello, World 2!" })
|
||||
]
|
||||
}),
|
||||
new List.Section({
|
||||
title: "Section 2",
|
||||
items: [
|
||||
new List.Item({
|
||||
title: "Hello, World!",
|
||||
value: "Section 2 Hello, World!",
|
||||
icon: new Icon({ type: IconEnum.Iconify, value: "gg:hello" })
|
||||
}),
|
||||
new List.Item({ title: "Hello, World 2!", value: "Section 2 Hello, World 2!" })
|
||||
]
|
||||
})
|
||||
],
|
||||
items: [
|
||||
new List.Item({
|
||||
title: "Hello, World!",
|
||||
value: "Hello, World!",
|
||||
icon: new Icon({ type: IconEnum.Iconify, value: "ri:star-s-fill" })
|
||||
}),
|
||||
new List.Item({
|
||||
title: "Hello, World 2!",
|
||||
value: "Hello, World 2!",
|
||||
icon: new Icon({ type: IconEnum.Iconify, value: "gg:hello" }),
|
||||
actions: new Action.ActionPanel({
|
||||
items: [
|
||||
new Action.Action({
|
||||
title: "Open",
|
||||
icon: new Icon({ type: IconEnum.Iconify, value: "ion:open-outline" }),
|
||||
value: "open"
|
||||
})
|
||||
]
|
||||
})
|
||||
})
|
||||
]
|
||||
})
|
||||
)
|
||||
})
|
||||
return ui.render(
|
||||
new Form.Form({
|
||||
key: "form1",
|
||||
fields: [
|
||||
new Form.NumberField({
|
||||
key: "age",
|
||||
label: "Age",
|
||||
placeholder: "Enter your age"
|
||||
})
|
||||
// new Form.NumberField({
|
||||
// key: "age"
|
||||
// }),
|
||||
// new Form.Form({
|
||||
// key: "random",
|
||||
// fields: [
|
||||
// new Form.BooleanField({ key: "Server On" }),
|
||||
// new Form.ArrayField({
|
||||
// key: "birthday",
|
||||
// content: new Form.DateField({ key: "birthday" })
|
||||
// })
|
||||
// ]
|
||||
// })
|
||||
]
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async onActionSelected(actionValue: string): Promise<void> {
|
||||
switch (actionValue) {
|
||||
case "open":
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
onSearchTermChange(term: string): Promise<void> {
|
||||
console.log("Search term changed to:", term)
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
onListItemSelected(value: string): Promise<void> {
|
||||
console.log("Item selected:", value)
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
expose(new ExtensionTemplate())
|
27
tsconfig.json
Normal file
27
tsconfig.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": [
|
||||
"ESNext",
|
||||
"DOM"
|
||||
],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": false,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user