cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
954 stars 105 forks source link

VSCode extension: CMakeLists.txt are not formated #228

Closed blackliner closed 3 years ago

blackliner commented 3 years ago

With the VSCode extension, only *.cmake files are considered CMake files. But the majority of files are usually CMakeLists.txt

Is there a way to configure the extension to look for CMakeLists.txt files in addition?

hofbi commented 3 years ago

Can approve this behaviour. This was introduced with the latest release. Using 0.6.11 is a possible workaround.

Further with the latest release the cmake-format binary seems to be missing. I get

whereis cmake-format
cmake-format:

With 0.6.11 a binary is there.

cheshirekow commented 3 years ago

Is there a way to configure the extension to look for CMakeLists.txt files in addition?

Add the following to your settings.json:

{
  "files.associations": {
    "CMakeLists.txt": "cmake"
  }
}
cheshirekow commented 3 years ago

@hofbi

This was introduced with the latest release.

There have been no changes in file associations with the latest release.

Further with the latest release the cmake-format binary seems to be missing

The vscode extension has never shipped the binary. The binary should be installed through pip.

blackliner commented 3 years ago

Is there a way to configure the extension to look for CMakeLists.txt files in addition?

Add the following to your settings.json:

{
  "files.associations": {
    "CMakeLists.txt": "cmake"
  }
}

Do you mean the .cmake-format file one gets when cmake-format --dump-config > .cmake-format ? Oh, vscode, got it

hofbi commented 3 years ago

Add the following to your settings.json

@blackliner He means the VSCode settings.json

But manually adding this seems to me just like a workarround. Actually one would expect that CMakeLists.txt are by default recognized to be formatted. VSCode itself does this association, right? For instance on my machine I have full CMake support on these files without the file association. However, the format is not happening and I am pretty sure this already worked.

Update:

I did some tests on another machine and here both issues do not occur. So it seems to be a local issue and maybe one causes the other. @blackliner What do you get when you run cmake-format -v && whereis cmake-format


The vscode extension has never shipped the binary. The binary should be installed through pip.

I did the installation via pip. This are my steps to reproduce

pip3 install cmake_format

whereis cmake-format
cmake-format:

pip3 install -U cmake_format==0.6.11

whereis cmake-format
cmake-format: /valid/path/to/cmake-format
blackliner commented 3 years ago

I had to uninstall the extension, because both this and C/C++ extension from Microsoft try to format.