refactor(airi-plugin-vscode): better code & fixed dependency bundling issue
This commit is contained in:
Vendored
+1
-2
@@ -35,8 +35,7 @@
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/plugins/airi-plugin-vscode/dist/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "npm: build - plugins/airi-plugin-vscode"
|
||||
]
|
||||
}
|
||||
],
|
||||
"compounds": [
|
||||
|
||||
@@ -66,12 +66,10 @@
|
||||
"publish": "tsx ./scripts/publish.ts",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"devDependencies": {
|
||||
"@guiiai/logg": "catalog:",
|
||||
"@moeru/std": "catalog:",
|
||||
"@proj-airi/server-sdk": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@proj-airi/server-sdk": "workspace:*",
|
||||
"@types/vscode": "^1.106.1",
|
||||
"tinyexec": "^1.0.2",
|
||||
"vscode-ext-gen": "^1.4.0"
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
import type { Events } from './types'
|
||||
|
||||
import { useLogger } from '@guiiai/logg'
|
||||
import { Client as ServerClient } from '@proj-airi/server-sdk'
|
||||
|
||||
/**
|
||||
* Airi Channel Server Client
|
||||
*/
|
||||
export class Client {
|
||||
private client: ServerClient<Events> | null = null
|
||||
|
||||
/**
|
||||
* Connect to Channel Server
|
||||
*/
|
||||
async connect(): Promise<boolean> {
|
||||
try {
|
||||
this.client = new ServerClient({ name: 'proj-airi:plugin-vscode' })
|
||||
|
||||
useLogger().log('Airi companion connected to Channel Server')
|
||||
return true
|
||||
}
|
||||
catch (error) {
|
||||
useLogger().errorWithError('Failed to connect to Airi Channel Server:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from Channel Server
|
||||
*/
|
||||
disconnect(): void {
|
||||
if (this.client) {
|
||||
this.client.close()
|
||||
this.client = null
|
||||
useLogger().log('Airi companion disconnected')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send event to Airi
|
||||
*/
|
||||
sendEvent(event: Events): void {
|
||||
if (!this.client) {
|
||||
useLogger().warn('Cannot send event: not connected to Airi Channel Server')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// Send event to Airi
|
||||
this.client.send({
|
||||
type: 'vscode:context',
|
||||
data: event,
|
||||
})
|
||||
|
||||
useLogger().log(`Sent event to Airi: ${event.type}`, event)
|
||||
}
|
||||
catch (error) {
|
||||
useLogger().errorWithError('Failed to send event to Airi:', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is connected to Channel Server
|
||||
*/
|
||||
isConnected(): boolean {
|
||||
return !!this.client
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import type { Events } from './types'
|
||||
|
||||
import { useLogger } from '@guiiai/logg'
|
||||
import { Client as ServerClient } from '@proj-airi/server-sdk'
|
||||
|
||||
export class Client {
|
||||
private client: ServerClient<Events> | null = null
|
||||
|
||||
async connect(): Promise<boolean> {
|
||||
try {
|
||||
this.client = new ServerClient<Events>({ name: 'proj-airi:plugin-vscode' })
|
||||
useLogger().log('AIRI connected to Server Channel')
|
||||
return true
|
||||
}
|
||||
catch (error) {
|
||||
useLogger().errorWithError('Failed to connect to AIRI Server Channel:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
disconnect(): void {
|
||||
if (this.client) {
|
||||
this.client.close()
|
||||
this.client = null
|
||||
useLogger().log('AIRI disconnected')
|
||||
}
|
||||
}
|
||||
|
||||
sendEvent(event: Events): void {
|
||||
if (!this.client) {
|
||||
useLogger().warn('Cannot send event: not connected to AIRI Server Channel')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
this.client.send({ type: 'vscode:context', data: event })
|
||||
|
||||
useLogger().log(`Sent event to AIRI: ${event.type}`, event)
|
||||
}
|
||||
catch (error) {
|
||||
useLogger().errorWithError('Failed to send event to AIRI:', error)
|
||||
}
|
||||
}
|
||||
|
||||
isConnected(): boolean {
|
||||
return !!this.client
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import type * as vscode from 'vscode'
|
||||
|
||||
import { initLogger, LoggerFormat, LoggerLevel, useLogger } from '@guiiai/logg'
|
||||
import { commands, window, workspace } from 'vscode'
|
||||
|
||||
import { Client } from './airi-client'
|
||||
import { Client } from './airi'
|
||||
import { ContextCollector } from './context-collector'
|
||||
|
||||
let client: Client
|
||||
@@ -17,8 +18,6 @@ let eventListeners: vscode.Disposable[] = []
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
initLogger(LoggerLevel.Debug, LoggerFormat.Pretty)
|
||||
|
||||
const { window, workspace, commands } = await import('vscode')
|
||||
|
||||
useLogger().log('AIRI is activating...')
|
||||
|
||||
// Get the configuration
|
||||
@@ -35,10 +34,10 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
if (isEnabled) {
|
||||
const connected = await client.connect()
|
||||
if (connected) {
|
||||
window.showInformationMessage('AIRI server channel connected!')
|
||||
window.showInformationMessage('AIRI Server Channel connected!')
|
||||
}
|
||||
else {
|
||||
window.showWarningMessage('AIRI server channel connection failed!')
|
||||
window.showWarningMessage('AIRI Server Channel connection failed!')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +59,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
commands.registerCommand('airi-vscode.status', () => {
|
||||
const status = isEnabled && client ? 'Connected' : 'Disconnected'
|
||||
window.showInformationMessage(`AIRI server channel status: ${status}.`)
|
||||
window.showInformationMessage(`AIRI Server Channel status: ${status}.`)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -78,8 +77,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
async function registerListeners(sendInterval: number) {
|
||||
unregisterListeners()
|
||||
|
||||
const { window, workspace } = await import('vscode')
|
||||
|
||||
// File save event
|
||||
eventListeners.push(
|
||||
workspace.onDidSaveTextDocument(async (document) => {
|
||||
@@ -136,7 +133,6 @@ function startMonitoring(interval: number) {
|
||||
if (!isEnabled)
|
||||
return
|
||||
|
||||
const { window } = await import('vscode')
|
||||
const editor = window.activeTextEditor
|
||||
if (!editor)
|
||||
return
|
||||
|
||||
Generated
+10
-5
@@ -1959,7 +1959,7 @@ importers:
|
||||
version: 3.1.8(typescript@5.9.3)
|
||||
|
||||
plugins/airi-plugin-vscode:
|
||||
dependencies:
|
||||
devDependencies:
|
||||
'@guiiai/logg':
|
||||
specifier: 'catalog:'
|
||||
version: 1.1.0
|
||||
@@ -1969,7 +1969,6 @@ importers:
|
||||
'@proj-airi/server-sdk':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/server-sdk
|
||||
devDependencies:
|
||||
'@types/vscode':
|
||||
specifier: ^1.106.1
|
||||
version: 1.106.1
|
||||
@@ -1991,7 +1990,7 @@ importers:
|
||||
version: 66.5.10
|
||||
'@wxt-dev/module-vue':
|
||||
specifier: ^1.0.3
|
||||
version: 1.0.3(vite@7.2.7(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))(wxt@0.20.11(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(rollup@4.53.3)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))
|
||||
version: 1.0.3(vite@8.0.0-beta.1(@types/node@24.10.2)(esbuild@0.25.12)(jiti@2.6.1)(less@4.4.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))(wxt@0.20.11(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(rollup@4.53.3)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))
|
||||
vue-tsc:
|
||||
specifier: ^3.1.8
|
||||
version: 3.1.8(typescript@5.9.3)
|
||||
@@ -22527,6 +22526,12 @@ snapshots:
|
||||
vite: 7.2.7(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)
|
||||
vue: 3.5.25(typescript@5.9.3)
|
||||
|
||||
'@vitejs/plugin-vue@6.0.2(vite@8.0.0-beta.1(@types/node@24.10.2)(esbuild@0.25.12)(jiti@2.6.1)(less@4.4.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))':
|
||||
dependencies:
|
||||
'@rolldown/pluginutils': 1.0.0-beta.50
|
||||
vite: 8.0.0-beta.1(@types/node@24.10.2)(esbuild@0.25.12)(jiti@2.6.1)(less@4.4.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)
|
||||
vue: 3.5.25(typescript@5.9.3)
|
||||
|
||||
'@vitest/coverage-v8@4.0.15(vitest@4.0.15(@opentelemetry/api@1.9.0)(@types/node@24.10.2)(jiti@2.6.1)(jsdom@25.0.1(bufferutil@4.0.9)(utf-8-validate@5.0.10))(less@4.4.2)(lightningcss@1.30.2)(msw@2.7.3(@types/node@24.10.2)(typescript@5.9.3))(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))':
|
||||
dependencies:
|
||||
'@bcoe/v8-coverage': 1.0.2
|
||||
@@ -23385,9 +23390,9 @@ snapshots:
|
||||
'@types/filesystem': 0.0.36
|
||||
'@types/har-format': 1.2.16
|
||||
|
||||
'@wxt-dev/module-vue@1.0.3(vite@7.2.7(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))(wxt@0.20.11(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(rollup@4.53.3)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))':
|
||||
'@wxt-dev/module-vue@1.0.3(vite@8.0.0-beta.1(@types/node@24.10.2)(esbuild@0.25.12)(jiti@2.6.1)(less@4.4.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))(wxt@0.20.11(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(rollup@4.53.3)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))':
|
||||
dependencies:
|
||||
'@vitejs/plugin-vue': 6.0.2(vite@7.2.7(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))
|
||||
'@vitejs/plugin-vue': 6.0.2(vite@8.0.0-beta.1(@types/node@24.10.2)(esbuild@0.25.12)(jiti@2.6.1)(less@4.4.2)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2))(vue@3.5.25(typescript@5.9.3))
|
||||
wxt: 0.20.11(@types/node@24.10.2)(jiti@2.6.1)(less@4.4.2)(lightningcss@1.30.2)(rollup@4.53.3)(terser@5.44.1)(tsx@4.21.0)(yaml@2.8.2)
|
||||
transitivePeerDependencies:
|
||||
- vite
|
||||
|
||||
Reference in New Issue
Block a user