question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide an API to track a position in a document across edits

See original GitHub issue

I’ve come across a few places where this’d be handy lately. Most recently, I run some tests for my user and I get back positions in the document of where each test is - this allows them to click on the test in the runner/results to jump directly to it.

Unfortunately, if the user modifies their test file then this location information becomes out of date and now jumps the user to the wrong location when they click it. This can be really common - you run your tests; 5 of them fail; you start working through them - working on the first test shifts the position of the tests below such that it’s now difficult to jump to them from the test list.

VS Code is presumably already tracking things like this for things like decorations so it’d be nice if we could use it too. For example, imagine an API like this:

// Get some token that represents a live position in the document
const loc = document.trackLocation(position);

// User makes some edits

// Request the new position
console.log(document.positionOf(loc));

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
chestozocommented, Apr 3, 2020

I see that internally there is a method that we would really appreciate - https://github.com/microsoft/vscode/blob/master/src/vs/editor/browser/widget/codeEditorWidget.ts#L1118 - getLineDecorations but it is not exposed to public usage.

I was trying to reach to it via

vscode.window.activeTextEditor._proxy
vscode.window.activeTextEditor._runOnProxy

but I couldn’t.

Any plans to make it public?

5reactions
DanTupcommented, Nov 15, 2018

@PEZ Sure - the code is in an experimental feature that nobody currently uses so I can’t guarantee how well it works, but it’s here:

https://github.com/Dart-Code/Dart-Code/blob/d996c73d6a455135b8e532ac266ef1f33704b0e7/src/decorations/hot_reload_coverage_decorations.ts#L54

Of interest are probably lines 73-83 which enumerates the changes and 130-145 which updates the internal model based on the changes. We track ranges of lines, so we offset any that were after the edit, leave any that were before, and drop any that are eclipsed by the edit. If you need exact offsets, you’d need to improve this somewhat.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP Tracking API Source | Segment Documentation
The Segment HTTP Tracking API lets you record analytics data from any website or application. The requests hit Segment servers, ...
Read more >
Geolocation API - W3C
The Geolocation API provides access to geographical location information associated with the hosting device.
Read more >
VS Code API | Visual Studio Code Extension API
The editor provides an API that makes it simple to provide such common features by having all UI and actions already in place...
Read more >
HERE REST APIs: Portable APIs for Maps, Routing and More
A REST API for location data management that allows developers to store, edit and retrieve geospatial data more efficiently. Tracking API. Store and...
Read more >
Intersection Observer API - MDN Web Docs
The Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found