handleGetTypeAtPosition returns the type at a position in a file.
(ctx context.Context, params *GetTypeAtPositionParams)
| 1429 | |
| 1430 | // handleGetTypeAtPosition returns the type at a position in a file. |
| 1431 | func (s *Session) handleGetTypeAtPosition(ctx context.Context, params *GetTypeAtPositionParams) (*TypeResponse, error) { |
| 1432 | setup, err := s.setupChecker(ctx, params.Snapshot, params.Project) |
| 1433 | if err != nil { |
| 1434 | return nil, err |
| 1435 | } |
| 1436 | defer setup.done() |
| 1437 | |
| 1438 | sourceFile := setup.program.GetSourceFile(params.File.ToFileName()) |
| 1439 | if sourceFile == nil { |
| 1440 | return nil, fmt.Errorf("%w: source file not found: %v", ErrClientError, params.File) |
| 1441 | } |
| 1442 | |
| 1443 | positionMap := sourceFile.GetPositionMap() |
| 1444 | node := astnav.GetTouchingPropertyName(sourceFile, positionMap.UTF16ToUTF8(int(params.Position))) |
| 1445 | if node == nil { |
| 1446 | return nil, nil |
| 1447 | } |
| 1448 | |
| 1449 | t := setup.checker.GetTypeAtLocation(node) |
| 1450 | if t == nil { |
| 1451 | return nil, nil |
| 1452 | } |
| 1453 | |
| 1454 | return setup.newTypeResponse(t), nil |
| 1455 | } |
| 1456 | |
| 1457 | // handleGetTypesAtPositions returns types at multiple positions in a file. |
| 1458 | func (s *Session) handleGetTypesAtPositions(ctx context.Context, params *GetTypesAtPositionsParams) ([]*TypeResponse, error) { |
no test coverage detected