oleg-shilo / sublime-codemap

CodeMap - is a ST3 plugin for showing the code tree representing the code structure of the active view/document
MIT License
41 stars 4 forks source link

Issues modifying existing custom mappers - python, for example #17

Closed Acecool closed 2 months ago

Acecool commented 6 years ago

I'm not sure what happened, but I modified the python custom mapper to show arguments, and simple error checking ( missing :s for class and function definitions ) notifications and I put it into Packages/User/CodeMap/custom_mappers/

It used to work, but I'm guessing an update changed that ( or something else happened ) because everything stopped working, including my partial universal mapping script, the Lua rules I defined, etc... I had to uninstall, reinstall, re-extract, delete the extracted, extract, delete the installed-packages file, reinstall, extract and alt + m 10 + times in order for the Lua one to work again ( code wasn't changed on my end so I know it isn't an issue there )...

But the modified python one I wrote doesn't load at all, and I didn't modify the code so I know it is working but I still took your original and added a simple concatenated message to the generate return and it doesn't show up.

Do the mappers not load in this order: if user/CodeMap/custom_mappers/.. exists then use it, else Packages/CodeMap/custom_mappers/.. then use it else InstalledPackages/CodeMapFile.... ?

Even deleting the extracted Packages/CodeMap/ mappers did nothing, even installing and using only the extracted CodeMap plugin did nothing...

I even tried modifying the non User/ extracted Packages folder and it just doesn't show up... Any ideas why? And, if it wasn't clear, I even tried running it without extracting it ( but if I don't extract the plugin then the User/CodeMap/ folder doesn't work for custom mappers... ).

Acecool commented 6 years ago

This can be closed - nothing works in Users/CodeMap/* if I install CodeMap and don't extract it, there is that issue....

But, I was able to extract it and edit codemap.sublime-settings and remove python from syntaxes table and then it loaded it from custom mappers...

Acecool commented 6 years ago

I also found a copy of custom_mappers/ python in CodeMap/code_map_support.py - why are there 2 copies of the same code - the purpose of coding it to limit repetitions in code? I'd recommend keeping it in the custom_mappers/ folder and not loading the same thing from 2 locations - CodeMap/custom_mappers/python.... Users/CodeMap/custom_mappers/python ( copied by me to alter it ) and CodeMap/code_map_support.py

oleg-shilo commented 6 years ago

The problem was introduced with the recent PR (SHA-1: a1f206cde84ccbf372136cbf0bbfdf605dffbce6). It leads to the failure to deploy sample custom mappers on startup and unpredictable runtime state of the whole plugin.

Unfortunately this type of problems is very difficult to catch as ST does not offer an easy troubleshooting of compressed packages. Note that ST team insisted on distributing this package in a compressed form.

This can be closed...-

No. It should not be closed. The exhibited behavior is wrong. I have marked the issue as a "bug" and it will be fixed very soon.

...why are there 2 copies of the same code - the purpose of coding it to limit repetitions in code...

:) You probably already guessed that repetition is not intended and rather a result of the PR merge mistake.

Thank you for reporting the problem.

mg979 commented 6 years ago

@Acecool

But, I was able to extract it and edit codemap.sublime-settings and remove python from syntaxes table and then it loaded it from custom mappers...

In the readme it is stated: Note that if you use a custom mapper for an extension that is already defined in the universal mapper settings, the latter will have precedence. Comment out the extension in the universal mapper section to use your custom mapper in its place.

You don't need to extract anything. In CodeMap settings, python is among he included extensions for the universal mapper, as such it will override the custom python mapper. To use the custom python mapper, you need to comment out python from the universal mapper extensions in CodeMap settings, as you found out.

You just have to edit CodeMap settings, no need to extract anything. You can use Side-by-Side Settings to edit settings, it will spare you some trouble.

Otherwise, you can do that from Preferences -> Package Settings -> CodeMap -> Settings - User. Open also Settings - Default, there you have:

    "syntaxes":     [
                        ["universal",   ""],
                        ["text",        "txt"],
                        ["python",      "py"]
                    ],

Copy it in user settings, and comment out the python line.

@oleg-shilo

The problem was introduced with the recent PR (SHA-1: a1f206c). It leads to the failure to deploy sample custom mappers on startup and unpredictable runtime state of the whole plugin.

This isn't really a bug, it's working as intended. First, the extensions of the universal mapper are checked, custom mappers are used only if they are not in that list. It could have been the other way around (first check custom mappers, then universal mapper) but I think it's much better this way. If you want to use the custom mapper, just comment out the thing in the settings. Otherwise, you would really need to extract and delete the custom mapper, if you wanted to use the regex instead.

Acecool commented 6 years ago

Found that and added it to my normal config so hopefully it won't override mine....

oleg-shilo commented 6 years ago

@mg979

This isn't really a bug...

Sorry. It is. ;) The code tries to prepare a copy of the included dedicated mappers and fails because there is a syntax error: two brackets next to the string variable. Though it is not a show stopper. I agree.

Anyway, I just wanted to stress that the plugin can use two types of mappers:

  1. dedicated custom mapper (python file for parsing/mapping specific syntax)
  2. universal mapper (regex based engine that uses patterns defined in settings file for parsing/mapping)

Thus for the universal mapper you indeed don't have to extract anything as the parsing algorithm is defined in the settings file.

And for the dedicated mappers you don't need to extract anything neither as the plugin does the extraction for you. Except... the version that you used had a defect that prevented the extraction. That's why your manual extraction has helped. BTW the latest release has the extraction problem fixed.