-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(spxls): add missing JSON marshalers and unmarshalers (#1156)
Signed-off-by: Aofei Sheng <[email protected]>
- Loading branch information
Showing
12 changed files
with
2,544 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package server | ||
|
||
import ( | ||
"errors" | ||
"go/types" | ||
) | ||
|
||
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_declaration | ||
func (s *Server) textDocumentDeclaration(params *DeclarationParams) (any, error) { | ||
return s.textDocumentDefinition(&DefinitionParams{ | ||
TextDocumentPositionParams: params.TextDocumentPositionParams, | ||
WorkDoneProgressParams: params.WorkDoneProgressParams, | ||
PartialResultParams: params.PartialResultParams, | ||
}) | ||
} | ||
|
||
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_definition | ||
func (s *Server) textDocumentDefinition(params *DefinitionParams) (any, error) { | ||
result, _, astFile, err := s.compileAndGetASTFileForDocumentURI(params.TextDocument.URI) | ||
if err != nil { | ||
if errors.Is(err, errNoValidSpxFiles) || errors.Is(err, errNoMainSpxFile) { | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
if astFile == nil { | ||
return nil, nil | ||
} | ||
|
||
_, obj := result.identAndObjectAtASTFilePosition(astFile, params.Position) | ||
if !isMainPkgObject(obj) { | ||
return nil, nil | ||
} | ||
|
||
defIdent := result.defIdentOf(obj) | ||
if defIdent == nil { | ||
return nil, nil | ||
} | ||
return s.createLocationFromIdent(result.fset, defIdent), nil | ||
} | ||
|
||
// See https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_typeDefinition | ||
func (s *Server) textDocumentTypeDefinition(params *TypeDefinitionParams) (any, error) { | ||
result, _, astFile, err := s.compileAndGetASTFileForDocumentURI(params.TextDocument.URI) | ||
if err != nil { | ||
if errors.Is(err, errNoValidSpxFiles) || errors.Is(err, errNoMainSpxFile) { | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
if astFile == nil { | ||
return nil, nil | ||
} | ||
|
||
_, obj := result.identAndObjectAtASTFilePosition(astFile, params.Position) | ||
if !isMainPkgObject(obj) { | ||
return nil, nil | ||
} | ||
|
||
objType := unwrapPointerType(obj.Type()) | ||
named, ok := objType.(*types.Named) | ||
if !ok { | ||
return nil, nil | ||
} | ||
|
||
objPos := named.Obj().Pos() | ||
if !objPos.IsValid() { | ||
return nil, nil | ||
} | ||
return s.createLocationFromPos(result.fset, objPos), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.