feat: enhance API and session management with Nacos and Redis integration
- Add Nacos registry for service registration and deregistration. - Implement Redis registry for session management with heartbeat and session claiming. - Improve completion service with session handling and request validation. - Enhance WebSocket handling for completion requests with JSON-RPC support. - Add tests for new registry implementations and completion manager functionalities. - Refactor existing code for better readability and maintainability.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
var ErrInvalidRequest = errors.New("invalid completion request")
|
||||
|
||||
// Request 是统一的补全请求模型。
|
||||
type Request struct {
|
||||
Language string `json:"language,omitempty"`
|
||||
SessionID string `json:"sessionId,omitempty"`
|
||||
@@ -18,6 +19,7 @@ type Request struct {
|
||||
Character int `json:"character"`
|
||||
}
|
||||
|
||||
// Item 对应一个补全候选项。
|
||||
type Item struct {
|
||||
Label string `json:"label"`
|
||||
Kind int `json:"kind,omitempty"`
|
||||
@@ -28,11 +30,13 @@ type Item struct {
|
||||
FilterText string `json:"filterText,omitempty"`
|
||||
}
|
||||
|
||||
// Response 是补全结果集合。
|
||||
type Response struct {
|
||||
Items []Item `json:"items"`
|
||||
IsIncomplete bool `json:"isIncomplete"`
|
||||
}
|
||||
|
||||
// Client 抽象 LSP 客户端所需的最小能力。
|
||||
type Client interface {
|
||||
DidOpen(ctx context.Context, uri, text string, version int) error
|
||||
DidChange(ctx context.Context, uri, text string, version int) error
|
||||
@@ -43,6 +47,7 @@ type documentState struct {
|
||||
version int
|
||||
}
|
||||
|
||||
// Service 负责文档生命周期同步(didOpen/didChange)与补全调用。
|
||||
type Service struct {
|
||||
client Client
|
||||
|
||||
@@ -57,6 +62,7 @@ func NewService(client Client) *Service {
|
||||
}
|
||||
}
|
||||
|
||||
// Complete 根据 URI 的历史状态决定发送 didOpen 或 didChange,再请求补全。
|
||||
func (s *Service) Complete(ctx context.Context, req Request) (Response, error) {
|
||||
if err := validateRequest(req); err != nil {
|
||||
return Response{}, err
|
||||
@@ -86,6 +92,7 @@ func (s *Service) Complete(ctx context.Context, req Request) (Response, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// validateRequest 做基础参数校验,避免向 LSP 发送非法请求。
|
||||
func validateRequest(req Request) error {
|
||||
if req.URI == "" {
|
||||
return ErrInvalidRequest
|
||||
|
||||
Reference in New Issue
Block a user