Skip to content

pvjagtap/PCLintPLus_VSCodeExtension

Repository files navigation

PC-Lint Plus Extension for Visual Studio Code

This extension integrates the PC-Lint Plus static code analysis tool with Visual Studio Code, making it easy to lint C/C++ files and view the results directly in the VS Code interface with comprehensive diagnostic support and intelligent include path management.

✨ Features

  • Single File & Workspace Linting: Lint individual files or entire workspaces with progress tracking
  • Smart Diagnostic Management: Results displayed in VS Code's Problems panel with accumulation across workspace files
  • Auto-Lint on Save: Configurable automatic linting when files are saved
  • Multiple Include Path Sources: Integrates with VSCode C++ extension and custom configurations
  • Advanced Configuration: Support for custom PC-Lint configuration files and preprocessor definitions
  • Command Line Length Fix: Uses temporary configuration files to avoid Windows command line limitations
  • Real-time Progress: Workspace linting with cancellation support and progress reporting
  • System Header Filtering: Automatically filters out system header issues (TASKING compiler, etc.)
  • Summary Diagnostics: Shows summary information for issues in included files

πŸ“‹ Requirements

  • PC-Lint Plus must be installed on your system
  • Visual Studio Code 1.60.0 or newer
  • C/C++ source files (.c, .cpp, .h, .hpp)

πŸ“¦ Installation

  1. Install the extension from the Visual Studio Code Marketplace
  2. Configure the extension settings (see Configuration section below)
  3. Set up your PC-Lint Plus executable path
  4. Configure include paths and preprocessor definitions as needed

βš™οΈ Configuration

Core Settings

Setting Description Default
pclintplus.executablePath Path to the PC-Lint Plus executable ""
pclintplus.repositoryPath Root path for the repository being analyzed Workspace folder
pclintplus.configFiles List of PC-Lint configuration files (.lnt) Predefined config files
pclintplus.outputFormat Output format for PC-Lint Plus "xml"

Include Path Management

Setting Description Default
pclintplus.includePaths List of include paths for the linter Extensive default paths
pclintplus.compilerIncludePath Path to compiler-specific include files "C:\\TASKING\\TriCore v6.3r1\\ctc\\include"
pclintplus.useVSCodeIncludes Enable integration with VSCode C++ extension paths true

Advanced Options

Setting Description Default
pclintplus.preprocessorDefinitions List of preprocessor definitions []
pclintplus.additionalArgs Additional command line arguments ["-b", "-width(240,4)"]
pclintplus.autoLintOnSave Enable automatic linting on file save false
pclintplus.filePatterns File patterns to include when linting workspace ["**/*.c", "**/*.h"]
pclintplus.excludePatterns File patterns to exclude when linting workspace ["**/node_modules/**", "**/build/**"]

Include Path Architecture

The extension uses a sophisticated multi-source include path system:

1. Extension Configuration (Primary)

{
  "pclintplus.includePaths": [
    "${workspaceFolder}/src/rte_gen",
    "${workspaceFolder}/input/swc_bsw/core",
    // ... extensive predefined paths
  ]
}

2. VSCode C++ Integration (Optional)

Automatically reads from .vscode/c_cpp_properties.json:

{
  "configurations": [
    {
      "name": "Win32",
      "includePath": [
        "${workspaceFolder}/**",
        "C:/Program Files/Microsoft Visual Studio/**"
      ]
    }
  ]
}

3. Compiler-Specific Paths (Auto-Added)

{
  "pclintplus.compilerIncludePath": "C:\\TASKING\\TriCore v6.3r1\\ctc\\include"
}

Smart Processing Features:

  • βœ… Variable substitution: ${workspaceFolder} β†’ actual workspace path
  • βœ… Existence validation: Only existing paths are included
  • βœ… Duplicate filtering: Prevents redundant paths from multiple sources
  • βœ… Platform awareness: Chooses correct configuration for Windows/Mac/Linux
  • βœ… Temporary config files: Avoids command line length limitations

πŸ“ Example Configuration

Basic Setup

{
  "pclintplus.executablePath": "C:\\pclint_plus\\windows\\pclp64.exe",
  "pclintplus.repositoryPath": "z:\\SW\\Development\\Deploy",
  "pclintplus.autoLintOnSave": true,
  "pclintplus.useVSCodeIncludes": true
}

