Skip to content

File edited externally to IDE does not reload #4551

Open
@tjayrush

Description

@tjayrush

I frequently edit my code in both the IDE and external to the IDE when I program in xCode (not necessary to ask why--trust me--it makes sense).

In xCode, this works fine because the file reloads (assuming it's been saved in the IDE--it warns me otherwise), if I edit it externally.

In Arduino IDE the file does not reload (either automatically or after a warning). In other words, the Arduino IDE is ignoring OS X's message that the file has changed.

Suggestion: IDE should watch for and react to externally edited files and update the file in the IDE if it changes. This is, what I would call, "standard operating procedure."

Activity

lmihalkovic

lmihalkovic commented on Feb 9, 2016

@lmihalkovic

Aside from the 'simple' possibility of a manual chk upon window activation, there is a standard java API for doing that cross platform.

tjayrush

tjayrush commented on Feb 9, 2016

@tjayrush
Author

Sorry for the newbie question (new to GitHub and Arduino). Does your comment mean "Cool idea, go ahead and implement that in your [me] own version," or "Good idea. I [Arduino developers] will make that change"?

As I say, I'm new to this whole thing. Thanks.

chrstphrchvz

chrstphrchvz commented on Feb 9, 2016

@chrstphrchvz

(Another user here.) Note that in Preferences there is the "Use external editor" option that causes the editor to be read-only, and does refresh project to refresh upon focusing on the Arduino IDE--but this is not an option if you still need to use the Arduino IDE's editor. I agree that this is somewhat non-standard where other editors such as XCode, TextWrangler watch for file changes rather than application focus, and allowing out-of-the-box compatibility with git.

lmihalkovic

lmihalkovic commented on Feb 10, 2016

@lmihalkovic
Sorry for the newbie question (new to GitHub and Arduino). Does your comment mean 
"Cool idea, go ahead and implement that in your [me] own version," or "Good idea. 
I [Arduino developers] will make that change"?

@tjayrush there may not be a straight answer ... i would not dare presume what the Arduino team will do. However you may want to read all the other open issues and reach your own conclusions about what they are likely/unlikely to implement. Speaking in my own name, i find the idea interesting and there is a chance i will do something about it in a different setting

VioletGiraffe

VioletGiraffe commented on Feb 24, 2017

@VioletGiraffe

I want to bump this issue. Detecting file changes and prompting to reload modified files is basic functionality in any IDE or even a plain text editor. Even if you don't do any fancy stuff like working on the same project in two different IDEs at the same time (which I do), you will still come across this problem as soon as you put your project under version control. You revert some changes or switch to another revision - boom, you have stale code in your IDE, possibly without noticing a problem for some time.

facchinm

facchinm commented on Feb 24, 2017

@facchinm
Member

Unless you select "Use external editor", the IDE keeps the sketch is a memory buffer and saves it to a temporary file when needed.
This allows compiling (and testing) a sketch without necessarily overwriting the original one (I doubt any other IDE does that, but it's very common to open Blink, change the pin and upload the code without saving anything). But since it's not disk-backed, this flow doesn't allow the sketch to reload a file while running as editor.
If someone has a proposal that preserves the current behaviour while allowing a sketch to be reloaded I'll be glad to analyse and implement it.

VioletGiraffe

VioletGiraffe commented on Feb 24, 2017

@VioletGiraffe

@facchinm
I see what you mean, however it doesn't seem to be much different from any other IDE. You open files and edit them all the time so the files are in an unsaved state. It is not uncommon then to change the file externally, and when you go back to the IDE you get a prompt:

image

image

image

I don't see why the exact same behavior won't work with Arduino - without changing anything else.

facchinm

facchinm commented on Feb 24, 2017

@facchinm
Member

The difference is that if you don't save a file in a normal IDE you compile the on-disk file, not the temporary copy. So for a normal IDE the "reload" dialog is a must, while in our case it would be somehow counter-intuitive. I'm not saying we are not going to implement somethig similar sooner or later but I'd give a low priority to this task

VioletGiraffe

VioletGiraffe commented on Feb 24, 2017

@VioletGiraffe

@facchinm : in my opinion that changes nothing and poses no problems. Say you've opened some example, then edited and uploaded it. How probable do you think it is that the example file you started with will be modified? I think that's unlikely. In any of the cases where Arduino IDE's in-memory compilation feature is useful, I don't think a prompt I'm asking about would ever appear at all. It would appear in the cases where it's actually required (e. g. you're working with your sketch in a version control repository).

facchinm

facchinm commented on Feb 24, 2017

@facchinm
Member

That makes sense, indeed, I'm only saying it's not top priority, and neither it's an easy check between (local) file timestamps

lmihalkovic

lmihalkovic commented on Feb 24, 2017

@lmihalkovic

This has been standard behavior in IDEs for years now.. the arduino environment persists in redifining what is standard expectation.. if you convince yourselves it is great.. but don t expect that it might always work with everyone

VioletGiraffe

VioletGiraffe commented on Feb 24, 2017

@VioletGiraffe

@facchinm: I would do it with a file system watcher which is the OS-level tool just for this task, rather than rely on timestamps.

lmihalkovic

lmihalkovic commented on Feb 24, 2017

@lmihalkovic

Not wanting to deal with the technical problems is one thing (we already know we are in different places on the continuum of what is 'difficulty'), but wanting to convince people they don t need what they wish for or .. is a very different type of response

lmihalkovic

lmihalkovic commented on Feb 24, 2017

@lmihalkovic

.. in my very humble opinion.

matthijskooijman

matthijskooijman commented on Feb 24, 2017

@matthijskooijman
Collaborator

I'd also like to see some prompt to reload on change, seems like a worthwhile addition to me (and has been on my mental TODO-list for a while, though I'll probably never find time for it). In my workflow I often use an external editor, but sometimes I quickly load a sketch and want to make some changes to it in the Arduino IDE. Now I end up toggling the external editor option every now and then, but that's not ideal. I also don't think that this would conflict with how the editor handles files currently.

Wrt implementation, the screenshots seem like good examples. I'd imagine something like:

  • When Arduino gets the focus, show a prompt for each file that has changed since it was last loaded or saved in the IDE.
  • It should have buttons to load the file from disk, not load the file from disk and probably also to apply the same answer to all files.
  • If the file is modified inside the Arduino IDE, the prompt should make this clear, and emphasize that loading from disk will throw away changes. Perhaps the "do not load" button should have a different text (such "Discard my changes").
  • When the file is not loaded from disk, it should be marked as modified in the IDE, and subsequently clicking save in the IDE will overwrite it. The IDE could check all files again just before saving and ask for confirmation saying something like "Files were changed on disk, you will overwrite these changes now".
  • Detecting whether a file was modified should probably happen using the modified time of the file, perhaps combined with a checksum of the file content most recently saved or loaded.

57 remaining items

added 3 commits that reference this issue on Jul 18, 2019
6203ff8
d44e6ce
06306be
added a commit that references this issue on Sep 20, 2019
bf736b0
added a commit that references this issue on Sep 30, 2019
e125797
added a commit that references this issue on Oct 22, 2019
0de59c2
added a commit that references this issue on Feb 13, 2020
be4b8ed
added a commit that references this issue on Mar 23, 2020
1eba2d3
added a commit that references this issue on Apr 7, 2020
70d5537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Component: IDEThe Arduino IDEfeature requestA request to make an enhancement (not a bug fix)in progressWork on this item is in progress

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @matthijskooijman@Humancell@VioletGiraffe@lmihalkovic@heX16

    Issue actions

      File edited externally to IDE does not reload · Issue #4551 · arduino/Arduino