Skip to content

Commit

Permalink
Also support single location in Implementation/TypeDefinition/Definit…
Browse files Browse the repository at this point in the history
…ion response

Signed-off-by: Tw <wei.tan@intel.com>
  • Loading branch information
tw4452852 committed Nov 30, 2021
1 parent 3f4550c commit 26ba7d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 28 additions & 0 deletions internal/lsp/protocol/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,31 @@ func ToCodeActionOptions(v map[string]interface{}) (*CodeActionOptions, error) {
}
return &opt, nil
}

// Locations is a type which represents the union of Location and []Location
type Locations []Location

func (ls *Locations) UnmarshalJSON(data []byte) error {
d := strings.TrimSpace(string(data))
if len(d) == 0 && strings.EqualFold(d, "null") {
return nil
}

if d[0] == '[' {
var locations []Location
err := json.Unmarshal(data, &locations)
if err != nil {
return err
}
*ls = locations
} else {
var location Location
err := json.Unmarshal(data, &location)
if err != nil {
return err
}
*ls = append(*ls, location)
}

return nil
}
6 changes: 3 additions & 3 deletions internal/lsp/protocol/tsserver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 26ba7d1

Please sign in to comment.