fix: implement code review suggestions

Address all feedback from PR review:
- Lock granularity
- Empty response handling
- Shutdown race condition
- Interface naming
This commit is contained in:
Lixeer
2026-02-24 22:33:04 +08:00
parent 3d605a4f53
commit d09c64fcee
4 changed files with 26 additions and 21 deletions
+13 -8
View File
@@ -94,19 +94,24 @@ func (p *GitHubCopilotProvider) Chat(
return nil, fmt.Errorf("marshal messages: %w", err)
}
p.mu.Lock()
defer p.mu.Unlock()
session := p.session
p.mu.Unlock()
resp, err := p.session.SendAndWait(ctx, copilot.MessageOptions{
if session == nil {
return nil, fmt.Errorf("provider closed")
}
resp, err := session.SendAndWait(ctx, copilot.MessageOptions{
Prompt: string(fullcontent),
})
if err != nil {
return nil, err
}
var content string
if resp != nil && resp.Data.Content != nil {
content = *resp.Data.Content
if resp == nil {
return nil, fmt.Errorf("empty response from copilot")
}
if resp.Data.Content == nil {
return nil, fmt.Errorf("no content in copilot response")
}
content := *resp.Data.Content
return &LLMResponse{
FinishReason: "stop",