Skip to content

Latest commit

 

History

History
408 lines (292 loc) · 9.9 KB

File metadata and controls

408 lines (292 loc) · 9.9 KB

VS Code Setup Guide

This guide explains how to set up and use Visual Studio Code for developing the Weather CLI C++ project.

Prerequisites

1. Install VS Code

Download and install VS Code:

2. Install Required Extensions

When you open the project in VS Code, you'll be prompted to install recommended extensions. Click Install All or install them manually:

Required:

  • C/C++ (ms-vscode.cpptools) - IntelliSense, debugging, code browsing
  • CMake Tools (ms-vscode.cmake-tools) - CMake integration
  • CMake (twxs.cmake) - CMake language support

Recommended:

  • GitHub Copilot (github.copilot) - AI pair programming
  • GitHub Copilot Chat (github.copilot-chat) - AI chat assistant

3. Platform-Specific Requirements

macOS:

brew install cmake
xcode-select --install  # For C++ compiler

Linux:

sudo apt-get install build-essential cmake gdb

Windows:

  • CMake 3.20+, MinGW GCC, libcurl (auto-installed by scripts\setup-windows.bat)
  • Or manually: choco install mingw cmake curl

Opening the Project

  1. Open VS Code
  2. File → Open Folder...
  3. Select copilot-cpp directory
  4. When prompted, install recommended extensions
  5. CMake Tools will auto-configure the project

Building the Project

Method 1: Using CMake Tools Extension (Recommended)

Configure:

  1. Press Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows/Linux)
  2. Type "CMake: Configure"
  3. Select your compiler kit (e.g., GCC, Clang, or Visual Studio)

Build:

  1. Press Cmd+Shift+P / Ctrl+Shift+P
  2. Type "CMake: Build"
  3. Or click Build in the status bar

Quick Build:

  • Press Cmd+Shift+B (macOS) or Ctrl+Shift+B (Windows/Linux)
  • Select "CMake: Build"

Method 2: Using Tasks

Press Cmd+Shift+P / Ctrl+Shift+P and run:

  • Tasks: Run Build Task → "CMake: Build"
  • Tasks: Run Task → "CMake: Clean Rebuild" (clean build)

Method 3: Using the integrated terminal

Open integrated terminal (`Ctrl+``) and run:

# macOS/Linux
make build

# Windows
mingw32-make build

Running the Application

From VS Code UI

  1. Open src/main.cpp
  2. Press F5 or click Run → Start Debugging
  3. Select debug configuration:
    • Debug Weather CLI (macOS/Linux)
    • Debug Weather CLI (Windows)

From Tasks

Press Cmd+Shift+P / Ctrl+Shift+P:

  • Tasks: Run Task → "Run Weather CLI"

This will build and run with default city (London).

From Terminal

# macOS/Linux
./build/weather_cli London

# Windows
.\build\weather_cli.exe London

Debugging

Debug Main Application

  1. Set breakpoints by clicking left of line numbers
  2. Press F5 to start debugging
  3. Choose configuration:
    • Debug Weather CLI (macOS/Linux)
    • Debug Weather CLI (Windows)

Debug with different city:

  1. Edit .vscode/launch.json
  2. Change "args": ["London"] to your city
  3. Save and press F5

Debug Tests

  1. Open a test file (e.g., tests/test_weather_service.cpp)
  2. Set breakpoints
  3. Press F5 and select:
    • Debug Tests (macOS/Linux)
    • Debug Tests (Windows)

Debug specific test:

  1. Press F5 and select Debug Current Test
  2. Enter test filter (e.g., WeatherServiceTest.*)

Debug Controls

  • F5 - Start/Continue
  • F10 - Step Over
  • F11 - Step Into
  • Shift+F11 - Step Out
  • Shift+F5 - Stop

Running Tests

Using CMake Tools

  1. Click Testing icon in sidebar (flask icon)
  2. View all tests in Test Explorer
  3. Click ▶️ next to a test to run it
  4. Right-click → Debug Test to debug

Using Tasks

Press Cmd+Shift+P / Ctrl+Shift+P:

  • Tasks: Run Task → "CTest: Run All Tests"

From Terminal

# macOS/Linux
ctest --test-dir build -V --output-on-failure

# Windows
ctest --test-dir build -C Debug -V --output-on-failure

IntelliSense Configuration

IntelliSense is auto-configured via CMake Tools. If you see errors:

  1. Press Cmd+Shift+P / Ctrl+Shift+P
  2. Run "CMake: Configure"
  3. Run "C/C++: Reset IntelliSense Database"

Manual configuration (if needed):

Keyboard Shortcuts

Building & Running

  • Cmd+Shift+B / Ctrl+Shift+B - Build
  • F5 - Start Debugging
  • Ctrl+F5 - Run Without Debugging

Navigation

  • Cmd+P / Ctrl+P - Quick file open
  • F12 - Go to Definition
  • Shift+F12 - Find All References
  • Alt+Left/Right - Navigate Back/Forward

Editing

  • Cmd+/ / Ctrl+/ - Toggle Comment
  • Shift+Alt+F - Format Document
  • F2 - Rename Symbol

Terminal

  • `Ctrl+`` - Toggle Terminal
  • Cmd+Shift+\`` / Ctrl+Shift+`` - New Terminal

Code Formatting

Auto-format on save

Already enabled in .vscode/settings.json:

"editor.formatOnSave": true

Manual formatting

Format current file:

  • Press Shift+Alt+F (macOS: Shift+Option+F)

Format all files:

  • Run task: "Format Code (clang-format)"

CMake Configuration

Configure build type

Edit .vscode/settings.json:

"cmake.configureSettings": {
    "CMAKE_BUILD_TYPE": "Debug",  // or "Release"
    "BUILD_TESTS": "ON"
}

Select compiler kit

  1. Click CMake kit in status bar
  2. Choose compiler:
    • GCC (Linux)
    • Clang (macOS/Linux)
    • GCC (MinGW) (Windows)

Windows-specific: MinGW setup

Windows uses MinGW GCC with the Unix Makefiles generator. No manual configuration is needed after running scripts\setup-windows.bat.

If CMake Tools prompts for a kit, select GCC (the MinGW one). The kit scan finds g++.exe automatically once MinGW is on your PATH.

Common Issues

Issue: IntelliSense shows red squiggles

Solution:

  1. Build the project first: Cmd+Shift+B
  2. CMake will fetch dependencies
  3. Run "CMake: Configure"
  4. Restart VS Code if needed

Issue: "No kit selected"

Solution:

  1. Click No Kit Selected in status bar
  2. Choose appropriate compiler kit
  3. Or run "CMake: Select a Kit" from command palette

Issue: Windows build fails

Solution:

  1. Run setup script: scripts\setup-windows.bat (as Administrator)
  2. Or manually: choco install mingw cmake curl
  3. See WINDOWS_GETTING_STARTED.md for full troubleshooting

Issue: Tests not showing in Test Explorer

Solution:

  1. Build the project first
  2. Enable test explorer in settings:
    "cmake.testExplorer.enabled": true
  3. Reload VS Code

Issue: Debugger won't start

Solution:

  1. Build project first: Ctrl+Shift+B
  2. Check the executable exists:
    • macOS/Linux: build/weather_cli
    • Windows: build\weather_cli.exe
  3. Verify the launch configuration in .vscode/launch.json

Project Structure in VS Code

copilot-cpp/
├── .vscode/                      📁 VS Code configuration
│   ├── c_cpp_properties.json    # IntelliSense config
│   ├── settings.json            # Workspace settings
│   ├── tasks.json               # Build tasks
│   ├── launch.json              # Debug configurations
│   └── extensions.json          # Recommended extensions
├── include/                      📁 Header files
├── src/                          📁 Source files
├── tests/                        📁 Test files
└── CMakeLists.txt               📄 Build configuration

Best Practices

1. Use Integrated Terminal

  • Access via `Ctrl+``
  • Automatically uses correct environment

2. Enable Auto-save

Add to settings:

"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000

3. Use Tasks for Repetitive Commands

4. Use Git Integration

  • Source Control panel (Ctrl+Shift+G)
  • Stage, commit, and push from UI

5. Use Copilot for Coding

  • Ask questions via Copilot Chat (Cmd+I / Ctrl+I)
  • Get code suggestions as you type
  • Follow project instructions in .github/copilot-instructions.md

Multi-Platform Development

Switching between platforms

On macOS/Linux:

make build

On Windows:

mingw32-make build

VS Code automatically uses the correct CMake configuration based on your OS.

Platform-specific settings

Settings in .vscode/settings.json adapt automatically:

  • Compiler paths
  • Include directories
  • Build configurations

Advanced Features

Code Navigation

Find all usages:

  1. Right-click on symbol
  2. Select "Find All References"

Go to definition:

  • Click while holding Cmd (macOS) or Ctrl (Windows/Linux)
  • Or press F12

Peek Definition

  • Press Alt+F12 to peek without leaving current file

Rename Symbol

  1. Select symbol
  2. Press F2
  3. Enter new name
  4. All references updated automatically

Code Actions

  • Click 💡 lightbulb icon
  • Or press Cmd+. / Ctrl+.
  • Quick fixes and refactorings

Next Steps

  1. Build the project: Press Cmd+Shift+B
  2. Run tests: Open Test Explorer and click ▶️
  3. Debug application: Press F5
  4. Explore code: Use Cmd+P to jump to files
  5. Ask Copilot: Use Copilot Chat for coding help

Additional Resources

Support

For project-specific questions:

For VS Code issues: