alefragnani / vscode-project-manager

Project Manager Extension for Visual Studio Code
GNU General Public License v3.0
1.93k stars 224 forks source link

[BUG] - Unable to load projects.json when using UTF8 with BOM #676

Closed claudiospizzi closed 1 year ago

claudiospizzi commented 1 year ago

If the projects.json is stored as UTF8 with BOM, the extension will throw the following error:

Error loading projects.json file. Message: SyntaxError: Unexpected token  in JSON at position 0

Environment/version

Steps to reproduce

  1. Execute command Project Manager: Edit Projects
  2. Execute command Change File Encoding > Save with Encoding > UTF8 with BOM for file projects.json
  3. Restat VS Code, the error will appear after the extension is loaded
alefragnani commented 1 year ago

Hi @claudiospizzi ,

Is there any reason why you did decide to change projects.json encoding? Did you have any issue with the file in its default encoding?

I’m using Node fs, and its default encoding is UTF8. Nothing special is being made in the file, so there is no reason to add support to alternative encoding, neither for loading nor saving.

Thanks for your understanding.

claudiospizzi commented 1 year ago

Hi @alefragnani

I use a two-level folder structure to organize all my repositories and VS Code projects. My repo/project counts go's far over 100, so I don't want to manage all project in the VS Code Project Manager module by hand and wrote a small command to patch the projects.json based on my two-level folder structure.

This is an example workspace structure, where I will create a project for every repo and attack tasks to represent all the folders.

~/Workspace/
    Personal/
        Repo1/
        Repo2/
    Work/
        Repo3/
        Repo4/

This is my command: Update-Workspace

The issue now, the Windows PowerShell command Set-Content to set file content uses UTF8 with BOM instead of using UTF8 without BOM. There is no native way to remove the BOM.

I just thought someone else would stumble across this issue too and it's worth checking/fixing. If you use fs, just replacing the BOM characters or trim the string after reading from file but before parsing the JSON should fix it.

Anyway, as you probably won't fix, I'll patch my command to strip away the BOM bytes at the beginning of the file. So, for me it's resolved, as I'll have a workaround.

--

P.S. Thank you for developing and maintaining this awesome module! I use it a lot in my coding workflow on a daily basis, really cool. :-)

alefragnani commented 1 year ago

Oh, I see. Well, if you have an well defined structure for your projects, maybe you could use the auto-detect feature.

The extension can automatically detect Git, Mercurial and SVN repos, VSCode projects or any basic folder, and presents the projects for you inside VACode. Simply use the projectManager.XXX.baseFolders settings, one for each kind of project. You can do ignore folders and delimit depth for search. More details https://github.com/alefragnani/vscode-project-manager#available-settings.

These auto-detectes projects has its own Panel in Project Manager Side Bar, but are all merged in the List Projects to Open commands. And you can't define Tags for them (yet).

Maybe this would work for you.

Hope this helps.

Ps. Thank you for your kind words. I'm glad to know the extension is being helpful.