cheshirekow / cmake_format

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

no response when using in windows by press hotkey #242

Open lovelypp777 opened 3 years ago

lovelypp777 commented 3 years ago

I installed cmake-format extension in vscode and I can run cmake-format.exe from the windows cmd window. but when I press Shift+Ctrl+I,there is no response. I don't know it is the correct hotkey. anything wrong?

cheshirekow commented 3 years ago

This is the default hotkey (this is what works for me). Here are a couple of things to check:

  1. Whichever implementation of pip you used to installed cmake-format, check that the install location that pip used is on your PATH (environment variable), or else set the location in your .vscode/settings.json .
  2. Ensure that this hotkey is not being used by any other extension for this file format
lovelypp777 commented 3 years ago

I checked vscode, "Ctrl+Shift+I" is not occupied. in windows cmd line, I can run pip and cmake-format.exe directly. the version is as following: cmake-format -v 0.6.13 pip --version pip20.2.3 from e:\tools\python39\lib\site-packages\pip (python 3.9)

windows 10 x64

thanks!

cheshirekow commented 3 years ago

Got it. Just to double check, this is what my keyboard shortcut info looks like in vscode. It sounds like yours looks the same but let me know if it is different: Selection_519

Can you try "Developer: toggle keyboard shortcuts troubleshooting" from the command pallet? If you then press Ctrl + shift + I you should see something like this in the console:

[2021-01-15 08:14:22.773] [renderer1] [warning] [File Watcher (chokidar)] Error: Circular symlink detected: "/home/josh/Codes/tangentsky/bazel-tangentsky/external/system/home" points to "/home"
[2021-01-15 08:17:44.345] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control
[2021-01-15 08:17:44.345] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl')
[2021-01-15 08:17:44.345] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched.
[2021-01-15 08:17:44.453] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl,shift], code: ShiftLeft, keyCode: 16, key: Shift
[2021-01-15 08:17:44.453] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,shift], code: ShiftLeft, keyCode: 4 ('Shift')
[2021-01-15 08:17:44.453] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched.
[2021-01-15 08:17:44.631] [renderer1] [info] [KeybindingService]: / Received  keydown event - modifiers: [ctrl,shift], code: KeyI, keyCode: 73, key: I
[2021-01-15 08:17:44.631] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,shift], code: KeyI, keyCode: 39 ('I')
[2021-01-15 08:17:44.631] [renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+[KeyI]
[2021-01-15 08:17:44.631] [renderer1] [info] [KeybindingService]: \ From 5 keybinding entries, matched editor.action.formatDocument, when: editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly && !inCompositeEditor, source: built-in.

Lastly, let's make sure that your listfile is detected as cmake. Open a CMakeLists.txt file and check the bottom right corner and make sure that the language says "CMake".

Selection_520

lovelypp777 commented 3 years ago

the right corner shows "CMake" when opening a CMakeLists.txt the "Developer: toggle keyboard shortcuts troubleshooting" show the following: [2021-01-16 21:12:19.165] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 16, key: Shift [2021-01-16 21:12:19.165] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 4 ('Shift') [2021-01-16 21:12:19.166] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched. [2021-01-16 21:12:19.341] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl,shift], code: ControlLeft, keyCode: 17, key: Control [2021-01-16 21:12:19.341] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,shift], code: ControlLeft, keyCode: 5 ('Ctrl') [2021-01-16 21:12:19.341] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched. [2021-01-16 21:12:19.602] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl,shift], code: KeyI, keyCode: 73, key: I [2021-01-16 21:12:19.603] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,shift], code: KeyI, keyCode: 39 ('I') [2021-01-16 21:12:19.603] [renderer1] [info] [KeybindingService]: | Resolving ctrl+shift+I [2021-01-16 21:12:19.603] [renderer1] [info] [KeybindingService]: \ No keybinding entries.

seems hotkey is not binded ?

cheshirekow commented 3 years ago

Yeah, that "No keybinding entries" is suspicious. What does your "Keyboard Shortcut" options look like, as compared to my screenshot above?

lovelypp777 commented 3 years ago

it's as following, seems no shortcut binding:

vshortcut

cheshirekow commented 3 years ago

Oh, well it looks like your keybinding is set to Alt + Shift + F. Can you repeat the "Developer: toggle keyboard shortcuts troubleshooting" experiment using Alt + Shift + F instead of Ctrl + shift + I?

lovelypp777 commented 3 years ago

when press Alt+Shift+F , the output is as following:

[2021-01-27 09:42:57.841] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 16, key: Shift [2021-01-27 09:42:57.841] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift], code: ShiftLeft, keyCode: 4 ('Shift') [2021-01-27 09:42:57.841] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched. [2021-01-27 09:42:57.841] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [shift,alt], code: AltLeft, keyCode: 18, key: Alt [2021-01-27 09:42:57.841] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift,alt], code: AltLeft, keyCode: 6 ('Alt') [2021-01-27 09:42:57.841] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched. [2021-01-27 09:42:58.117] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [shift,alt], code: KeyF, keyCode: 70, key: F [2021-01-27 09:42:58.117] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [shift,alt], code: KeyF, keyCode: 36 ('F') [2021-01-27 09:42:58.117] [renderer1] [info] [KeybindingService]: | Resolving shift+alt+F [2021-01-27 09:42:58.117] [renderer1] [info] [KeybindingService]: \ From 5 keybinding entries, matched editor.action.formatDocument, when: editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly && !inCompositeEditor, source: user.

cheshirekow commented 3 years ago

That looks promising. Did the document format when you used Alt + Shift + F?

lovelypp777 commented 3 years ago

no

cheshirekow commented 3 years ago

Did you ever figure out the problem? Do you see any pop-up text in the bottom right when using Alt + Shift + F indicating that execution of cmake-format failed?

Naufragous commented 3 years ago

Hey, I also had a similar experience on a freshly installed Windows machine with Visual Studio Code. In my case the missing YAML package for python caused cmake-format to fail silently in VS Code.

Running pip install pyyaml fixed the issue.

Maybe the VS Code extension could check this dependency and produce an error message?

Michael-Liao commented 1 year ago

I also ran into this issue a few weeks ago. As it turns out the cmake-format.py file was not using utf-8 encoding. This happens when I execute the following command in powershell

cmake-format --dump-config python > cmake-format.py

It will save to a UTF-16LE (you can see it in the bottom right corner of vscode). This is the main reason for cmake-format to not work when you use "Format Document" (Alt + Shift + F under windows).

To solve this issue, open the vscode command palette (F1 or Ctrl + Shift + P). under change file encoding > save with encoding > utf-8 then you can format the document correctly.