MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / getCodeActionsForDiagnostic

Method getCodeActionsForDiagnostic

pkg/lsp/handler.go:1629–1690  ·  view source on GitHub ↗

getCodeActionsForDiagnostic generates code actions for a specific diagnostic

(uri string, diag Diagnostic)

Source from the content-addressed store, hash-verified

1627
1628// getCodeActionsForDiagnostic generates code actions for a specific diagnostic
1629func (h *Handler) getCodeActionsForDiagnostic(uri string, diag Diagnostic) []CodeAction {
1630 actions := []CodeAction{}
1631 msg := strings.ToLower(diag.Message)
1632
1633 // Common SQL error fixes
1634 if strings.Contains(msg, "unexpected") || strings.Contains(msg, "expected") {
1635 // Suggest adding missing semicolon
1636 if strings.Contains(msg, "semicolon") || strings.Contains(msg, ";") {
1637 actions = append(actions, CodeAction{
1638 Title: "Add missing semicolon",
1639 Kind: CodeActionQuickFix,
1640 Diagnostics: []Diagnostic{diag},
1641 Edit: &WorkspaceEdit{
1642 Changes: map[string][]TextEdit{
1643 uri: {
1644 {
1645 Range: Range{Start: diag.Range.End, End: diag.Range.End},
1646 NewText: ";",
1647 },
1648 },
1649 },
1650 },
1651 })
1652 }
1653 }
1654
1655 // Suggest uppercase for keywords
1656 if strings.Contains(msg, "keyword") {
1657 content, ok := h.server.Documents().GetContent(uri)
1658 if ok {
1659 lines := strings.Split(content, "\n")
1660 if diag.Range.Start.Line < len(lines) {
1661 line := lines[diag.Range.Start.Line]
1662 start := diag.Range.Start.Character
1663 end := diag.Range.End.Character
1664 if start < len(line) && end <= len(line) && start < end {
1665 word := line[start:end]
1666 upper := strings.ToUpper(word)
1667 if word != upper {
1668 actions = append(actions, CodeAction{
1669 Title: fmt.Sprintf("Convert '%s' to uppercase", word),
1670 Kind: CodeActionQuickFix,
1671 Diagnostics: []Diagnostic{diag},
1672 Edit: &WorkspaceEdit{
1673 Changes: map[string][]TextEdit{
1674 uri: {
1675 {
1676 Range: diag.Range,
1677 NewText: upper,
1678 },
1679 },
1680 },
1681 },
1682 })
1683 }
1684 }
1685 }
1686 }

Callers 1

handleCodeActionMethod · 0.95

Calls 2

GetContentMethod · 0.80
DocumentsMethod · 0.80

Tested by

no test coverage detected