Advanced Configuration

{
  "pclintplus.executablePath": "C:\\pclint_plus\\windows\\pclp64.exe",
  "pclintplus.repositoryPath": "z:\\SW\\Development\\Deploy",
  "pclintplus.configFiles": [
    "cfg/pclint_plus/co-tasking.lnt",
    "cfg/pclint_plus/base.lnt",
    "cfg/pclint_plus/au-misra3.lnt",
    "cfg/pclint_plus/options.lnt",
    "cfg/pclint_plus/env-xml.lnt",
    "cfg/pclint_plus/tricore.lnt"
  ],
  "pclintplus.preprocessorDefinitions": [
    "DEBUG",
    "PLATFORM_X86",
    "APPL_BUILD"
  ],
  "pclintplus.autoLintOnSave": true,
  "pclintplus.useVSCodeIncludes": true
}

Usage

Available Commands

Command Description Shortcut
PC-Lint Plus: Lint Current File Lint the currently open file Command Palette
PC-Lint Plus: Lint Workspace Lint all C/C++ files in the workspace Command Palette
PC-Lint Plus: Clear Diagnostics Clear all lint diagnostics from Problems panel Command Palette

Access commands via:

  • Command Palette: Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac)
  • Custom Keybindings: Bind commands to your preferred shortcuts

Workspace Linting Features

  • Progress Tracking: Real-time progress with file count and percentage
  • Cancellation Support: Cancel long-running workspace lints
  • Diagnostic Accumulation: Issues from all files collected in Problems panel
  • Summary Report: Final statistics on processed files and found issues

Auto-Lint on Save

Enable pclintplus.autoLintOnSave to automatically lint C/C++ files when saved:

  • Only processes lintable files (.c, .cpp, .h, .hpp)
  • Respects file type detection
  • Provides immediate feedback on code changes

πŸ”§ Troubleshooting

Debug Information

The extension provides comprehensive logging in the PC-Lint Plus output channel:

  1. Open View β†’ Output
  2. Select PC-Lint Plus from the dropdown
  3. Review detailed execution logs and error messages

Common Issues & Solutions

Issue Cause Solution
"PC-Lint Plus executable not found" Invalid executable path Check pclintplus.executablePath setting
"Config file not found" Missing .lnt configuration files Verify files exist in specified locations
"Unable to open include file" Missing include directory Add directory to pclintplus.includePaths
"Command line too long" error Excessive include paths Enable temporary config files (default)
No diagnostics in workspace lint Diagnostic clearing issue Fixed in latest version
System header warnings TASKING/compiler headers Automatically filtered out

Performance Tips

  • Large Workspaces: Extension automatically limits to 2000 files for performance
  • Include Path Optimization: Remove unnecessary paths to speed up linting
  • File Exclusions: Use pclintplus.excludePatterns to skip build directories

πŸ›οΈ Architecture

Extension Components

  • Extension Entry Point: Command registration and VS Code integration
  • LintRunner Class: Core linting logic and PC-Lint Plus execution
  • Configuration Manager: Multi-source include path resolution
  • Diagnostic Processor: XML parsing and VS Code diagnostic creation

Key Architectural Features

  • Temporary Config Files: Eliminates command line length limitations
  • Diagnostic Accumulation: Maintains issues across multiple files in workspace linting
  • Smart Path Resolution: Combines multiple include path sources intelligently
  • System Header Filtering: Automatically excludes compiler-specific warnings

⚠️ Known Limitations

  • Large Workspaces: May take significant time to process thousands of files
  • Compiler Constructs: Some advanced compiler-specific features may not be recognized
  • File Limit: Workspace linting limited to 2000 files for performance
  • Platform Dependencies: Paths and executable locations are platform-specific

πŸ“‹ System Requirements

Supported Platforms

  • βœ… Windows (Primary development platform)
  • βœ… macOS (Cross-platform support)
  • βœ… Linux (Cross-platform support)

File Type Support

  • βœ… C files (.c)
  • βœ… C++ files (.cpp)
  • βœ… Header files (.h, .hpp)

πŸ“š Release Notes

