mirror of
https://github.com/laravel-ls/protocol.git
synced 2026-06-18 13:00:03 +02:00
Initial commit
This commit is contained in:
commit
9061064e97
21 changed files with 1699 additions and 0 deletions
79
document_definition.go
Normal file
79
document_definition.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package protocol
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const (
|
||||
// MethodTextDocumentDefinition method name of "textDocument/definition".
|
||||
MethodTextDocumentDefinition = "textDocument/definition"
|
||||
)
|
||||
|
||||
// DefinitionParams defines the parameters for a textDocument/definition request.
|
||||
//
|
||||
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#definitionParams
|
||||
type DefinitionParams struct {
|
||||
WorkDoneProgressParams
|
||||
PartialResultParams
|
||||
TextDocumentPositionParams
|
||||
}
|
||||
|
||||
// DefinitionResponse represents the result of a textDocument/definition request.
|
||||
//
|
||||
// It can be a single Location, a slice of Locations, a slice of LocationLinks or null.
|
||||
//
|
||||
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#definition
|
||||
type DefinitionResponse struct {
|
||||
Location *Location
|
||||
LocationList []Location
|
||||
LocationLinks []LocationLink
|
||||
Null bool
|
||||
}
|
||||
|
||||
func (dr DefinitionResponse) MarshalJSON() ([]byte, error) {
|
||||
if dr.Location != nil {
|
||||
return json.Marshal(dr.Location)
|
||||
}
|
||||
if dr.LocationList != nil {
|
||||
return json.Marshal(dr.LocationList)
|
||||
}
|
||||
if dr.LocationLinks != nil {
|
||||
return json.Marshal(dr.LocationLinks)
|
||||
}
|
||||
return []byte("null"), nil
|
||||
}
|
||||
|
||||
func (dr *DefinitionResponse) UnmarshalJSON(data []byte) error {
|
||||
// Make sure object is reset.
|
||||
*dr = DefinitionResponse{}
|
||||
|
||||
// Check for null
|
||||
if string(data) == "null" {
|
||||
dr.Null = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// Try single Location
|
||||
var loc Location
|
||||
if err := json.Unmarshal(data, &loc); err == nil && loc.URI != "" {
|
||||
dr.Location = &loc
|
||||
return nil
|
||||
}
|
||||
|
||||
// Try []Location
|
||||
var locList []Location
|
||||
if err := json.Unmarshal(data, &locList); err == nil {
|
||||
dr.LocationList = locList
|
||||
return nil
|
||||
}
|
||||
|
||||
// Try []LocationLink
|
||||
var linkList []LocationLink
|
||||
if err := json.Unmarshal(data, &linkList); err == nil {
|
||||
dr.LocationLinks = linkList
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("invalid definition response: not null, Location, []Location, or []LocationLink")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue