defuz / RustAutoComplete

A SublimeText binding for RACER (Rust auto completion tool)
MIT License
105 stars 20 forks source link

Fix #12 - Use python `tempfile` for tempfiles #15

Closed porglezomp closed 9 years ago

porglezomp commented 9 years ago

Use tempfile to create tempfiles instead of current folder

glennw commented 9 years ago

Thanks for the PR! Someone else added the encoding='utf8' recently to fix a unicode issue. I don't think that's relevant anymore with the change you've made (since it's not based on the current path) - does that make sense to you?

Also, when I first wrote the plugin, I initially used something similar (a temp path) but I found racer didn't autocomplete items from the local project unless the tempfile was stored alongside them - but maybe that has been resolved now?

If you can confirm the above items are not an issue, I'll merge this and make a new release!

porglezomp commented 9 years ago

Thanks, I hadn't considered all of those issues, so I'll investigate some more to confirm they work.

porglezomp commented 9 years ago

It looks like you indeed have to be in the same folder as the sources for it to work. I'll see about doing the best possible thing to find the code folder, and only use the system tmp folder as a last resort.

In terms of the encoding issue, does the open([stuff], encoding="utf-8") even work without Python 3? I know ST3 uses Python 3.3, but ST2 uses the system Python, so I don't know if the current code will work on most installations of ST2.

glennw commented 9 years ago

Sounds good. I'm not sure about the encoding stuff - but I only use ST3 and I'm fine with this plugin being ST3-only (it's only listed as ST3 compatible in package control I think). Unless there's an easy way to make it work with ST2 as well, which I guess would be ideal.

porglezomp commented 9 years ago

Okay, I didn't see that it was ST3 only. Since I know I'm targeting Python 3.3 I can fix the encoding for sure.

I have a few ideas about things that we could do to guess where to put it. Currently you're saving the temp file next to the file, and I'm saving it to the global tmp now if it's unsaved. Should I attempt to treat it as a cargo project if the window has an open folder? I would save unsaved temp files into os.path.join(window.folders()[0], "src") which would look like ~/Dev/project-name/src?

Furthermore, if there's no open folder, should I try to guess where to save it based on the stems of open files? Maybe only if they're all in the same directory?

Note that currently racer doesn't handle very complex file structures right now, so if someone has a project like:

main.rs
module.rs
moremodule/
    mod.rs
    item.rs

I don't think it's able to complete any code inside moremodule:: from main.rs

glennw commented 9 years ago

I think the best idea might be to ask the author of racer (https://github.com/phildawes/racer) where he would recommend saving the temp file?

porglezomp commented 9 years ago

I'll ask him about doing that, but in the meantime I've hacked together a solution that I think does a better job than what we have currently.

glennw commented 9 years ago

Looks good - does it handle the utf8 encoding change we discussed above? I couldn't see where it handles that but I may have missed it.

porglezomp commented 9 years ago

That's odd, I appear to have left it off. It should be fixed now?

glennw commented 9 years ago

Thanks!