abingham / traad

An JSON+HTTP server for the rope Python refactoring library
MIT License
107 stars 20 forks source link

Add codeassist.find_definition_location #104

Closed jcaw closed 6 years ago

jcaw commented 6 years ago

Add an interface to allow clients to find where objects are defined.

A method stub for the server command already existed - this extends it to add full functionality. One note is that the old method stub was written to return the results of the Rope operation directly (this would fail as they can't be directly converted into json). The new method returns a dictionary of the form:

{
    'result': value,
    'realpath': value,
    'path': value,
    'name': value,
    'lineno': value,
}

I was able to find two different functions within Rope that locate definitions. The findit module has one, and the code_assist module has another. This uses the function from the code_assist module.

I have also added an interface for this in emacs-traad. The branch is available here - I'll request a pull there too if this is accepted.

jcaw commented 6 years ago

I've updated to send the code directly, falling back to loading from disk if no code is passed.

Sorry it took a while - busy week.

Do you think this approach will scale to large files? I was thinking that the client could send most buffers directly, but prompt the user to save the file if it's too large.

abingham commented 6 years ago

Sorry it took a while - busy week.

No worries, I feel your pain.

Do you think this approach will scale to large files? I was thinking that the client could send most buffers directly, but prompt the user to save the file if it's too large.

I suspect it'll be fine, and I think we should wait to see if it actually becomes a problem in practice before trying to account for it. Since buffer contents are optional in your changes, we can make the clients as smart as necessary as we go. Thanks!

jcaw commented 6 years ago

Awesome. I figured I'd make the backend flexible so the client can choose. That sounds good!