@@ -55,6 +55,12 @@ func NewServer(version string, lintRequest *utils.LintFileRequest) *ServerState
5555 serverCapabilities := handler .CreateServerCapabilities ()
5656 serverCapabilities .TextDocumentSync = protocol .TextDocumentSyncKindIncremental
5757 serverCapabilities .CompletionProvider = & protocol.CompletionOptions {}
58+ serverCapabilities .CodeActionProvider = & protocol.CodeActionOptions {
59+ CodeActionKinds : []protocol.CodeActionKind {protocol .CodeActionKindQuickFix },
60+ }
61+ serverCapabilities .ExecuteCommandProvider = & protocol.ExecuteCommandOptions {
62+ Commands : []string {"vacuum.openUrl" },
63+ }
5864
5965 return protocol.InitializeResult {
6066 Capabilities : serverCapabilities ,
@@ -99,6 +105,36 @@ func NewServer(version string, lintRequest *utils.LintFileRequest) *ServerState
99105 handler .TextDocumentCompletion = func (context * glsp.Context , params * protocol.CompletionParams ) (any , error ) {
100106 return nil , nil
101107 }
108+
109+ handler .TextDocumentCodeAction = func (context * glsp.Context , params * protocol.CodeActionParams ) (any , error ) {
110+ var actions []protocol.CodeAction
111+
112+ for _ , diagnostic := range params .Context .Diagnostics {
113+ if diagnostic .CodeDescription != nil && diagnostic .CodeDescription .HRef != "" {
114+ quickFixKind := protocol .CodeActionKindQuickFix
115+ actions = append (actions , protocol.CodeAction {
116+ Title : "View documentation" ,
117+ Kind : & quickFixKind ,
118+ Command : & protocol.Command {
119+ Title : "Open documentation" ,
120+ Command : "vacuum.openUrl" ,
121+ Arguments : []interface {}{diagnostic .CodeDescription .HRef },
122+ },
123+ })
124+ }
125+ }
126+
127+ return actions , nil
128+ }
129+
130+ handler .WorkspaceExecuteCommand = func (context * glsp.Context , params * protocol.ExecuteCommandParams ) (any , error ) {
131+ if params .Command == "vacuum.openUrl" && len (params .Arguments ) > 0 {
132+ if url , ok := params .Arguments [0 ].(string ); ok {
133+ utils .OpenURL (url )
134+ }
135+ }
136+ return nil , nil
137+ }
102138 return state
103139}
104140
@@ -166,7 +202,9 @@ func ConvertResultIntoDiagnostic(vacuumResult *model.RuleFunctionResult) protoco
166202 severity := GetDiagnosticSeverityFromRule (vacuumResult .Rule )
167203
168204 diagnosticErrorHref := fmt .Sprintf ("%s/rules/unknown" , model .WebsiteUrl )
169- if vacuumResult .Rule .RuleCategory != nil {
205+ if vacuumResult .Rule .DocumentationURL != "" {
206+ diagnosticErrorHref = vacuumResult .Rule .DocumentationURL
207+ } else if vacuumResult .Rule .RuleCategory != nil {
170208 diagnosticErrorHref = fmt .Sprintf ("%s/rules/%s/%s" , model .WebsiteUrl ,
171209 strings .ToLower (vacuumResult .Rule .RuleCategory .Id ),
172210 strings .ReplaceAll (strings .ToLower (vacuumResult .Rule .Id ), "$" , "" ))
@@ -191,7 +229,7 @@ func ConvertResultIntoDiagnostic(vacuumResult *model.RuleFunctionResult) protoco
191229 message += "\n \n Description: " + vacuumResult .Rule .Description
192230 }
193231 if vacuumResult .Rule .HowToFix != "" {
194- message += "\n \n How to fix: " + vacuumResult .Rule .HowToFix + "\n \n Rule ID:"
232+ message += "\n \n How to fix: " + vacuumResult .Rule .HowToFix + "\n \n Rule ID: " + vacuumResult . Rule . Id + " \n "
195233 }
196234
197235 return protocol.Diagnostic {
0 commit comments