microsoft/typescript-go · error · ErrClientError
%w: getSymbolsInScope requires a location
Error message
%w: getSymbolsInScope requires a location
What it means
getSymbolsInScope requires a location to enumerate visible symbols, and resolveLocation returned nil without error: the request carried neither a non-empty location node handle nor both file and position. Any subset (file without position, position without file, or nothing) triggers this guard.
Source
Thrown at internal/api/session.go:1615
}
return setup.newSymbolResponse(symbol), nil
}
// handleGetSymbolsInScope returns all symbols with the given meaning that are visible at a location.
func (s *Session) handleGetSymbolsInScope(ctx context.Context, params *GetSymbolsInScopeParams) ([]*SymbolResponse, error) {
setup, err := s.setupChecker(ctx, params.Snapshot, params.Project)
if err != nil {
return nil, err
}
defer setup.done()
location, err := setup.resolveLocation(params.Location, params.File, params.Position)
if err != nil {
return nil, err
}
if location == nil {
return nil, fmt.Errorf("%w: getSymbolsInScope requires a location", ErrClientError)
}
symbols := setup.checker.GetSymbolsInScope(location, ast.SymbolFlags(params.Meaning))
results := make([]*SymbolResponse, len(symbols))
for i, symbol := range symbols {
results[i] = setup.newSymbolResponse(symbol)
}
return results, nil
}
// handleGetSignaturesOfType returns the call or construct signatures of a type.
func (s *Session) handleGetSignaturesOfType(ctx context.Context, params *GetSignaturesOfTypeParams) ([]*SignatureResponse, error) {
setup, err := s.setupChecker(ctx, params.Snapshot, params.Project)
if err != nil {
return nil, err
}
defer setup.done()View on GitHub (pinned to 1bcfa18d79)
Solutions
- Send either a location node handle obtained from a prior symbol/AST query, or both file and position together
- Validate the pair client-side: file and position must be present or absent as a unit
- If you only have an offset, make sure the file identifier accompanies it
Example fix
// before
getSymbolsInScope(snap, proj, {meaning: 1}) // no location at all
// after
pos := uint32(120)
getSymbolsInScope(snap, proj, {file: &api.DocumentIdentifier{FileName: "/abs/a.ts"}, position: &pos, meaning: 1}) Defensive patterns
Strategy: type-guard
Type guard
func hasScopeLocation(p *api.GetSymbolsInScopeParams) bool {
if p == nil { return false }
if p.Location != "" { return true }
return p.File != nil && p.Position != nil // file and position must arrive as a pair
} Try / catch
if err != nil && strings.Contains(err.Error(), "requires a location") {
// request-shape bug: add location handle or file+position, then re-send
} Prevention
- Treat file+position as one composite field; serialize both or neither
- Beware omitempty zeroing position (0 is a valid offset) — use pointers as the struct does
- Reuse node handles returned by earlier symbol queries as the location anchor
When it happens
Trigger: Sending params with all three optional fields (location, file, position) absent or empty; serializing pointers as null via omitempty so both sides of the file+position pair disappear; sending only file or only position.
Common situations: Client structs with omitempty on both file and position where one is zero-valued; refactors that pass a location handle from an unrelated response (empty string when unset); UI events that carry a cursor offset but no document.
Related errors
- Cannot run a temporary file update on an inactive snapshot
- Snapshot is disposed
- Cannot create directory: a file already exists at "/${segmen
- Invalid file path: "${path}"
- Bad line number. Line: ${line}, lineStarts.length: ${lineSta
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/0f4585efb7e77e88.
Report an issue: GitHub.