Latest Version

  • βœ… Fixed: Command line length errors with temporary config files
  • βœ… Fixed: Diagnostic accumulation in workspace linting
  • βœ… Added: Comprehensive Doxygen documentation
  • βœ… Added: Multi-source include path support
  • βœ… Added: VSCode C++ extension integration
  • βœ… Added: System header filtering
  • βœ… Added: Progress reporting and cancellation
  • βœ… Improved: Error handling and user feedback

0.1.4

  • Initial release of the PC-Lint Plus extension
  • Support for individual file and workspace linting
  • Integration with VS Code Problems panel
  • Configuration options for paths and settings

πŸ“„ License

This extension is licensed under the MIT License.

🀝 Contributing

Contributions are welcome! Please feel free to:

  • πŸ› Submit Issues: Report bugs or request features
  • πŸ”§ Pull Requests: Contribute code improvements
  • πŸ“– Documentation: Help improve documentation
  • πŸ§ͺ Testing: Test on different platforms and configurations

πŸ› οΈ Development Environment

Prerequisites

  • Node.js 14.x or higher
  • npm 6.x or higher (or yarn 1.x)
  • Visual Studio Code 1.60.0 or newer
  • TypeScript 4.4.0 or higher (installed globally recommended)
  • Git for version control

Quick Start

# Clone the repository
git clone <repository-url>
cd vscode-pclint-plus

# Install dependencies
npm install

# Open in VS Code
code .

# Launch extension development host
# Press F5 or run "Extension: Start Debugging"

πŸ“ Project Structure

vscode-pclint-plus/
β”œβ”€β”€ src/                    # TypeScript source files
β”‚   β”œβ”€β”€ extension.ts        # Main extension entry point
β”‚   └── lintRunner.ts       # Core linting functionality
β”œβ”€β”€ out/                    # Compiled JavaScript output
β”œβ”€β”€ images/                 # Extension icons and assets
β”œβ”€β”€ assets/                 # Demo images and videos
β”œβ”€β”€ package.json            # Extension manifest and dependencies
β”œβ”€β”€ tsconfig.json          # TypeScript configuration
β”œβ”€β”€ .vscode/               # VS Code workspace settings
β”‚   β”œβ”€β”€ launch.json        # Debug configuration
β”‚   └── tasks.json         # Build tasks
β”œβ”€β”€ .vscodeignore          # Files excluded from packaging
└── README.md              # This documentation

πŸ—οΈ Local Compilation

Method 1: Using npm Scripts

# Install dependencies (if not done already)
npm install

# Compile TypeScript to JavaScript
npm run compile

# Watch mode for development (auto-recompile on changes)
npm run watch

# Clean and rebuild
npm run clean && npm run compile

Method 2: Using TypeScript Compiler Directly

# Install TypeScript globally (if not installed)
npm install -g typescript

# Compile once
tsc -p ./

# Watch mode
tsc -watch -p ./

# Check for compilation errors
tsc --noEmit -p ./

Method 3: Using VS Code Tasks

  1. Open Command Palette (Ctrl+Shift+P)
  2. Run Tasks: Run Task
  3. Select:
    • npm: compile - Single compilation
    • npm: watch - Continuous compilation
    • typescript: build - TypeScript build task

πŸ§ͺ Testing & Debugging

Debug Extension in Development Host

# Method 1: VS Code Debug
1. Open the project in VS Code
2. Go to Run and Debug view (Ctrl+Shift+D)
3. Select "Launch Extension" configuration
4. Press F5 or click the green play button
5. New Extension Development Host window opens
6. Test your extension in the development host

# Method 2: Command Line
npm run debug

Debug Configuration (.vscode/launch.json)

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Extension",
      "type": "extensionHost",
      "request": "launch",
      "runtimeExecutable": "${execPath}",
      "args": ["--extensionDevelopmentPath=${workspaceFolder}"],
      "outFiles": ["${workspaceFolder}/out/**/*.js"],
      "preLaunchTask": "npm: compile"
    }
  ]
}

Testing with Sample Projects

# Create test workspace
mkdir test-workspace
cd test-workspace

# Create sample C files
echo '#include <stdio.h>\nint main() { return 0; }' > test.c
echo '#ifndef TEST_H\n#define TEST_H\nint test_func();\n#endif' > test.h

# Configure PC-Lint Plus settings in VS Code
# Test single file and workspace linting

πŸ“¦ Building & Packaging

