Skip to content

Mapping when tokens in source code are longer than in the generated produces wrong end position based on the shortest generated token #295

@leonidaz

Description

@leonidaz

When a mapping / token in the source code has a greater length than the generated one, the end offset / end character position ends up being the shorter generated one when the longer in the source code is should be provided for selection / range for vscode.

Example:

Source code:

import {
	TrackedArray,
	TrackedObject,
	TrackedSet,
	TrackedMap,
	createRefKey,
} from 'ripple';

Generated code:

import { TrackedArray, TrackedObject, TrackedSet, TrackedMap, createRefKey } from 'ripple';

The offset in the source code is 97 and 91 in the generated code.

The end position when translating generated to source for vscode's source locations ends up being { line 6, character: 10 } where it should be { line: 6, character: 16 }. This stems from the calculation of the wrong offset 91 from the generated one as the function translateOffset() always selects the smallest offset based on Math.min().

Looks like the fix would be to provide contextual info for the function translateOffset() to prefer selecting the longer offset when translating generated to source offsets when calculating the end source position.

I'll put up a pr shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions