edubkendo / atom-racer

Intelligent code completion for Rust in the Atom Editor. Requires Racer.
MIT License
115 stars 24 forks source link

Fix temporary files recognition #73

Open ghost opened 8 years ago

ghost commented 8 years ago

This commit fixes an issue connected with temporary files recognition during auto-completion process. Invoking the “find definition” facility on a symbol placed in the file currently being edited implied opening a temporary file (with a .racertmp infix), which does not seem to exist at the moment immediately after executing a Racer command.

The RacerClient class imports temp and performs a temp.open() call for creating, opening and writing a temporary file passed into Racer. The temp library uses Math.random and toString(36) in order to produce a random path suffix. When called on a floating-point number, the toString method generate a string containing a decimal delimeter (.). Hence that random path suffix contains an extra dot (e.g. ._main.rs.racertmp116717-2079-43y0eh.hktltbj4i), and extname yields some random noise (.hktltbj4i in the previous example) instead of a string starting with .racertmp. That was not correctly handled by the code.

The attached screenshot illustrates what happened on my machine before applying the patch. A screenshot of at Atom session depicting the issue