Position of mouse click?


#1

I’m trying to build IDE like features for Scala using Ensime. I have cursor-based “go to definition”, but typically in an IDE you should also be able to say cmd-click a symbol to go to it’s definition. This was next on my agenda, but I can’t find a way to get a mouse click as a Position in the buffer. Is there a way?


How to catch `cmd+click` in editor view?
#2

There’s been a few sporadic requests for this kind of thing, this is the closest I was able to find:


#3

This is exactly what I built code-links to do. It works by drawing a marker over anything I want to convert into a link and then listening for click events.

It also exposes this as a service so that other plugins can scan different languages and provide links without having to deal with markers or clicks. coffee-links uses this service.


#4

Awesome, I’ll check it out!


#5

We do this internally on every mousedown event. You might try consulting our approach here: https://github.com/atom/atom/blob/master/src/text-editor-component.coffee#L365

I’d be open to adding some kind of API to the view layer to intercept mouse clicks.


#6

@AsaAyers, I have looked at code-links, and it would be cool to use it. It would be nice to let the links show up and I actually have a means to generate all the links with Ensime (the server/client-based IDE thing for Scala).

https://github.com/ensime/ensime-server/blob/master/swank/src/main/scala/org/ensime/server/protocol/swank/SwankProtocol.scala#L1310

However, problem arrises when trying to implement:

# @param {string} source - editor text
# @returns {Object[]} - minimum requirement: a `range` property
process(source) ->

You see, with Ensime we in this case communicate via filename to a running server that has access to the file system of the project. So I can’t send the whole file content I get from “process” to Ensime, but I only need the filename (and maybe patch the file it if it is updated and unsaved and I want that functionality)

Is it possible to extend the process interface?


#7

Abolutely! The interface is just based on what I needed. I was hoping someone would be interested in adding links for other languages. This is starting to get off topic, so do you want to open an issue in code-links and we can discuss the needed changes there?


#8

Sure thing!


#9

@AsaAyers Hey, very late coming, but I did the change I needed. Like so:

It’s of course very API-breaking for providers so I didn’t just want to trough you a pull request immediately. I just did the change for the bundled javascript provider. Please let me know if you want me to issue a PR or not or if we can do it in a less breaking way.

In the meantime I’m going to try to use it with my intended use case which is this thing:

I’ll report back!

Cheers,
Viktor


#10

The great thing about the design of services is that there’s no reason to break compatibility. If you can clean this up to be the new 0.3.0 api we can also consume 0.2.0 providers at the same time.

This will primarily involve adding a new consumeLinkProvider function and wrapping any incoming 0.2.0 providers with a function that converts the editor to the source.


#11

Ah, cool! Got it.


#12

@AsaAyers Finally came around to this.

Is this ok? https://github.com/hedefalk/code-links/commit/109860a52b9b42a7ea80487f6771ad6c4da44942

Was a bit fiddly since it was a bit nested the actual going from editor to text, but I’m a bit slow thinking right now so there might be a WTF in there.

I need to do another change too where I want to be able to return a Promise from the processors, but I wanted to get feedback for this one first. Thing is my link provider is really async and I think this is very reasonable.

One more thing - the links go away after half a second for me, I see the code that does this, but should it really be like that? It’s a bit too short I think and I would like to have them as long as the button is pressed?