oleg-shilo / codemap.vscode

Code map (syntax tree) of the active document
MIT License
84 stars 28 forks source link

Custom mapper doesn´t work #10

Closed Kampi closed 5 years ago

Kampi commented 5 years ago

I want to create a custom mapper for assembly language (primary goal) so I follow your example in the wiki to create a generic wrapper for a file extension (I try it with your markdown example first). My file main.x looks like this

# Test
### Test3

I have a mapper_X.js on my desktop (complete path C:\Users\Daniel\Desktop\mapper_X.js) "codemap.md": [ { "pattern": "^(\\s*)### (.*)", "clear": "##", "prefix": " -", "icon": "level3" }, { "pattern": "^(\\s*)## (.*)", "clear": "##", "prefix": " ", "icon": "level2" }, { "pattern": "^(\\s*)# (.*)", "clear": "#", "prefix": "", "icon": "level1" }, { "pattern": "!\\[image\\]", "clear": "![image]", "prefix": "<image>", "icon": "none" } ] VS code marks the ":" in '"codemap.md": [' red and say ";" expected. Why?

I also add "codemap.X": "C:\\Users\\Daniel\\Desktop\\mapper_X.js", to my settings.json. VS code marks codemap.X green and say Unknown configuration setting.

And I don´t get any result in my Code Map window with the above example.

What goes wrong here?

Thank you!

oleg-shilo commented 5 years ago

The idea of any extension configuration is that it is defined in the JSON not JS file. That's why you have a syntax error.

The config file is also must be present in the special location. Not in the desktop folder.

What you need to do is to use VSCode to start editing user settings. This will create the json file where you will need to paste your settings content.

swlsong commented 5 years ago

Could you please tell me what I am doing wrong. I first copied the definition of codemap.md to user settings, renamed it to codemap.X, and then created a test.X file where I input some markdown headlines, but they don't appear in the left pane. I make this trail to make the step as small as possible.

"codemap.X": [ { "pattern": "^(\s)### (.)", "clear": "###", "prefix": " -", "icon": "level3" }, { "pattern": "^(\s)## (.)", "clear": "##", "prefix": " ", "icon": "level2" }, { "pattern": "^(\s)# (.)", "clear": "#", "prefix": "", "icon": "level1" }, { "pattern": "!\[image\]", "clear": "![image]", "prefix": "", "icon": "none" }, { "pattern": "!\[\]", "clear": "![]", "prefix": "", "icon": "none" } ],

oleg-shilo commented 5 years ago

The following is an extract from Wiki that I have created to assist you and others in the situatuion like yours:


How To

Hint
When creating a custom generic mapper it is difficult to get it right from the first hit because your mapper will depend on the correctness of your regular expressions. Which in turn usually start working only after a few attempts. Thus it will be much easier if you implement a very generic mapper first and only then then start refining your regex patterns.

Creating simple generic mapper

Assume we need to create a mapper for the files with the extension '.x'. Follow these very simple steps.

The regex from the sample above was taken from the PowerShell syntax mapper:

"codemap.ps1": [
  {
    "pattern": "function \\w*",
    "clear": "function ",
    "suffix": "(...)",
    "icon": "function"
  }
],
swlsong commented 5 years ago

Thank you very much! It definitely helps step by step. Actually, I'm trying to use your excellent extension for the R language, and its scripts should be saved with the .R and not .r file extension. If I observe correctly, it seems not to work if the pattern suffix is in uppercase. Can you explain it, please?

"codemap.X": [ { "pattern": "function \w*", "icon": "function" } ],

swlsong commented 5 years ago

I accidentally found the solution. The pattern suffix doesn't need to be in the same case as the file extension. If I name the pattern as "codemap.x", and the file as "test.X", it works. If I name the pattern as "codemap.X", it doesn't. So, I can use your extension now. Thank you!

oleg-shilo commented 5 years ago

Great.

If you are happy with your R mapper, you can share it and I will include it into the default distro.

swlsong commented 5 years ago

Thank you for the encouragement. I won't dare to call my effort a R mapper, though. As an appreciation of your valuable extension, I want to show that even some most rudimentary pattern for the generic mapper can help a lot. With the following example, I get a wonderful list of functions or unit tests.

  "codemap.r": [
    {
      "pattern": ".*<-.*function.*",
      "icon": "function"
    },
    {
      "pattern": ".*test_that.*",
      "icon": "function"
    }
  ],
swlsong commented 5 years ago

I found the defined values for the key "icon" in your wiki and therefore deleted my question from my last comment.

icon - name of the predefined icon:

class interface function property document level1 level2 level3 none

oleg-shilo commented 5 years ago

Excellent, can you also share any realistic/representative R source that I can take, pass through the mapper and use the screenshot for the documentation? It would save me the time for chasing it online.

oleg-shilo commented 5 years ago

Don't worry. I got a good code sample now.

swlsong commented 5 years ago

Great, it's very kind of you. I would have used some scripts from the testthat package at https://github.com/r-lib/testthat/tree/master/R.

oleg-shilo commented 5 years ago

done. he latest version of CopdeMap contains default support for R.

https://github.com/oleg-shilo/codemap.vscode/blob/dd1c1102e0bc6fcb305024089ed61e5f6c753f8e/package.json#L81-L97

Though if you have your mapping defined in settings.json it will take the precedence over the default configuration. To check out the actual configuration you can execute the new "Show mappers" command:

image

swlsong commented 5 years ago

The new version is automatically installed. I love it and removed my pattern definition. Thank you!

oleg-shilo commented 5 years ago

Actually VSCode supposed not to remove custom user configuration on extension update. This si rather odd and... unfortunately outside of my control.

Though you can always restore your custom mapper patterns by specifying them (again) in the settings.json file.

swlsong commented 5 years ago

No, no, I myself have removed it because yours already does more than mine.

I want to share some information which is off topic in this issue. I newly switched to the portable version of vscode to avoid profile roaming. I noticed

AppData\Roaming\Code\User\codemap.user\syntaxer\1.2.1.0\syntaxer.exe

is currently the only piece that does not live in the data folder of the portable vscode.

oleg-shilo commented 5 years ago

No, no, I myself have removed it ...

Cool, then it makes sense :)

...is currently the only piece that does not live in the data folder...

Correct. syntaxer.exe is a server that is running in background and it needs to be deployed outside of extension dir so it does not interfere with the upgrading steps. When thy are executed.

CodeMap extension deploys it to the dedicated versioned sub folder of the VSCode user folder. The very same folder where persistent user settings are stored. And according VSCode documentation this folder is determined as below:

image

I am almost confident that even portable VSCode installation stores user data there as well.

swlsong commented 5 years ago

Thank you. It's very kind of you to response every time in great detail. I searched but didn't find settings.json in AppData\Roaming\Code and its subfolders. But you must know much more than me.

oleg-shilo commented 5 years ago

Not a problem. :)

You did not found settings.json probably because in case of portable install this file is stored somewhere else. I actually would appreciate if you tell me where exactly.

You can find it out by follow these very simple steps.

Now note the file full path VSCode active doc settings.json.

I am trying to get this info because syntaxer.exe is a user asset (similarly to settings.json) so it needs to be stored outside of the "extensions" folder and I simply don't know how VSCode solves the location problem for settings.json file. But if I do, then it can be an opportunity to store syntaxer.json at the same location.

swlsong commented 5 years ago

It's in <vscode directory>\data\user-data\User\settings.json.

oleg-shilo commented 5 years ago

Thank you.

swlsong commented 5 years ago

You are welcome and thank you again for your extension!

oleg-shilo commented 5 years ago

I am closing this issue but you can reopen it if any further help is required .