Skip to content

Commit

Permalink
fix HTML string from language server
Browse files Browse the repository at this point in the history
  • Loading branch information
nighca committed Jan 9, 2025
1 parent a8245ce commit e9bdcde
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tools/spxls/internal/server/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type SpxResourceURI string

// HTML returns the HTML representation of the spx resource URI.
func (u SpxResourceURI) HTML() string {
return fmt.Sprintf("<resource-preview resource=%q />\n", u)
return fmt.Sprintf("<resource-preview resource=%s />\n", attr(string(u)))
}

// SpxGetDefinitionsParams represents parameters to get definitions at a
Expand Down
2 changes: 1 addition & 1 deletion tools/spxls/internal/server/spx_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type SpxDefinition struct {

// HTML returns the HTML representation of the definition.
func (def SpxDefinition) HTML() string {
return fmt.Sprintf("<definition-item def-id=%q overview=%q>\n%s</definition-item>\n", def.ID, def.Overview, def.Detail)
return fmt.Sprintf("<definition-item def-id=%s overview=%s>\n%s</definition-item>\n", attr(def.ID.String()), attr(def.Overview), def.Detail)
}

// CompletionItem constructs a [CompletionItem] from the definition.
Expand Down
6 changes: 6 additions & 0 deletions tools/spxls/internal/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"fmt"
"go/types"
"html/template"
"io/fs"
"regexp"
"strings"
Expand Down Expand Up @@ -268,3 +269,8 @@ func getSimplifiedTypeString(typ types.Type) string {
return p.Name()
})
}

// attr transforms given string value to an HTML attribute value (with quotes).
func attr(value string) string {
return fmt.Sprintf(`"%s"`, template.HTMLEscapeString(value))
}

0 comments on commit e9bdcde

Please sign in to comment.