Install vsce (Visual Studio Code Extension Manager)

npm install -g vsce

Package Extension

# Package for distribution (.vsix file)
vsce package

# Package with specific version
vsce package --patch
vsce package --minor
vsce package --major

# Pre-release version
vsce package --pre-release

Install Packaged Extension Locally

# Install the .vsix file
code --install-extension vscode-pclint-plus-*.vsix

# Or via VS Code UI:
# 1. Open Extensions view (Ctrl+Shift+X)
# 2. Click "..." menu β†’ "Install from VSIX..."
# 3. Select your .vsix file

πŸ”§ Development Scripts

Add these scripts to your package.json:

{
  "scripts": {
    "vscode:prepublish": "npm run compile",
    "compile": "tsc -p ./",
    "watch": "tsc -watch -p ./",
    "clean": "rimraf out",
    "lint": "eslint src --ext ts",
    "lint:fix": "eslint src --ext ts --fix",
    "package": "vsce package",
    "publish": "vsce publish",
    "debug": "code --extensionDevelopmentPath=${PWD}"
  }
}

Development Workflow

Daily Development Cycle

# 1. Start development session
npm run watch          # Terminal 1: Continuous compilation
code .                 # Open VS Code
# Press F5             # Launch Extension Development Host

# 2. Make changes to TypeScript files
# 3. Changes auto-compile (watch mode)
# 4. Reload Extension Development Host (Ctrl+R)
# 5. Test changes
# 6. Repeat steps 2-5

# 7. Before committing
npm run lint           # Check code style
npm run compile        # Final compilation check
npm test               # Run tests (if available)

Code Quality Tools

# Install development dependencies
npm install --save-dev @types/vscode @types/node eslint typescript

# ESLint configuration (.eslintrc.json)
{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": [
    "@typescript-eslint/recommended"
  ],
  "rules": {
    "@typescript-eslint/no-unused-vars": "warn",
    "@typescript-eslint/explicit-function-return-type": "off"
  }
}

Publishing Workflow

Prepare for Release

# 1. Update version in package.json
npm version patch|minor|major

# 2. Update CHANGELOG.md
# Document new features, fixes, breaking changes

# 3. Build and test
npm run compile
npm run lint
vsce package

# 4. Test the packaged extension
code --install-extension vscode-pclint-plus-*.vsix

# 5. Publish to marketplace
vsce publish

CI/CD Setup (GitHub Actions Example)

# .github/workflows/build.yml
name: Build and Test
on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '16'
      - run: npm install
      - run: npm run compile
      - run: npm run lint
      - run: npm run package

πŸ” Debugging Tips

Common Development Issues

# TypeScript compilation errors
tsc --noEmit -p ./      # Check for type errors

# Extension not loading
# Check VS Code Developer Console (Help β†’ Toggle Developer Tools)

# Include path issues
# Test with absolute paths first
# Check file existence with fs.existsSync()

# PC-Lint Plus execution issues
# Test command manually in terminal
# Check executable permissions on Linux/Mac

Debugging PC-Lint Plus Integration

// Add debug logging to lintRunner.ts
this.outputChannel.appendLine(`Debug: Command = ${fullCommand}`);
this.outputChannel.appendLine(`Debug: Working Dir = ${process.cwd()}`);
this.outputChannel.appendLine(`Debug: Args = ${JSON.stringify(args)}`);

Useful Development Resources

VS Code Extension Development

TypeScript Resources

PC-Lint Plus Integration

Development Best Practices

  1. Always run in watch mode during development
  2. Test both single file and workspace linting after changes
  3. Use the output channel for debugging information
  4. Test with different PC-Lint Plus configurations
  5. Verify cross-platform compatibility (Windows/Mac/Linux paths)
  6. Profile performance with large workspaces
  7. Handle errors gracefully with user-friendly messages
  8. Document complex logic with JSDoc/Doxygen comments

πŸ”— Links

  • GitHub Repository: [Link to your repository]
  • VS Code Marketplace: [Link to marketplace page]
  • PC-Lint Plus Documentation: [Link to PC-Lint Plus docs]
  • Issue Tracker: [Link to issues page]

Made for C/C++ developers using PC-Lint Plus

About

VS Code extension for running PC-Lint Plus and displaying results in Problems panel

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors