MCPcopy Index your code
hub / github.com/microsoft/typescript-go / handleGetTypeAtPosition

Method handleGetTypeAtPosition

internal/api/session.go:1431–1455  ·  view source on GitHub ↗

handleGetTypeAtPosition returns the type at a position in a file.

(ctx context.Context, params *GetTypeAtPositionParams)

Source from the content-addressed store, hash-verified

1429
1430// handleGetTypeAtPosition returns the type at a position in a file.
1431func (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.
1458func (s *Session) handleGetTypesAtPositions(ctx context.Context, params *GetTypesAtPositionsParams) ([]*TypeResponse, error) {

Callers 1

HandleRequestMethod · 0.95

Calls 11

setupCheckerMethod · 0.95
GetTouchingPropertyNameFunction · 0.92
ToFileNameMethod · 0.80
GetPositionMapMethod · 0.80
UTF16ToUTF8Method · 0.80
GetTypeAtLocationMethod · 0.80
doneMethod · 0.65
GetSourceFileMethod · 0.65
ErrorfMethod · 0.65
intInterface · 0.50
newTypeResponseMethod · 0.45

Tested by

no test coverage detected