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:
2026-02-15 17:46:34 +08:00
parent 57afb90bc0
commit 3284ce07c7
22 changed files with 1863 additions and 87 deletions

View File

@@ -19,6 +19,28 @@ go run ./cmd/server
默认地址:`http://127.0.0.1:8080`
## 配置文件(推荐)
后端现在支持 JSON 配置文件:
1. 复制 `config.example.json``config.json`
2. 修改你需要的字段
3. 启动服务(会自动读取当前目录 `config.json`
```bash
cp config.example.json config.json
go run ./cmd/server
```
也可以显式指定路径:
```bash
CONFIG_FILE=./config.local.json go run ./cmd/server
```
优先级为:`默认值 < 配置文件 < 环境变量`
也就是说你可以把大部分配置放在文件里,临时参数再用环境变量覆盖。
## 企业化配置(环境变量)
- `PORT`:默认 `8080`
@@ -39,6 +61,17 @@ go run ./cmd/server
- `INSTANCE_URL`:实例可回源地址(用于路由提示),默认 `http://127.0.0.1:${PORT}`
- `INSTANCE_TTL`:实例注册 TTL默认 `30s`
- `INSTANCE_HEARTBEAT_INTERVAL`:实例心跳周期,默认 `10s`
- `ENABLE_NACOS_REGISTER`:是否启用 Nacos SDK 注册,默认 `false`
- `NACOS_SERVER_ADDR`Nacos 地址,默认 `10.0.0.10:8848`
- `NACOS_NAMESPACE`Nacos namespace默认空public
- `NACOS_GROUP`Nacos group默认 `DEFAULT_GROUP`
- `NACOS_SERVICE_NAME`Nacos 服务名,默认 `lsp-gateway`
- `NACOS_CLUSTER_NAME`:可选 clusterName
- `NACOS_USERNAME`Nacos 用户名,可空
- `NACOS_PASSWORD`Nacos 密码,可空
- `NACOS_IP`:实例注册 IP建议注入 Pod/主机内网 IP
- `NACOS_PORT`:实例注册端口,默认取 `PORT`
- `NACOS_EPHEMERAL`:是否临时实例,默认 `true`
语言服务器命令(可替换为企业内部镜像/封装):
- `GO_LSP_COMMAND``GO_LSP_ARGS`
@@ -48,6 +81,19 @@ go run ./cmd/server
默认 JS/TS 命令:
- `typescript-language-server --stdio`
Nacos SDK 注册示例:
```bash
ENABLE_NACOS_REGISTER=true
NACOS_SERVER_ADDR=10.0.0.10:8848
NACOS_USERNAME=nacos
NACOS_PASSWORD=nacos
NACOS_SERVICE_NAME=lsp-gateway
NACOS_GROUP=DEFAULT_GROUP
NACOS_IP=10.0.2.15
NACOS_PORT=8080
```
## 健康检查
- `GET /health`