Skip to content

Askath/zed-sonarlint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SonarLint for Zed

THIS IS A WIP. PROBABLY NOT WORKING ATM

A Zed extension that integrates SonarLint static code analysis for Java projects.

Features

  • Static Code Analysis: Real-time detection of bugs, vulnerabilities, and code smells in Java code
  • Automatic Setup: Downloads and configures SonarLint language server automatically
  • Cross-Platform: Works on Windows, macOS, and Linux
  • Java Runtime Detection: Automatically finds and uses system Java installations
  • Comprehensive Rule Set: Supports all SonarLint Java analyzers

Requirements

  • Java 8 or later: SonarLint requires a Java Runtime Environment (JRE) to operate
  • Zed Editor: This extension is designed for the Zed code editor

Installation

  1. Add this extension to your Zed extensions directory
  2. Restart Zed
  3. Open a Java project - the extension will automatically download and configure SonarLint

How It Works

This extension:

  1. Downloads SonarLint: Automatically downloads the SonarLint VSCode extension and extracts the language server components
  2. Detects Java: Finds your system Java installation or uses JAVA_HOME
  3. Launches Language Server: Starts the SonarLint language server with appropriate Java analyzers
  4. Provides Analysis: Integrates with Zed's LSP system to show diagnostics and suggestions

Configuration

Standalone Mode (Default)

The extension uses default SonarLint configuration with:

  • Telemetry disabled
  • Standard Java test file patterns
  • Default rule set enabled

Connected Mode (SonarQube/SonarCloud Integration)

To connect to a SonarQube server or SonarCloud, create a .sonarlint/settings.json file in your project root or add configuration to .zed/settings.json:

SonarQube Server Configuration

{
  "sonarlint": {
    "connectedMode": {
      "connections": {
        "sonarqube": [
          {
            "serverUrl": "https://your-sonarqube-server.com",
            "token": "your-user-token",
            "connectionId": "my-sonarqube"
          }
        ]
      },
      "project": {
        "connectionId": "my-sonarqube",
        "projectKey": "your-project-key"
      }
    }
  }
}

SonarCloud Configuration

{
  "sonarlint": {
    "connectedMode": {
      "connections": {
        "sonarcloud": [
          {
            "token": "your-sonarcloud-token",
            "organizationKey": "your-organization",
            "connectionId": "my-sonarcloud"
          }
        ]
      },
      "project": {
        "connectionId": "my-sonarcloud",
        "projectKey": "your-project-key"
      }
    }
  }
}

Connected Mode Benefits

  • Quality Profiles: Uses the same rules and configuration as your SonarQube/SonarCloud project
  • Issue Suppressions: Respects False Positive and Won't Fix issue statuses
  • Custom Rules: Access to organization-specific rules and configurations
  • Taint Analysis: Advanced security vulnerability detection
  • Team Synchronization: Shared project settings across team members

Setting Up Connected Mode

  1. Generate User Token:

    • SonarQube: Go to User Settings → Security → Generate Token
    • SonarCloud: Go to My Account → Security → Generate Token
  2. Find Project Key: Available in your SonarQube/SonarCloud project dashboard

  3. Configure Connection: Add the configuration to your project settings

  4. Team Sharing: Commit the configuration file (without tokens) and have team members add their personal tokens

Example Configuration Files

See the examples/ directory for complete configuration examples:

  • examples/sonarlint-settings.json - Place in .sonarlint/settings.json
  • examples/zed-settings.json - Place in .zed/settings.json

Configuration Priority

The extension loads configuration in this order (first found wins):

  1. .sonarlint/settings.json in project root
  2. sonarlint section in .zed/settings.json
  3. Default standalone configuration

File Structure

.zed/sonarlint/
├── sonarlint.vsix          # Downloaded VSCode extension
├── server/
│   └── sonarlint-ls.jar    # SonarLint language server
└── analyzers/
    ├── sonarjava.jar       # Java analyzer
    └── [other analyzers]   # Additional language analyzers

Development

To build the extension:

cargo build --release

To test:

cargo check

Technical Details

  • Language Server Protocol: Uses SonarLint's LSP implementation
  • Artifact Source: Downloads from VS Code marketplace
  • Java Detection: Supports system Java, JAVA_HOME, and common installation paths
  • Architecture: Rust-based extension following Zed's extension patterns

Troubleshooting

Java Not Found

If you get "Java runtime not found" errors:

  1. Install Java 8 or later
  2. Ensure java is in your PATH, or
  3. Set the JAVA_HOME environment variable

Extension Not Loading

  1. Check Zed's extension logs
  2. Verify Java installation with java -version
  3. Ensure internet connectivity for initial download

Contributing

Contributions are welcome! Please follow the existing code style and add tests for new features.

License

This extension follows the same licensing as the underlying SonarLint components.

About

Sonarlint Extension for Java in the Zed editor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages