Skip to content

feat: centralize quick fixes in analyzer and add stdin support for IDE extensions#21

Merged
willibrandon merged 10 commits intomainfrom
feature/ide-quick-fix-expansion
Aug 5, 2025
Merged

feat: centralize quick fixes in analyzer and add stdin support for IDE extensions#21
willibrandon merged 10 commits intomainfrom
feature/ide-quick-fix-expansion

Conversation

@willibrandon
Copy link
Owner

@willibrandon willibrandon commented Aug 5, 2025

Description

This PR implements analyzer-provided suggested fixes for mtlog diagnostics and transitions both IDE extensions (VS Code and GoLand) to use stdin-based communication with the analyzer. All quick fix logic is now centralized in the analyzer, ensuring consistent behavior across platforms.

Key changes:

  • Added suggested fixes to the analyzer for MTLOG001 (template/argument mismatch) and MTLOG006 (missing error parameter)
  • Transitioned from file-based to stdin-based analyzer communication for real-time analysis
  • Removed all custom quick fix implementations from GoLand plugin (PascalCaseQuickFix, TemplateArgumentQuickFix, MissingErrorQuickFix)
  • Cleaned up VS Code extension by removing ~400 lines of dead code and unused quick fix methods
  • Fixed analyzer scope detection to properly handle function parameters and named return values
  • Added comprehensive test coverage for analyzer suggested fixes

MTLOG006 Quick Fix Details

The analyzer now intelligently adds missing error parameters to Error/E level logs:

  • Detects error variables in the current scope (including function parameters and named returns)
  • If an error variable is found (e.g., err, e, myErr), it adds that variable
  • If no error is in scope, it adds nil with a TODO comment: // TODO: replace nil with actual error
  • Properly handles different contexts: if blocks, function literals, and nested scopes

Type of change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation update

Checklist

  • Tests pass (go test ./...)
  • Linter passes (golangci-lint run)
  • Benchmarks checked (if performance-related)
  • Documentation updated (if needed)
  • Zero-allocation promise maintained (if applicable)

Additional notes

  • Both IDE extensions now use the analyzer's stdin mode for real-time analysis without file I/O
  • This architectural change ensures that all diagnostic fixes come from a single source of truth
  • The stdin-based approach improves performance by avoiding repeated file reads/writes
  • All 70 GoLand plugin tests pass with the new architecture
  • VS Code extension compiles cleanly after removing dead code

Relates to #18

…detection

- Add MissingErrorQuickFix that intelligently finds error variables in scope
- Remove all caching mechanisms from MtlogExternalAnnotator and MtlogProjectService
- Improve stdin mode: pass editor content directly to analyzer without file system dependency
- Add test suite with 14 scenarios for error detection
- Replace clearCache() with restartProcesses() throughout
- Add MtlogForceAnnotator for cases when ExternalAnnotator doesn't call apply()
- Improve logging throughout for better debugging

The quick fix searches for error variables in the current scope (err, e, myErr, etc.) and adds them as parameters. When no error is found, it adds 'nil' with a TODO comment.
…ension

- Add scope-aware error variable detection to analyzer (findErrorVariableInScope)
- Switch VS Code extension to use analyzer stdin mode for suggested fixes
- Generate contextual error parameters: 'err' when in scope, 'nil' with TODO otherwise
- Add test coverage for scope detection scenarios
- Match GoLand plugin behavior for error parameter quick fixes
- Support TODO comment placement (same line vs next line based on existing comments)
- Add suggested fixes to analyzer for MTLOG001 (template/argument mismatch) and MTLOG006 (missing error parameter)
- Update GoLand plugin to use analyzer-provided fixes exclusively, removing custom quick fix implementations
- Update VS Code extension to use analyzer-provided fixes and remove ~400 lines of dead code
- Fix analyzer scope detection to include function parameters and named return values
- Add test coverage for suggested fixes
- Ensure parity between VS Code and GoLand extensions by using analyzer as single source of truth

Both IDE extensions now rely exclusively on the analyzer for quick fixes, ensuring consistent behavior across platforms and simplifying maintenance.
- Fix test expectations to match new diagnostic message format where ID comes before severity
- Ensure MTLOG001 diagnostic properly applies downgrade-errors flag
@willibrandon willibrandon self-assigned this Aug 5, 2025
@willibrandon willibrandon added enhancement New feature or request tooling Development tools, build systems, and analyzers performance Performance improvements and optimizations. Zero-allocation promise territory. 🚀 labels Aug 5, 2025
- Add SPLUNK_GENERAL_TERMS=--accept-sgt-current-at-splunk-com to CI workflow
- Update docker-compose.test.yml with new license acceptance requirement
- Fixes CI failures due to Splunk's new EULA acceptance requirement for 10.x images
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR centralizes quick fix logic in the analyzer and transitions both IDE extensions to use stdin-based communication. It removes custom quick fix implementations from the GoLand plugin and VS Code extension, replacing them with analyzer-provided suggested fixes for consistent behavior across platforms.

  • Implements analyzer-provided suggested fixes for MTLOG001 (template/argument mismatch) and MTLOG006 (missing error parameter)
  • Transitions both IDE extensions from file-based to stdin-based analyzer communication for real-time analysis
  • Removes all custom quick fix implementations (~1000+ lines of code) from IDE extensions

Reviewed Changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
vscode-extension/mtlog-analyzer/src/extension.ts Transitions to stdin-based analyzer communication and removes custom quick fix logic
goland-plugin/src/main/kotlin/com/mtlog/analyzer/quickfix/AnalyzerSuggestedQuickFix.kt New quick fix implementation that applies analyzer-provided text edits
cmd/mtlog-analyzer/main.go Adds stdin mode support for IDE extensions with JSON request/response format
cmd/mtlog-analyzer/analyzer/analyzer.go Implements suggested fixes for MTLOG001 and MTLOG006 diagnostics
goland-plugin/src/test/kotlin/com/mtlog/analyzer/quickfix/MissingErrorQuickFixTest.kt Test coverage for missing error parameter fixes

- Fix incorrect pointer dereference in analyzer pass.Report() calls
- Clarify module vs non-module pattern logic in main.go
- Improve GoLand text edit sorting to use actual document offsets
- Remove unnecessary test comment
The previous commit incorrectly removed pointer dereference from pass.Report() calls. Since diagnostic is defined as *analysis.Diagnostic, the dereference is required.
…alyzer

- Replace file I/O with AST-based analysis for finding line info
- Fix tautological condition and unconditionally terminated loop
- Remove redundant break statements in switch cases
- Remove unused functions: reportDiagnostic, reportDiagnosticWithConfig, findContainingIfBlock, getErrorVariableFromIfCondition, etc.
- Improve compatibility with stdin mode where files may not exist on disk
@willibrandon willibrandon merged commit 93139b2 into main Aug 5, 2025
23 checks passed
@willibrandon willibrandon deleted the feature/ide-quick-fix-expansion branch August 5, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request performance Performance improvements and optimizations. Zero-allocation promise territory. 🚀 tooling Development tools, build systems, and analyzers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant