All files / src/server/routes workspace-analysis.ts

0% Statements 0/53
0% Branches 0/1
0% Functions 0/1
0% Lines 0/53

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                                                                                                                       
import type express from 'express'
import { window } from 'vscode'
import { WorkspaceAnalysisService } from '../../services/workspace-analysis-service'
import { logger } from '../../utils/logger-adapter'
 
let workspaceAnalysisService: WorkspaceAnalysisService | null = null
 
export function registerWorkspaceAnalysisRoutes(app: express.Express) {
  // 工作区分析接口
  app.post('/analyze-workspace', async (_req, res) => {
    try {
      logger.info('收到工作区分析请求')
 
      if (!workspaceAnalysisService) {
        const context = (globalThis as any).__dalidevExtensionContext
        if (!context) throw new Error('Extension context not available')
        workspaceAnalysisService = new WorkspaceAnalysisService(context)
      }
 
      const analysisResult = await workspaceAnalysisService.analyzeWorkspace()
      window.showInformationMessage('工作区分析完成')
      res.json({ success: true, message: '工作区分析完成', data: analysisResult })
    }
    catch (error) {
      logger.error('工作区分析失败:', error)
      res.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) })
    }
  })
 
  // 清理工作区分析缓存接口
  app.post('/clear-workspace-cache', async (_req, res) => {
    try {
      logger.info('收到清理工作区分析缓存请求')
      if (!workspaceAnalysisService) {
        const context = (globalThis as any).__dalidevExtensionContext
        if (!context) throw new Error('Extension context not available')
        workspaceAnalysisService = new WorkspaceAnalysisService(context)
      }
      await workspaceAnalysisService.clearCache()
      window.showInformationMessage('工作区分析缓存已清理')
      res.json({ success: true, message: '工作区分析缓存已清理' })
    }
    catch (error) {
      logger.error('清理工作区分析缓存失败:', error)
      res.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) })
    }
  })
 
  // 获取工作区分析缓存统计接口
  app.get('/workspace-cache-stats', async (_req, res) => {
    try {
      if (!workspaceAnalysisService) {
        const context = (globalThis as any).__dalidevExtensionContext
        if (!context) throw new Error('Extension context not available')
        workspaceAnalysisService = new WorkspaceAnalysisService(context)
      }
      const stats = workspaceAnalysisService.getCacheStats()
      res.json({ success: true, data: stats })
    }
    catch (error) {
      logger.error('获取工作区分析缓存统计失败:', error)
      res.status(500).json({ success: false, error: error instanceof Error ? error.message : String(error) })
    }
  })
}