clemos / haxe-sublime-bundle

Sublime Text bundle for Haxe programming language
Apache License 2.0
237 stars 86 forks source link

ST3 (OSX) .hx file & .hx.tmp, and 'changed on disk' #127

Closed DanielHudson closed 9 years ago

DanielHudson commented 10 years ago

When I'm editing an .hx file, ST3 (OSX) appears to create a .hx.tmp file, I also get the following message appearing frequently as I type into an .hx file..

Has changed on disk.
Do you want to reload it?

Not sure if this is a ST3 issue or haxe-sublime-bundle one...

DanielHudson commented 10 years ago

Doesn't appear to be an issue anymore!?

clemos commented 10 years ago

Well sorry for not replying before, I just forgot it completely (december 30, you know ;)) The issue you had is usually a consequence of some other bug in the bundle, which apparently has been fixed.

kevinfiol commented 10 years ago

Just installed this plugin on Windows 7 with Sublime Text 2, and getting this issue. Additionally, the plugin seems to take a second or two to load autocompletions at times, although I'm not sure if this is normal as I've found nothing online detailing that.

clemos commented 10 years ago

The symptom described in this ticket can be the consequence of a number of different issues, actually. Do you get any error in the ST Console either at start-up time, or when you type , or ( in an .hx file ? I confess I don't really test ST2 anymore, and even less on Windows :\

tjrhodes commented 9 years ago

I think you should open this up, I'm getting this error with build 3083 and 3085 of ST3 and the the haxe plugin.

If I uninstall and reinstall ST3, without the haxe bundle all is well, as soon as I install the bundle I get this error. I'm on Ubuntu Gnome 15.04, I've tried EXT4, NTFS partitions, NAS and a USB drive. Happens on all of them.

ghost commented 9 years ago

Please check sublime's console. Do you have any errors there after "file changed" message?

tjrhodes commented 9 years ago

Hi,

Yes I do :) Looks to be a permissions problem, although everything listed is in my home dir? Do you want me to try to run sublime as sudo?

Here's the console output...

Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 359, in on_query_completions res = callback.on_query_completions(v, prefix, locations) File "HaxeComplete in /home/tom/.config/sublime-text-3/Installed Packages/Haxe.sublime-package", line 1822, in on_query_completions File "HaxeComplete in /home/tom/.config/sublime-text-3/Installed Packages/Haxe.sublime-package", line 1979, in get_haxe_completions File "HaxeComplete in /home/tom/.config/sublime-text-3/Installed Packages/Haxe.sublime-package", line 1841, in save_temp_file File "./shutil.py", line 244, in copy2 File "./shutil.py", line 190, in copystat PermissionError: [Errno 1] Operation not permitted

ghost commented 9 years ago

Is there any file path after Operation not permitted?

lewislepton commented 9 years ago

im actually getting this problem also. but noticed its not until i choose a build type, say NEKO or iOS etc. but if i dont choose one beforehand it leaves it alone

this is the entire console output from sublime when i tap Reload

startup, version: 3083 osx x64 channel: stable
executable: /Applications/Developer/Sublime Text.app/Contents/MacOS/Sublime Text
working dir: /
packages path: /Users/lewislepton/Library/Application Support/Sublime Text 3/Packages
state path: /Users/lewislepton/Library/Application Support/Sublime Text 3/Local
zip path: /Applications/Developer/Sublime Text.app/Contents/MacOS/Packages
zip path: /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.214474
using gpu buffer for window
first paint time: 0.269765
startup time: 0.286625
reloading plugin Default.block
reloading plugin Default.comment
reloading plugin Default.copy_path
reloading plugin Default.delete_word
reloading plugin Default.detect_indentation
reloading plugin Default.duplicate_line
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.indentation
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_file_settings
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.quick_panel
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.swap_line
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin 0_package_control_loader.00-package_control
reloading plugin 0_package_control_loader.02-bz2
reloading plugin Package Control.bootstrap
reloading plugin Package Control.Package Control
plugins loaded
Package Control: Skipping automatic upgrade, last run at 2015-05-12 15:10:23, next run at 2015-05-12 16:10:23 or after
ignored packages updated to: ["Vintage", "Haxe"]
reloading Packages/User/Package Control.sublime-settings
reloading Packages/User/Preferences.sublime-settings
reloading Packages/User/Package Control.sublime-settings
ignored packages updated to: ["Vintage"]
reloading plugin Haxe.HaxeComplete
hello
Haxe : Reloading haxe module
Haxe : Reloading haxelib module
HAXE : haxelib list 
HAXE : haxelib install 
HAXE : haxelib search 
HAXE : haxelib upgrade 
reloading Packages/Haxe/Support/Haxe.sublime-settings
generating syntax summary
generating meta info summary
reloading Packages/User/Package Control.sublime-settings
reloading Packages/User/Preferences.sublime-settings
generating meta info summary
reloading Packages/User/Preferences.sublime-settings
ignored packages updated to: ["Vintage", "SideBarEnhancements"]
reloading Packages/User/Package Control.sublime-settings
reloading Packages/User/Preferences.sublime-settings
reloading Packages/User/Package Control.sublime-settings
ignored packages updated to: ["Vintage"]
reloading plugin SideBarEnhancements.SideBar
reloading plugin SideBarEnhancements.SideBarAPI
reloading plugin SideBarEnhancements.SideBarDefaultDisable
reloading Packages/User/Package Control.sublime-settings
reloading Packages/User/Preferences.sublime-settings
reloading Packages/User/Preferences.sublime-settings
recreating index
Starting Haxe server on port 6001
not well-formed (invalid token): line 1, column 104
invalid xml
not well-formed (invalid token): line 1, column 104
invalid xml
not well-formed (invalid token): line 1, column 104
invalid xml
reloading Packages/User/Preferences.sublime-settings
reloading Packages/User/Preferences.sublime-settings
not well-formed (invalid token): line 1, column 104
invalid xml
Traceback (most recent call last):
  File "/Applications/Developer/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 359, in on_query_completions
    res = callback.on_query_completions(v, prefix, locations)
  File "HaxeComplete in /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages/Haxe.sublime-package", line 1822, in on_query_completions
  File "HaxeComplete in /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages/Haxe.sublime-package", line 1980, in get_haxe_completions
  File "HaxeComplete in /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages/Haxe.sublime-package", line 1782, in run_haxe
  File "features.haxe_errors in /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages/Haxe.sublime-package", line 67, in highlight_errors
FileNotFoundError: [Errno 2] No such file or directory: '/Users/lewislepton/Developer/HAXE/GAMES/SEARCH/<builtin>'
Traceback (most recent call last):
  File "/Applications/Developer/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 304, in on_activated
    callback.on_activated(v)
  File "HaxeComplete in /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages/Haxe.sublime-package", line 502, in on_activated
  File "HaxeComplete in /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages/Haxe.sublime-package", line 522, in on_open_file
  File "features.haxe_errors in /Users/lewislepton/Library/Application Support/Sublime Text 3/Installed Packages/Haxe.sublime-package", line 67, in highlight_errors
FileNotFoundError: [Errno 2] No such file or directory: '/Users/lewislepton/Developer/HAXE/GAMES/SEARCH/<builtin>'
reloading /Users/lewislepton/Developer/HAXE/GAMES/SEARCH/source/MenuState.hx
lewislepton commented 9 years ago

im on mac, with latest public sublime text 3

tjrhodes commented 9 years ago

No, in console no path after the Operation not permitted. Also, running as sudo doesn't help, I still get the error which is weird as sudo should be able to do what they like right?

ghost commented 9 years ago

I think I fixed your issue @lewislepton. @tjrhodes, not sure. I'll try to reproduce your issue.

lewislepton commented 9 years ago

cool spot. let us know when its up ;)

lewislepton commented 9 years ago

or has it just been updated. ill just try ;)

tjrhodes commented 9 years ago

@r3a1ay ok, what else can I do to help you find it? Any log files you want or anything?

lewislepton commented 9 years ago

just so you know. that lastest update ha fixed that problem for myself on MAC with sublime text 3

tjrhodes commented 9 years ago

unfortunately with latest git the problem persists for me...

what extra info can I give you?

ghost commented 9 years ago

@tjrhodes, open any .hx file and try to run this code in sublime's console:

import os, shutil
fn = sublime.active_window().active_view().file_name()
fn_tmp = fn + '.tmp'
print(fn, os.stat(fn).st_mode)
shutil.copy2(fn, fn_tmp)
os.remove(fn_tmp)
tjrhodes commented 9 years ago

@r3a1ay ok, I got this back...

/media/tom/Tome/001. WORK/NICK MORTIMER/IEDP Email App/production/src/server/Remote.hx 33279 '/media/tom/Tome/001. WORK/NICK MORTIMER/IEDP Email App/production/src/server/Remote.hx.tmp'

Which are the correct paths to the open file, no errors though.

ghost commented 9 years ago

ok, try this:

import os, shutil, stat
fn = sublime.active_window().active_view().file_name()
fn_tmp = fn + '.tmp'
print(fn, os.stat(fn).st_mode)
os.chmod(fn , os.stat(fn).st_mode | stat.S_IWRITE)
shutil.copy2(fn, fn_tmp)
os.remove(fn_tmp)
tjrhodes commented 9 years ago

@r3a1ay right, error this time...

/media/tom/Tome/001. WORK/NICK MORTIMER/IEDP Email App/production/src/server/Remote.hx 33279
Traceback (most recent call last):
  File "<string>", line 1, in <module> NameError: name 'stat' is not defined
ghost commented 9 years ago

Did you import stat module?

import os, shutil, stat

Please try this code one more time:

import os, shutil, stat
fn = sublime.active_window().active_view().file_name()
fn_tmp = fn + '.tmp'
print(fn, os.stat(fn).st_mode)
os.chmod(fn , os.stat(fn).st_mode | stat.S_IWRITE)
shutil.copy2(fn, fn_tmp)
os.remove(fn_tmp)
ghost commented 9 years ago

Don't forget to open .hx file.

tjrhodes commented 9 years ago

ooops, nope, now we get the same [Errno 1] as the has changed on disk, so I think you must be close :)

/media/tom/Tome/001. WORK/NICK MORTIMER/IEDP Email App/production/src/server/Remote.hx 33279
Traceback (most recent call last):
  File "<string>", line 1, in <module>
PermissionError: [Errno 1] Operation not permitted: '/media/tom/Tome/001. WORK/NICK MORTIMER/IEDP Email App/production/src/server/Remote.hx'
ghost commented 9 years ago

Yes, I don't know why but this line causes the issue:

os.chmod(fn , os.stat(fn).st_mode | stat.S_IWRITE)

I'll try to fix that.

ghost commented 9 years ago

Meanwhile you can comment 1840, 1846, 1858 lines in HaxeComplete.py file if you know how to do that. This should fix the issue.

...
#os.chmod( temp , os.stat( temp ).st_mode | stat.S_IWRITE )
...
#os.chmod( fn , os.stat( fn ).st_mode | stat.S_IWRITE )
...
tjrhodes commented 9 years ago

Hi,

I've commented all the chmod lines (1840, 1846, 1858) and now I get...

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 359, in on_query_completions
res = callback.on_query_completions(v, prefix, locations)
  File "/home/tom/.config/sublime-text-3/Packages/Haxe/HaxeComplete.py", line 1822, in on_query_completions
comps,hints = self.get_haxe_completions( view , offset )
  File "/home/tom/.config/sublime-text-3/Packages/Haxe/HaxeComplete.py", line 1979, in get_haxe_completions
temp = self.save_temp_file( view )
  File "/home/tom/.config/sublime-text-3/Packages/Haxe/HaxeComplete.py", line 1841, in save_temp_file
shutil.copy2( temp , fn )
  File "./shutil.py", line 244, in copy2
  File "./shutil.py", line 190, in copystat
PermissionError: [Errno 1] Operation not permitted

ls -l shows the file like this...

-rwxrwxrwx 1 root root 19120 mag 13 16:53 Remote.hx

..which should be cool for anyone to do anything with, I chowned it from root to my user and retried, same error though.

ghost commented 9 years ago

Try to remove all .hx.tmp files in your file manager app.

clemos commented 9 years ago

It's really the copy operation that fails, which makes sense if the containing directory is owned by root... So I guess you should change that also. It also looks like this issue : https://github.com/clemos/haxe-sublime-bundle/issues/180 which involved Perforce, but I doubt it's related.

clemos commented 9 years ago

@r3a1ay I guess we should just try / catch this whole copy file part and return nothing + log an error in case anything goes wrong...

tjrhodes commented 9 years ago

Ok, I've removed the tmp file from the directory and I think it's working now, just added a couple of dummy functions to the file with no more has changed on disk popups and errors in the console! Thank you so much @r3a1ay .

@clemos That's without changing ownership of the parent directory btw. I was also getting these errors with files in my home directory on an EXT4 partition, so it's nto just the NTFS partition this particular file is in. Which gets mounted as root in fstab but allows anyone to do anything to it...

ghost commented 9 years ago

@clemos, it seams copy works without chmod. I don't know why.

If we save .hx file with python (to get completion in haxe compiler) without generating .tmp file, sublime shows 'file changed' message. Maybe we should wrap whole clear_temp_file and save_temp_file functions with try block. But this will cause issues with code completion.

ghost commented 9 years ago

I think we should check st_mode:

if os.stat( temp ).st_mode & stat.S_IWRITE == 0:
    os.chmod( temp , os.stat( temp ).st_mode | stat.S_IWRITE )

This will fix @tjrhodes's issue.

ghost commented 9 years ago

@tjrhodes, can you try to add this condition before all 'chmod' lines?


        if os.path.exists( fn ):
            if os.path.exists( temp ):
                if os.stat( temp ).st_mode & stat.S_IWRITE == 0:
                    os.chmod( temp , os.stat( temp ).st_mode | stat.S_IWRITE )
                shutil.copy2( temp , fn )
                os.remove( temp )
            # copy saved file to temp for future restoring
            shutil.copy2( fn , temp )

        if os.stat( fn ).st_mode & stat.S_IWRITE == 0:
            os.chmod( fn , os.stat( fn ).st_mode | stat.S_IWRITE )
        # write current source to file
        f = codecs.open( fn , "wb" , "utf-8" , "ignore" )
        f.write( src )
        f.close()

        return temp

    def clear_temp_file( self , view , temp ) :
        fn = view.file_name()

        if os.path.exists( temp ) :
            if os.stat( temp ).st_mode & stat.S_IWRITE == 0:
                os.chmod( temp , os.stat( temp ).st_mode | stat.S_IWRITE )
tjrhodes commented 9 years ago

@r3a1ay yup adding the if conditions to check st_mode works for me :)

ghost commented 9 years ago

Good news. That condition shouldn't cause any issue. I think we can use this fix.

ghost commented 9 years ago

@tjrhodes, thanks for your help with this issue.

tjrhodes commented 9 years ago

@r3a1ay no no, thankyou, really speedy response and very good work sorting it out.