- 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.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package lsp
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeURIRebasesRelativeFileURI(t *testing.T) {
|
|
workspace, err := filepath.Abs(filepath.Join("testdata", "ws"))
|
|
if err != nil {
|
|
t.Fatalf("filepath.Abs() error = %v", err)
|
|
}
|
|
|
|
client := &Client{workspaceDir: workspace}
|
|
got, err := client.normalizeURI("file:///main.go")
|
|
if err != nil {
|
|
t.Fatalf("normalizeURI() error = %v", err)
|
|
}
|
|
|
|
want, err := pathToURI(filepath.Join(workspace, "main.go"))
|
|
if err != nil {
|
|
t.Fatalf("pathToURI() error = %v", err)
|
|
}
|
|
if got != want {
|
|
t.Fatalf("normalizeURI() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
// 绝对 file URI 不应被重写。
|
|
func TestNormalizeURIKeepsAbsoluteFileURI(t *testing.T) {
|
|
workspace, err := filepath.Abs(filepath.Join("testdata", "ws"))
|
|
if err != nil {
|
|
t.Fatalf("filepath.Abs() error = %v", err)
|
|
}
|
|
|
|
client := &Client{workspaceDir: workspace}
|
|
absPath := filepath.Join(workspace, "demo.go")
|
|
uri, err := pathToURI(absPath)
|
|
if err != nil {
|
|
t.Fatalf("pathToURI() error = %v", err)
|
|
}
|
|
|
|
got, err := client.normalizeURI(uri)
|
|
if err != nil {
|
|
t.Fatalf("normalizeURI() error = %v", err)
|
|
}
|
|
if got != uri {
|
|
t.Fatalf("normalizeURI() = %q, want %q", got, uri)
|
|
}
|
|
}
|