facelessuser / ApplySyntax

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

Does not work with Sublime Text 3 (build 3059) #58

Closed mbrodala closed 10 years ago

mbrodala commented 10 years ago

Either I am doing something fundamentally wrong, or this plugin does not work with the lastest stable Sublime Text 3. Neither my custom syntaxes nor the default syntaxes seem to be applied.

For example the INI-Syntax is not applied to Git files, even though I have the corresponding Syntax-Package (clintberry/sublime-text-2-ini) installed.

What might be the issue here?

The only hint I get from Sublime is from the Console:

Unable to open /C/Users/<me>/AppData/Roaming/Sublime Text 3/Packages/ApplySyntax/ApplySyntax.sublime-settings
facelessuser commented 10 years ago

How did you install it? It should be working. The last changes were done 7 days ago, and you are the first to complian. Also, I only use ST3 and it seems to be working for me. Did you alter your settings file and corrupt it?

facelessuser commented 10 years ago

I think the issue is now solved. Some one was able to give me some info. Let me know if things are good for you after you update.

mbrodala commented 10 years ago

I cannot seem to upgrade to the latest version and am still on 2014.06.15.21.45.49. What was the previous ST3 version before the current 2014.06.29.05.47.29? I'd like to rule out errors in PackageControl (maybe it has installed the ST2 version?)

mbrodala commented 10 years ago

Now I have a more verbose error message for you:

reloading plugin ApplySyntax.ApplySyntax
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "X/importlib/__init__.py", line 88, in import_module
  File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1525, in _find_and_load_unlocked
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 671, in load_module
    exec(compile(source, source_path, 'exec'), mod.__dict__)
  File "ApplySyntax in C:\Users\<me>\AppData\Roaming\Sublime Text 3\Installed Packages\ApplySyntax.sublime-package", line 309, in <module>
  File "ApplySyntax in C:\Users\<me>\AppData\Roaming\Sublime Text 3\Installed Packages\ApplySyntax.sublime-package", line 41, in ensure_user_settings
FileNotFoundError: [Errno 2] No such file or directory: 'User\\ApplySyntax.sublime-settings'

Maybe this helps.

facelessuser commented 10 years ago

Your error shows that on line 41 it is failing. On the ST3 branch line 41 is checking if a path exists; this would not cause the error you are seeing, but would exit cleanly. On the ST2 branch, line 41 is trying to create a file; this would cause an error.

So what does this mean? You are using the wrong branch.

You need to use the ST3 branch. Install via Package Control to ensure you get the correct branch. This is why you are failing

mbrodala commented 10 years ago

Guess what I did. ;-) No idea why Package Control keeps fetching the ST2 package instead of ST3.

facelessuser commented 10 years ago

You can see I have it configured in Package Control correctly: https://github.com/wbond/package_control_channel/blob/master/repository/a.json#L606 EDIT:(reference is dead since the file has since been updated, but you can search the file and see).

The only other thing I can suggest is maybe posting your PackageControl.sublime-settings here so I can see if anything looks funny. If I can't see anything obvious there, you will need to take it up with the PackageControl maintainer.

mbrodala commented 10 years ago

I am sure that you haven't done anything wrong but I'd still like to know whats happening. My user settings for Package Control are as boring as it can get:

{
  "auto_upgrade_last_run": null,
  "installed_packages":
  [
    "ApplySyntax",
    "DocBlockr",
    "Hipster Ipsum",
    "INI",
    "LESS",
    "Package Control",
    "PHP Completions Kit",
    "Puppet",
    "Random HEX Color"
  ]
}

Do you also need my default settings?

facelessuser commented 10 years ago

Sorry I missed this. I don't see anything wrong with your settings. Sadly, I can't be much more help. If it was an error on my part, I would gladly fix, but I afraid there is nothing more I can do from my end. You could probably manually install it, but you would then have to manually update as well.

mbrodala commented 10 years ago

I now went the full route: I downloaded your latest ST3 revision from Github, manually created a package-metadata.json, repackaged it to .sublime-package and overwrote mine. Now it seems to show up and load properly, at least some Git files now have the INI syntax set.

Issue is: ApplySyntax still shows up as upgradable package in Package Control and according to the versions, this would actually downgrade my ST3 version 2014.07.15.02.13.20 to the ST2 version 2014.06.15.21.45.49. Should I ask the Package Control maintainers instead? :-/

But my original goal was getting automatic syntax setting for TypoScript files with .txt endings to work. As it still doesn't, could you maybe give me a hint what's wrong with the following setup:

{
  "syntaxes": [
    {
      "name": "TypoScript",
      "rules": [
        {"file_name": ".*constants\\.txt"},
        {"file_name": ".*setup\\.txt"},
        {"file_name": ".*ext_typoscript_constants\\.txt"},
        {"file_name": ".*ext_typoscript_setup\\.txt"}
      ]
    }
  ]
}

I do have a TypoScript.tmLanguage for this but the mentioned files remain on plain text.

Please redirect me to the proper location to ask such questions if there is one. ;-)

GoOz commented 9 years ago

@mbrodala Did you ever find the solution? I have the exact same issue. Package installed (multiple times to be sure) with Package Control, ApplySyntax appears in installed package but still the same errors you had.

mbrodala commented 9 years ago

Nope, the issue remains and i still have to manually switch syntax for the affected files.

KES777 commented 9 years ago

I also switch syntax type manually (

facelessuser commented 9 years ago

Has anyone tried manually installing ApplySyntax? The original issue looks to have been throwing an error that only ST2 branch would throw. But if Package Control is installing the wrong this would circumvent the issue and allow us to verify that the correct branch either causes an issue or doesn't. Make sure to uninstall via package control first.

Another issue is that people keep getting confused about how to specify the name. I've recently spent some time updating the docs to make these things more clear http://facelessuser.github.io/ApplySyntax/usage/#name. Please do read them and let me know if things aren't clear. But name requires the relative packages path (PackageName/sub-directories/if-any/language-file-without-extension) and file name (extension not needed, and please use forward slashes /).

TypoScript is not sufficient as it is just pointing at a package directory. What if two packages have TypoScript.tmLanguage?

ApplySyntax used to translate TypoScript to TypoScript/Typoscript but that confused people as you could also directly say TypoScript/Typoscript . So now it is always explicit and consistent.

Now that Sublime is adding a new language format, sublime-syntax I may make the extension explicit moving forward.

mbrodala commented 9 years ago

@facelessuser Thanks for the details, I really appreciate this. Is there some way to debug what syntax was detected or expected? I still have no luck with TypoScript, TypoScript/TypoScript or User/TypoScript. My TypoScript.tmLanguage lives in Packages/User/TypoScript.tmLanguage.

My latest attempt:

{
  "syntaxes": [
    {
      "name": "TypoScript/Typoscript",
      "rules": [
        {"file_name": ".*(constants|setup)\\.txt$"},
        {"file_name": ".*ext_typoscript_(setup|constants)\\.txt$"}
      ]
    }
  ]
}
facelessuser commented 9 years ago

If your package lives at Packages/User/TypoScript.tmLanguage why are you doing TypoScript/Typoscript? Based on what I mentioned earlier PackageName/sub-directories/if-any/language-file-without-extension, you need to do User/TypoScript. Hope that makes sense.

mbrodala commented 9 years ago

Because I wanted to be sure to try everything. And as I said User/TypoScript doesn't work either.

KES777 commented 9 years ago

in ApplySyntax.py there is debug( command, but nothing is logged because of this code "if no Path continue" in 'def set_syntax' function. Also you may set 'dev_enabled' and 'debug_enabled' (I do not remember right, please open ApplySyntax.py and look for 'def debug' 'def devlog'. You can find sharp names there)

Describe in DOC please that "name": ["RSpec", "RSpec (snippets and syntax)/Syntaxes/RSpec"] "RSpec" means "Packages/RSpec.tmLanguage" "RSpec (snippets and syntax)/Syntaxes/RSpec" means "Packages/RSpec (snippets and syntax)/Syntaxes/RSpec.tmLanguage"

You can continue implicit suggestion while name without slash. So if name : "Perl" if( loadresources( 'Packages/Perl.tmLanguage' ); ) OK else if( loadresources( 'Packages/Perl/Perl.tmLanguage' ); ) OK else debug 'No Perl tmLanguage';

mbrodala commented 9 years ago

Thanks for the hint to add debug_enabled and dev_enabled to the user settings. Now I get this on console:

ApplySyntax: Language Hash - '8849373952597948661'
ApplySyntax: Updating Extensions
ApplySyntax: Found Extensions: XML/XML - ['xml.dist']
ApplySyntax: Found Extensions: Rails/Ruby Haml - ['haml']
ApplySyntax: Found Extensions: Ruby/Ruby - ['thor', 'rake', 'simplecov', 'jbuilder', 'rb', 'podspec', 'rabl']
ApplySyntax: Found Extensions: Ruby Slim/Syntaxes/Ruby Slim - ['emblem']
ApplySyntax: Found Extensions: Blade/Blade - ['blade.php']
ApplySyntax: Found Extensions: PHP/PHP - ['php3', 'php4', 'php5', 'inc', 'phtml']
ApplySyntax: Found Extensions: PHP/Smarty - ['tpl']
ApplySyntax: Found Extensions: YAML/YAML - ['.gemrc', 'yml', 'yml.dist']
ApplySyntax: Found Extensions: INI/INI - ['.gitattributes', '.gitconfig', '.gitignore', 'ini.dist', '.npmrc']
ApplySyntax: Found Extensions: ShellScript/Shell-Unix-Generic - ['bash', 'sh', 'zsh']
ApplySyntax: Found Extensions: Python/Python - ['py3', 'pyw']
ApplySyntax: Prunning Extensions

My TypoScript.tmLanguage is not detected at all even though it was installed as regular package through Package Control and ended up in Packages/User/.

Interesting to note that the README of the TypoScript syntax package now includes this hint for ApplySyntax:

Supported files

The package will apply the syntax to *.ts files. You can create your own rules using the ApplySyntax package with this configuration:

{
    "syntaxes": [
        {
            "name": "TypoScript/TypoScript",
            "rules": [
                {"file_name": ".*\\\\ext_conf_template\\.txt$"},
                {"file_name": ".*\\\\ext_typoscript_(setup|constants)\\.txt$"},
                {"file_name": ".*\\\\(setup|constants)\\.txt$"}
            ]
        }
    ]
}

I have tried this very snippet but to no avail.

facelessuser commented 9 years ago

@mbrodala The problem I am having is I need to know exactly what your setup is. TypoScript gives an example of what to do, but you have told me that you keep your TypoScript in another location. I need excact info. Provide me with files and everything I need to know to try and reproduce your situation.

My TypoScript.tmLanguage is not detected at all even though it was installed as regular package through Package Control and ended up in Packages/User/.

  1. That debug info is specifically dealing with the extensions keyword in rules.
  2. Your rule is using patterns to apply syntax to files named ext_conf_template.txt, ext_typoscript_setup.txt, ext_typoscript_constants.txt, setup.txt, and constants.txt. If you are hoping it will catch *.ts files, the rules are not configured to do that, so if that is your problem, you need more rules.
  3. The rules above specifically are for windows paths as they are using backslashes, you may need to add forward slash rules if you are on Linux or OSX.
  4. Package Control never installs plugins in Packages/User, they are installed in Packages, if they are in User, then some script has copied them there. You just mentioned that the TyppoScript plugin specifically tells the user to use the name TypoScript/TypoScript, this tells me it isn't supposed to be in User.

So I ran a test since finally pointed me at the repo you are using for TypoScript. This is what I did, and these are my results:

  1. Install https://packagecontrol.io/packages/TypoScript via Package Control.
  2. I added to the syntaxes list in my settings file the following rule:

    {
           "name": "TypoScript/TypoScript",
           "rules": [
               {"file_name": ".*\\\\ext_conf_template\\.txt$"},
               {"file_name": ".*\\\\ext_typoscript_(setup|constants)\\.txt$"},
               {"file_name": ".*\\\\(setup|constants)\\.txt$"}
           ]
       }
  3. Create a file called setup.py on my Desktop.
  4. Open setup.py in Sublime Text.
  5. File opened with syntax TypoScript

I have no User/TypoScript.tmLanguage; neither Package Control or the plugin itself created a file in that location.

This is on Windows7 x64 on Sublime Text Build 3084.

TypoScript and ApplySyntax are working fine for me. If you want Linux or OSX support either modify paths to use forward slashes or add new rules that use forward slashes under the windows variants. If you want *.ts support, then create a new rule that will trigger on *.ts files.

facelessuser commented 9 years ago

@KES777

Please create a separate issue for documentation issues. I will not address issues that are not in an open, relevant issue. But thank you for taken time to find some of the inconsistencies.

Documentation is still being improved via issue #72, so there is probably still incorrect info. If you create an issue, I will correct those mistakes. For instance, despite what the documentation says, Rspec is incorrect. The actual, official rule does not use that syntax, but uses what I described earlier:

        {
            // One could use just the second rule to match every ruby file in a /spec/
            // directory, but I prefer to be more explicit.
            "name": ["RSpec/RSpec", "RSpec (snippets and syntax)/Syntaxes/RSpec", "Better RSpec/Better RSpec"],
            "rules": [
                {"file_name": ".*spec\\.rb$"},
                {"file_name": ".*/spec/.*\\.rb$"},
                {"file_name": ".*\\\\spec\\\\.*\\.rb$"}
            ]
        },

So create a new issue, and I will correct the mistakes.

mbrodala commented 9 years ago

@facelessuser Thanks a lot for your info and pointing out my weird User path over and over again. Apparently exactly that was the issue; I removed the language file from there and properly installed it via Package Control again. Now it lives in Installed Packages and the following setting works:

{
  "syntaxes": [
    {
      "name": "TypoScript/TypoScript",
      "rules": [
        {"file_name": ".*(\\\\|/)ext_conf_template\\.txt$"},
        {"file_name": ".*(\\\\|/)ext_typoscript_(setup|constants)\\.txt$"},
        {"file_name": ".*(\\\\|/)(setup|constants)\\.txt$"}
      ]
    }
  ]
}

(Slightly adjusted to support both Windows and Unix paths.)

As for your questions: 2. No, I have manually assigned TypoScript as syntax for *.ts files through Sublime.

Once again, thanks a lot. :-)

facelessuser commented 9 years ago

Thanks a lot for your info and pointing out my weird User path over and over again.

I have found learning by repetition very effective :smile:.

I know it took forever to get this resolved for you, but I am glad things are finally working for you.