Skip to content

Add optional scan-on-open for Rust files #13

Description

@dollfins

Description

Currently, the extension only scans on save (onDidSaveTextDocument). It does not scan files when they are first opened. A user opening a Soroban contract for the first time must either save it or manually run the scan command to see diagnostics.

Current Behavior

File is scanned only on save:

vscode.workspace.onDidSaveTextDocument((doc) => {
    if (doc.languageId === 'rust' && runOnSave) {
        diagnosticsProvider.scanFile(doc);
    }
})

Expected Behavior

Add an optional Scan on Open feature:

  1. When a Rust file is opened and it has not been scanned yet in this session, automatically scan it
  2. Add a configuration setting sorobanGuard.runOnOpen (default: true)
  3. Track which files have been scanned in a Set<string> to avoid redundant scans
  4. Reset the tracking set when the extension is deactivated or when Clear Results is run

Implementation Notes

  • Register vscode.window.onDidChangeActiveTextEditor to detect when a new file is opened
  • Use a Set<string> of scanned file paths to avoid re-scanning
  • Respect the existing exclude patterns
  • Show a brief "scanning on open" status in the status bar
  • Ensure this does not cause excessive scanning when switching between open tabs

Acceptance Criteria

  • Rust files are automatically scanned when first opened
  • New setting sorobanGuard.runOnOpen controls this behavior
  • Already-scanned files are not re-scanned on tab switch
  • Exclude patterns are respected
  • No performance impact on editor startup

Complexity

Medium — requires understanding of editor lifecycle events and performance considerations.

Points

150

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions