facelessuser / ApplySyntax

Syntax detector for Sublime Text
https://facelessuser.github.io/ApplySyntax/
343 stars 48 forks source link

After updating my rails syntax isn't detected anymore #7

Closed mhenrixon closed 11 years ago

mhenrixon commented 11 years ago

Something must have changed recently to break how rails syntax was found and set. Any ideas?

ApplySyntax: Syntax file for Ruby on Rails does not exist at Packages/Rails/Ruby on Rails.tmLanguage

No wonder ST3 doesn't keep packages that way anymore. I don't want to have to copy language files to that directory for every syntax I want to support. So how can we fix this?

So I tried installing it from the package manage:

Traceback (most recent call last): File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 207, in on_load callback.on_load(v) File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Installed Packages/ApplySyntax.sublime-package/ApplySyntax.py", line 63, in on_load self.detect_syntax(view) File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Installed Packages/ApplySyntax.sublime-package/ApplySyntax.py", line 80, in detect_syntax if self.syntax_matches(syntax): File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Installed Packages/ApplySyntax.sublime-package/ApplySyntax.py", line 140, in syntax_matches result = self.function_matches(rule) File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Installed Packages/ApplySyntax.sublime-package/ApplySyntax.py", line 201, in function_matches function = self.get_function(path_to_file, function_name) File "/Users/mhenrixon/Library/Application Support/Sublime Text 3/Installed Packages/ApplySyntax.sublime-package/ApplySyntax.py", line 173, in get_function with open(path_to_file, "r") as f: FileNotFoundError: [Errno 2] No such file or directory: 'ApplySyntax/is_rails_file.py'

facelessuser commented 11 years ago

I am not sure what your problem is yet. First are you using the ST3 branch? The ST3 branch can find and use syntax files inside of sublime-packages. You can ignore Packages/Rails/Ruby because ST3 takes that path and resolves it internally using load_resources so that output can be a bit misleading. I use ST3 right now, and I have tested Rails and it seems to work fine. I don't think you are using the correct ST3 branch at all because your debug output lines don't match with the ST3 branches source code, but instead matches with ST2 branches source.

In short, use the ST3 branch and report back.

mhenrixon commented 11 years ago

hmm so odd I deleted PM installed version and re-cloned from git and checked out the ST3 branch again (just like I had it before pulling changed on the ST3 branch and now everything was back to working again). The git pull must have gotten messed up or something. Maybe I pulled from master, that would explain it. I've done it before.

ngocphamm commented 11 years ago

I have this problem again even though I checked out "ST3" branch.

ApplySyntax: Syntax file for ApacheConf does not exist at Packages/ApacheConf/ApacheConf.tmLanguage

This is what I've done:

 ~/Library/Application Support/Sublime Text 3/Packages ⮀  git clone git://github.com/facelessuser/ApplySyntax.git
Cloning into 'ApplySyntax'...
remote: Counting objects: 230, done.
remote: Compressing objects: 100% (115/115), done.
remote: Total 230 (delta 135), reused 205 (delta 114)
Receiving objects: 100% (230/230), 36.86 KiB | 0 bytes/s, done.
Resolving deltas: 100% (135/135), done.
 ~/Library/Application Support/Sublime Text 3/Packages ⮀  cd ApplySyntax
 ~/Library/Application Support/Sublime Text 3/Packages/ApplySyntax ⮀ ⭠ master  ⮀  git checkout ST3
Branch ST3 set up to track remote branch ST3 from origin.
Switched to a new branch 'ST3'
 ~/Library/Application Support/Sublime Text 3/Packages/ApplySyntax ⮀ ⭠ ST3  ⮀
facelessuser commented 11 years ago

Apply Syntax only sets the syntax. Some of the syntaxes in the settings you have to install yourself via PackageControl. Apply Syntax does not add any new syntaxes to your Sublime Text install.

ngocphamm commented 11 years ago

I did installed the ApacheConf package but it goes to Installed Packages folder. This is the problem of ApplySyntax not be able to read from this folder and .sublime-package file, I suppose.

facelessuser commented 11 years ago

Apply Syntax can read from Installed Packages just fine. I added that code myself and use it as well. The problem is that the Apache package is installed with a different name now than it probably was at the time the setting was added. You need to change the setting to look for ApacheConf not Apache.

If that works for you, you can create a pull request.

ngocphamm commented 11 years ago

Could you please send me the zip file of the ApplySyntax you are using?

I'm not a Pythonist but I tried to read the code at https://github.com/facelessuser/ApplySyntax/blob/ST3/ApplySyntax.py. It doesn't really reveal anything related to using Syntax file installed inside Installed Packages/.

Of course I changed the detecting rule to ApacheConf. See below.

"syntaxes": [
        {
            // This doesn't really need to be here as ST2 identifies Apache files correctly, but I leave it
            // for instructional value
            "name": "ApacheConf",
            "rules": [
                {"file_name": "^.*(\\.htgroups|\\.htpasswd|httpd\\.conf|_htaccess|htaccess\\.txt)$"}
            ]
        }
    ]

And this is what inside Installed Packages

 ~/Library/Application Support/Sublime Text 3/Installed Packages ⮀  ll
total 5080
drwxr-xr-x  13 ngocpham  staff      442 Jun 19 05:09 .
drwxr-xr-x   7 ngocpham  staff      238 Jun 15 19:10 ..
-rw-r--r--   1 ngocpham  staff     5889 Jun 18 15:36 ApacheConf.tmLanguage.sublime-package
-rw-r--r--   1 ngocpham  staff     3030 May  6 21:15 ChangeQuotes.sublime-package
-rw-r--r--   1 ngocpham  staff    29698 Jun 19 05:09 DocBlockr.sublime-package
-rw-r--r--   1 ngocpham  staff   156486 Jun 14 06:52 Emmet.sublime-package
-rw-r--r--   1 ngocpham  staff    35943 May 12 11:49 GitGutter.sublime-package
-rw-r--r--   1 ngocpham  staff     2245 Jun  2 09:32 INI.sublime-package
-rw-r--r--   1 ngocpham  staff    15446 May 20 23:16 Phpcs.sublime-package
drwxr-xr-x   3 ngocpham  staff      102 May  6 21:22 PyV8
-rw-r--r--   1 ngocpham  staff     1988 May  8 21:26 SublimeBlockCursor.sublime-package
-rw-r--r--   1 ngocpham  staff  2241686 Jun  5 22:52 Theme - Nil.sublime-package
-rw-r--r--@  1 ngocpham  staff    87256 May 25 23:31 Vintageous.sublime-package
 ~/Library/Application Support/Sublime Text 3/Installed Packages ⮀
facelessuser commented 11 years ago

Sublime text takes care of "Installed Packages" if you use the format Packages/Plugin/mysyntax.tmLanguage.

Here you see I use load_resources to see if the file exists. Load resources can read files in installed packages zip archives. If it throws an error, I know it doesn't exist. If there is no error, I continue loading the syntax

            try:
                sublime.load_resource(new_syntax)
                self.view.set_syntax_file(new_syntax)
                log('Syntax set to ' + name + ' using ' + new_syntax)
            except:
                log('Syntax file for ' + name + ' does not exist at ' + new_syntax)

As for your problem, I made a mistake. I didn't realize that "tmLanguage" was now alos part of the package name. This works, I verified it myself (this looks in the package ApacheConf.tmLanguage for a tmLanguage file called ApacheConf):

{
            // This doesn't really need to be here as ST2 identifies Apache files correctly, but I leave it
            // for instructional value
            "name": "ApacheConf.tmLanguage/ApacheConf",
            "rules": [
                {"file_name": "^.*(\\.htaccess|\\.htgroups|\\.htpasswd|httpd\\.conf)$"}
            ]
        }
ngocphamm commented 11 years ago

Yeah. That works! Thank you for your attention. :+1: