Link syntax to open file at line/column

I’m developing a package that processes the currently open file via an external application. It creates an item in a dock which contains an HTML version of the application’s output. If there are problems, the application reports the corresponding line and column number. I’m trying to mark these parts of the output to be links which when clicked open the file in Atom at that position.

Concretely, in my -view.js function I have code like this:

const link = document.createElement('a');
link.textContent = 'line ' + l + ' column ' + c
link.href ="<URI>"
line.appendChild(link)

The result looks like this, but the created link doesn’t do anything:

image

Is there a URI syntax that implements the function I’m looking for? Right now I cannot even manage to open the file via a standard file:// URI, much less at a specific position. Maybe there is an “atom://core” variant for this?

There is a package (open) that allows you to open files to a specific line/column with the following syntax:

atom://open?url=file://<file_path>[&line=<line>[&column=<column>]][&devMode][&safeMode][&newWindow]

I believe there is also a way to do it with atom://core/open/?something but I can’t find any documentation on it.

according to the code it looks like uri should be:

atom://core/open/file/?filename=<filepath>&line=<line>&column=<col>

but they don’t support the other options

Thanks!

For the first, I’d rather not depend on another package.

For the second, unfortunately it doesn’t work. As an href in an a element, it doesn’t do anything. With atom.workspace.open it opens an empty text editor associated with a file whose name is the URI interpreted as a path, atom: / core / open / ?filename=....

I have the impression that Atom URIs are not meant to be used as link targets. I guess I’ll have to put onClick-callbacks on the a elements.

You might need to enable URI handling in the settings in Atom.

For what it’s worth, I am the author of the open package. I use it in for our error logs to be able to easily open the file to the correct line of the error.

I created the package before Atom added the core URI.

image

Just tested the core URI seems to work fine as a link on my machine. I seems like it is sensitive to not having a slash after “file”

Windows 10
Atom 1.42.0-beta0 x64
<a href="atom://core/open/file?filename=C:\\test.txt&line=2&column=2">test.txt</a>

I think the “URI Handler” setting refers to the OS, whether “atom://” links are delegated to Atom. Moreover, registration as the handler is only supported on Windows & MacOS, I’m on Linux.
image

You are correct, a slash was the problem.

Thanks a lot!

Glad it worked!

Atom does mentions how to get the handler working on linux
https://flight-manual.atom.io/hacking-atom/sections/handling-uris/#linux-support