fix: 修复若干问题,添加java lsp
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
"monica-go-completion-backend/internal/completion"
|
||||
"monica-go-completion-backend/internal/logging"
|
||||
"monica-go-completion-backend/internal/lsp"
|
||||
"monica-go-completion-backend/internal/monitor"
|
||||
)
|
||||
|
||||
var requestIDSeed atomic.Int64
|
||||
@@ -235,14 +236,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
manager := completion.NewManager(completion.ManagerConfig{
|
||||
WorkspaceDir: cfg.WorkspaceDir,
|
||||
MaxSessions: cfg.MaxSessions,
|
||||
SessionTTL: cfg.SessionTTL,
|
||||
CleanupInterval: cfg.CleanupInterval,
|
||||
InstanceID: cfg.InstanceID,
|
||||
Registry: registry,
|
||||
}, cfg.Servers, func(ctx context.Context, spec completion.LanguageServerSpec, workspaceDir string) (completion.RuntimeClient, error) {
|
||||
clientFactory := func(ctx context.Context, spec completion.LanguageServerSpec, workspaceDir string) (completion.RuntimeClient, error) {
|
||||
return lsp.NewClient(ctx, lsp.Config{
|
||||
Command: spec.Command,
|
||||
Args: spec.Args,
|
||||
@@ -250,11 +244,31 @@ func main() {
|
||||
LanguageID: spec.LanguageID,
|
||||
ClientName: "monica-lsp-gateway",
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
manager := completion.NewManager(completion.ManagerConfig{
|
||||
WorkspaceDir: cfg.WorkspaceDir,
|
||||
MaxSessions: cfg.MaxSessions,
|
||||
SessionTTL: cfg.SessionTTL,
|
||||
CleanupInterval: cfg.CleanupInterval,
|
||||
InstanceID: cfg.InstanceID,
|
||||
Registry: registry,
|
||||
}, cfg.Servers, clientFactory)
|
||||
defer func() {
|
||||
_ = manager.Close()
|
||||
}()
|
||||
|
||||
// 后台预热各语言 LSP 会话,首次请求无需等待冷启动。
|
||||
go manager.WarmUp(context.Background())
|
||||
|
||||
// 后台探测各语言 LSP 可用性(demo 实现:周期性握手探测)。
|
||||
lspStatusMonitor := monitor.NewLSPStatusMonitor(cfg.Servers, cfg.WorkspaceDir, clientFactory, monitor.Config{
|
||||
ProbeInterval: 60 * time.Second,
|
||||
ProbeTimeout: 30 * time.Second,
|
||||
FailureThreshold: 2,
|
||||
})
|
||||
defer lspStatusMonitor.Close()
|
||||
|
||||
// 注册通用中间件与业务路由。
|
||||
router := gin.New()
|
||||
if err := configureProxySettings(router, cfg); err != nil {
|
||||
@@ -267,8 +281,9 @@ func main() {
|
||||
router.Use(apiTokenMiddleware(cfg.APIToken))
|
||||
|
||||
api.RegisterRoutes(router, manager, api.RouteOptions{
|
||||
RequestTimeout: cfg.RequestTimeout,
|
||||
MaxBodyBytes: cfg.MaxBodyBytes,
|
||||
RequestTimeout: cfg.RequestTimeout,
|
||||
MaxBodyBytes: cfg.MaxBodyBytes,
|
||||
LSPStatusProvider: lspStatusMonitor,
|
||||
})
|
||||
|
||||
server := &http.Server{
|
||||
|
||||
Reference in New Issue
Block a user