Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codemap generic mapper does not work with UTF-16 encoded files #33

Closed
TheBloke opened this issue May 3, 2020 · 10 comments
Closed

Codemap generic mapper does not work with UTF-16 encoded files #33

TheBloke opened this issue May 3, 2020 · 10 comments

Comments

@TheBloke
Copy link

TheBloke commented May 3, 2020

Hello

I just installed CodeMapper in VSCode 1.44.2 for Windows.

The extension seems to be working fine for supported languages, eg C#. But for some reason I am unable to configure the generic mapper to support a custom language.

I have tried following the example from the Wiki, and copied the example "codemap.x" configuration, renaming it "codemap.ws" as I wish to support files with a .ws extension. However my newly added variable "codemap.ws" is shown in settings.json to be invalid, and Codemap shows nothing when I test it on a sample file. I then tried copying the example in exactly, using "codemap.x", and it shows the same thing.

Here's a screenshot demonstrating my attempt to use both "codemap.ws" and "codemap.x" :
image

As you can see, both show as greyed out, and neither work on sample files with .ws or .x extensions.

I noticed on the Codemap extension configuration page that it has specific entries for Md, Ps1, Py and R , and if I try adding a settings.json value such as "codemap.md" or "codemap.ps1", these show as valid.

Apologies if I've done something wrong, or misunderstood something, or misread the Wiki. I am very new to VSCode.

Thanks in advance, and for creating Codemap, which looks to be exactly what I want - a way to get an outline view for a niche file extension.

PS. A separate issue, much less important - the Wiki and description talks of "Refreshing on demand via Refresh toolbar button"; I do not have any button in my Codemap bar except "Collapse All" :
image

@oleg-shilo
Copy link
Owner

The generic mapper may not work for two reasons:

  • Invalid setting file
  • invalid regex expression

So I always eliminate the first reason by adding the existing MD mapper but for a new file extension. And then opening the MD wile renamed into the extension I want.

So first ensure you are editing the right file and inserting the mapper value in the right place:

image

I suggest you also do it for the MD mapper (i have attached the file).
settings.zip

When you place the file in the C:\Users\<user_name>\AppData\Roaming\Code\User folder you can test it by opening any MD file renamed in the *.ws:

image

When you get it working you can start experimenting with your regex as your infrastructure is already working.
image

========================

And I will have a look at the missing refresh button. Txs

@oleg-shilo
Copy link
Owner

The new issue has been raised: #34

And fixed now.

@TheBloke
Copy link
Author

TheBloke commented May 4, 2020

Thanks very much for the fast reply, and for fixing issue #34.

OK, so I understand a lot better now. Firstly, I realise now that it is not a problem that "codemap.ws" shows as 'invalid' in settings.json, I can ignore this.

So the issue I have is that Codemap will for some reason not recognise the files I am trying to work with.

EDIT: I have identified the problem; my .ws files have UTF-16 LE encoding, and this does not seem to work with Codemap? If I re-save the files as UTF-8, it works immediately. See next comment.

First, here's a working example: I followed your suggestion and copied "codemap.md" settings to "codemap.ws", and then renamed a .md file to .ws. This worked fine. Then I edited the settings to include a couple of simple regexes, and confirmed this also worked fine in my test file, as shown here:
image

  • In right hand split, settings.json with some test config
  • In middle split, test file (started out as MD file then renamed to .ws, and test enum/functions added)
  • On left, Codemap is recognising the function and enum entries from this test file.

So that's all perfect.

But then when I try with a real .ws file, I get nothing:
image

So I am thinking there must be some issue specific to the files I'm trying to load?

Could it be because these files are in UTF-16 format? I don't know if that affects your code, but I do know I had trouble when I was trying to grep these files on a Solaris system, due to the unusual file encoding.

image

Below I have attached one of the files I am trying to work with. Would you be able to have a look to see whether it works for you, and if not, what the problem might be?

playerTypes.ws.zip

And here is the basic config that I am testing with, which should pick out the enum and function definitions from that file:

"codemap.ws": [
        {
            "pattern": "function \\w*",
            "clear": "function",
            "prefix": "",
            "icon": "function"
        },
        {
            "pattern": "enum \\w*",
            "clear": "enum",
            "prefix": "",
            "icon": "function"
        }
    ]

Thanks so much again for your time in helping me.

@TheBloke
Copy link
Author

TheBloke commented May 4, 2020

Could it be because these files are in UTF-16 format? I don't know if that affects your code, but I do know I had trouble when I was trying to grep these files on a Solaris system, due to the unusual file encoding.

This is the problem!

I just saved one of my .ws files as UTF-8, and immediately Codemap worked with it:
image
image

So, is there any way that Codemap could support UTF-16 LE files? Unfortunately I have to work with this encoding, as I am writing modifications to existing code, and all the files are UTF-16 LE.

Thanks again.

@TheBloke TheBloke changed the title Can't configure generic mapper Codemap generic mapper does not work with UTF-16 encoded files May 4, 2020
oleg-shilo pushed a commit that referenced this issue May 6, 2020
* Issue #33: Codemap generic mapper does not work with UTF-16 encoded files.
Changed (from reading doc content from the file) to reading the doc content from the text editor buffer. So no dependency on the file encoding.Fix
@oleg-shilo
Copy link
Owner

Can you check this patch before I publish it. It should fix your problem:

Uploading codemap-1.11.2.vsix.zip…

@TheBloke
Copy link
Author

TheBloke commented May 6, 2020

Thanks very much for making the fix. I'd be glad to test it.

The ZIP doesn't seem to be downloadable at the moment? Did it upload OK? For me it shows like this:

image

@TheBloke
Copy link
Author

TheBloke commented May 6, 2020

I've grabbed the updated file from the source repo, going to try putting it in place now. One minute..

@TheBloke
Copy link
Author

TheBloke commented May 6, 2020

It works! I now have enums and functions visible on my UTF-16 .ws files.

I got a few errors when I manually compiled mapper_generic.ts to mapper_generic.js, but the resulting .js file still seems to work fine (and I'm sure these errors are just because I manually compiled it in out/src)

So yes, please could you push this to an official release.

Thanks very much for the fast resolution!

@oleg-shilo
Copy link
Owner

Great. Will publish in a min

@oleg-shilo
Copy link
Owner

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants