vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Support alternate encodings of CMakePresets.json

Open eladmaimoni opened this issue 3 years ago • 4 comments

I created a new cmake project using Visual Studio 2022 that targets both Windows and WSL-2.

Visual Studio 2022 generated a default CMakePresets.json file that contains default cmake presets for linux and Windows named linux-default and windows-default respectively.

Configuring and building the project works both via Visual Studio and via Visual Studio Command Prompt, for example:

cmake --preset=linux-default

However, when opening the same folder in Visual Studio Code, I can't view and choose one of the existing presets.

When I open the "Select Configure Preset" menu it is empty. I don't see any presets available. I only have an option to add a new preset.

image

Furthermore, if I try to add a new preset, it overrides the content of CMakePresets.json.

So how can I choose one of the pre existing presets? is this a bug?


UPDATE

It seems that somehow the json parser fails to work properly. This is what I see in the output window:

[presetController] Failed to parse CMakePresets.json: 
	SyntaxError: Unexpected end of JSON input
	at JSON.parse (<anonymous>)
	at PresetsController.parsePresetsFile (c:\Users\mrmai\.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:60445:36)
	at PresetsController.resetPresetsFile (c:\Users\mrmai\.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:59782:38)
	at async PresetsController.reapplyPresets (c:\Users\mrmai\.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:59797:9)
	at async FSWatcher.<anonymous> (c:\Users\mrmai\.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:59711:17)

It happens regardless of the actual content of the json file. It seems the problem a problem with the file encoding. If I edit it with notepad++ and save it with utf-8 encoding, the parsing works. but if I slightly change it with VS Code the parsing error occurs.

eladmaimoni avatar Dec 28 '21 14:12 eladmaimoni

What encoding are you using? We only support UTF-8 right now. You can also change the encoding in VS Code by clicking the encoding label on the status bar: image

bobbrow avatar Dec 28 '21 16:12 bobbrow

@bobbrow Thanks I wasn't aware of this option. Still I think it is worth fixing. It happened to me on a freshly installed VS Code & Extensions and it is very hard to figure out what is wrong.

eladmaimoni avatar Dec 29 '21 09:12 eladmaimoni

I tried to reproduce this issue by creating a new CMake Project using Visual Studio 2022. It created CMakePresets.json with UTF-8 with BOM encoding which I could load successfully in VS Code. @elad8a Maybe your VS installation uses a different encoding (e.g. UTF-16) by default?

chausner avatar May 14 '22 22:05 chausner

Okay, it seems the BOM was likely the cause and support for it has already been added in https://github.com/microsoft/vscode-cmake-tools/issues/2396 which is why I haven't been able to reproduce the problem anymore.

chausner avatar May 15 '22 00:05 chausner