Visual Studio Code: Difference between revisions
No edit summary |
|||
(14 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=== | === Settings sync === | ||
Sync my settings on any new machine. | |||
(bottom-left gear) > Turn on settings sync | |||
Use my github account. | |||
=== | === Extensions === | ||
* Debug > Install additional debuggers... > C++ | |||
* C/C++ | * C/C++ | ||
* CMake, CMake Tools | * CMake, CMake Tools (one for project mgmt, one for cmake file editing) | ||
* [[eslint]] | * [[eslint]] | ||
* Bookmarks; go F2, set ctrl-F2 | * Bookmarks; go F2, set ctrl-F2 | ||
* Numbered bookmarks; go c-1, set c-a-sh-1 | * Numbered bookmarks; go c-1, set c-a-sh-1 | ||
Line 24: | Line 16: | ||
* change-case | * change-case | ||
* overtype | * overtype | ||
* SSH Tooling | * [https://marketplace.visualstudio.com/items?itemName=neptunedesign.vs-sequential-number sequential-number] | ||
* sort-imports (for ES6) | * [[MongoDB for VS Code]] | ||
* REST client | |||
Run API queries out of *.http files. If you get web services errors, restart code (all instances). | |||
* Docker, Dev Containers | |||
You can connect to a remote docker host with some settings foo. | |||
* Remote - SSH, SSH Tooling | |||
==== nah/old... ==== | |||
* x GitLens | |||
* x sort-imports (for ES6) | |||
* Debugger for Firefox | |||
* Debugger for Chrome | |||
=== Config and Key Bindings === | === Config and Key Bindings === | ||
Line 55: | Line 58: | ||
-exec x/300sb Query.c_str() | -exec x/300sb Query.c_str() | ||
=== Restoring Deleted Files === | |||
This feature has saved my ass! | |||
Check Local History: Visual Studio Code has a Local History feature that saves a copy of files every time you save them. To access the Local History, open the Command Palette in Visual Studio Code and run the command “Local History: Find Entry to Restore”. This will open a menu listing all the history entries, with a search bar. You can search for the deleted file and restore it from the Local History. | |||
=== Code completion and linting === | === Code completion and linting === | ||
==== Code formatting ==== | |||
Auto-format your code, all day long! This literally saves hours of typing, not to mention keeping the code uniform. DO IT. | |||
Prefs > Settings > search > format on save > check the box! | |||
We let vscode use clang-format to format C++ code. You need to install it: | |||
sudo apt install clang-format | |||
Custom rules are defined here: | |||
[workspace-folder]/.clang-format | |||
See [https://clang.llvm.org/docs/ClangFormatStyleOptions.html the formatting rules] for help. | |||
If formatting errors out or does not happen, run [clang-format #filename#] in a command prompt and see if you have errors in your rules file. | |||
NOTE: eslint is the current way to enforce code style in Javascript. See [[eslint|the eslint page]] for more information. | |||
Some C++ ones: | |||
Standard: Cpp11 | |||
BasedOnStyle: LLVM | |||
IndentWidth: 2 | |||
ColumnLimit: 0 | |||
AccessModifierOffset: -2 | |||
NamespaceIndentation: All | |||
BreakBeforeBraces: Custom | |||
BraceWrapping: | |||
AfterEnum: true | |||
AfterStruct: true | |||
AfterClass: true | |||
SplitEmptyFunction: true | |||
AfterControlStatement: false | |||
AfterNamespace: false | |||
AfterFunction: true | |||
AfterUnion: true | |||
AfterExternBlock: false | |||
BeforeCatch: false | |||
BeforeElse: false | |||
SplitEmptyRecord: true | |||
SplitEmptyNamespace: true | |||
==== Intellisense ==== | ==== Intellisense ==== | ||
Line 86: | Line 133: | ||
} | } | ||
=== | === Install === | ||
* Add the repo | |||
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg | |||
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg | |||
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' | |||
* Update as usual | |||
sudo apt-get update | |||
sudo apt-get install code # released monthly | |||
# or code-insiders (released daily) | |||
# use [apt search visualst] |
Latest revision as of 11:26, 10 December 2024
Settings sync
Sync my settings on any new machine.
(bottom-left gear) > Turn on settings sync
Use my github account.
Extensions
- Debug > Install additional debuggers... > C++
- C/C++
- CMake, CMake Tools (one for project mgmt, one for cmake file editing)
- eslint
- Bookmarks; go F2, set ctrl-F2
- Numbered bookmarks; go c-1, set c-a-sh-1
- vscode-icons
- change-case
- overtype
- sequential-number
- MongoDB for VS Code
- REST client
Run API queries out of *.http files. If you get web services errors, restart code (all instances).
- Docker, Dev Containers
You can connect to a remote docker host with some settings foo.
- Remote - SSH, SSH Tooling
nah/old...
- x GitLens
- x sort-imports (for ES6)
- Debugger for Firefox
- Debugger for Chrome
Config and Key Bindings
Go to File > Preferences > Settings for a shitton of settings. Search for the name you want.
Turn OFF these very-slow automatic checks in your launch.json file:
"npm.autoDetect": "off", "gulp.autoDetect": "off", "grunt.autoDetect": "off", "jake.autoDetect": "off", "typescript.tsc.autoDetect": "off",
Turn this shit off, it "reuses tabs" on files you open (unless you double-click to open, or edit the file). Nonsense.
"workbench.editor.enablePreview": false
Use the editor; changes are stored and shared across installs from here:
ls ~/.config/Code/User/ keybindings.json -> ../../../development/config/common/home/m/.config/Code/User/keybindings.json settings.json -> ../../../development/config/common/home/m/.config/Code/User/settings.json
Debugging
While debugging, you can use the Debug Console to print memory, including the content of strings that are clipped by default in the variables and watch windows.
View > Open View > Debug Console
From there, send gdb a command to print memory – 300 characters of a string in this example:
-exec x/300sb Query.c_str()
Restoring Deleted Files
This feature has saved my ass!
Check Local History: Visual Studio Code has a Local History feature that saves a copy of files every time you save them. To access the Local History, open the Command Palette in Visual Studio Code and run the command “Local History: Find Entry to Restore”. This will open a menu listing all the history entries, with a search bar. You can search for the deleted file and restore it from the Local History.
Code completion and linting
Code formatting
Auto-format your code, all day long! This literally saves hours of typing, not to mention keeping the code uniform. DO IT.
Prefs > Settings > search > format on save > check the box!
We let vscode use clang-format to format C++ code. You need to install it:
sudo apt install clang-format
Custom rules are defined here:
[workspace-folder]/.clang-format
See the formatting rules for help.
If formatting errors out or does not happen, run [clang-format #filename#] in a command prompt and see if you have errors in your rules file.
NOTE: eslint is the current way to enforce code style in Javascript. See the eslint page for more information.
Some C++ ones:
Standard: Cpp11 BasedOnStyle: LLVM IndentWidth: 2 ColumnLimit: 0 AccessModifierOffset: -2 NamespaceIndentation: All BreakBeforeBraces: Custom BraceWrapping: AfterEnum: true AfterStruct: true AfterClass: true SplitEmptyFunction: true AfterControlStatement: false AfterNamespace: false AfterFunction: true AfterUnion: true AfterExternBlock: false BeforeCatch: false BeforeElse: false SplitEmptyRecord: true SplitEmptyNamespace: true
Intellisense
Use CMake to generate json that includes the project headers, then import that into vscode settings, for a DRY way to set up header paths.
- Add this to CMakeList.txt to generate compile_commands.json:
# MDM This creates compile_commands.json, which can be imported by vscode to set include paths from here, w00t DRY set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
- Edit your project settings (eg...)
/home/m/development/thedigitalage/AbetterTrader/server/.vscode/c_cpp_properties.json
- Add a compileCommands directive:
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [], "compilerPath": "/usr/bin/clang", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64", "configurationProvider": "vector-of-bool.cmake-tools", "compileCommands": "${workspaceFolder}/cmake-debug/compile_commands.json" } ], "version": 4 }
Install
- Add the repo
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
- Update as usual
sudo apt-get update sudo apt-get install code # released monthly # or code-insiders (released daily) # use [apt search visualst]