Skip to content

fix: resolve TypeScript error detection issues#69

Closed
dmmulroy wants to merge 4 commits intomainfrom
fix/error-detection-issues
Closed

fix: resolve TypeScript error detection issues#69
dmmulroy wants to merge 4 commits intomainfrom
fix/error-detection-issues

Conversation

@dmmulroy
Copy link
Copy Markdown
Owner

@dmmulroy dmmulroy commented Jul 8, 2025

Summary

This PR fixes three critical issues that prevented tsc.nvim from detecting TypeScript errors that were visible when running pnpm run typecheck or tsc directly, while maintaining 100%
backward compatibility
with existing configurations.

Root Causes Fixed

  1. Auto-detection override: The default config always called find_nearest_tsconfig() for the project flag, overriding user configurations. Now auto-detection only occurs when no
    explicit project is configured.

  2. ANSI color parsing: TypeScript outputs colored text by default, but the regex parser expected plain text. Fixed by automatically adding --color false flag (unless user explicitly
    sets color = true).

  3. Working directory mismatch: The plugin ran from the current buffer directory instead of project root. Fixed by setting cwd option in jobstart() to the project root directory.

Key Changes

  • lua/tsc/init.lua:

    • Removed hardcoded project function from default config
    • Added proper working directory handling in monorepo loop
    • Enhanced error validation and handling
  • lua/tsc/utils.lua:

    • Added conditional auto-detection logic in parse_flags()
    • Added automatic --color false flag (respects user override)
    • Updated find_nearest_tsconfig() to return absolute paths in array format
    • Added get_project_root() helper function
  • lua/tsc/utils-test.lua:

    • Comprehensive test suite covering all utility functions
    • Tests for each bug fix to prevent regression
    • Edge cases and error condition testing
  • Documentation:

    • Updated README.md with accurate configuration examples
    • Added CLAUDE.md with bug fix details and architecture notes
    • Clarified automatic color flag behavior

Monorepo Integration

This PR has been updated to work seamlessly with the new monorepo features:

  • Full compatibility with run_as_monorepo = true
  • Works with Trouble integration (use_trouble_qflist = true)
  • Supports diagnostics mode (use_diagnostics = true)
  • Compatible with all new commands (TSCStop, TSCOpen, TSCClose)

Backward Compatibility

✅ 100% backward compatible - all existing configurations continue to work:

  • String flags: flags = "--noEmit --watch"
  • Function-based project: project = function() return "path" end
  • Object flags: flags = { noEmit = true, project = "/path" }
  • Auto-detection: flags = { noEmit = true } (auto-finds tsconfig) ✅
  • Color overrides: flags = { color = true }

Migration Path

Users can migrate gradually:

-- Old format (still works)
flags = "--noEmit --watch"

-- New format (recommended)
flags = { noEmit = true, watch = true }

-- With explicit overrides
flags = { noEmit = true, color = true, project = "/custom/path" }

Test Plan

- Test with different TypeScript project structures (single project, monorepo)
- Test with different tsc versions and configurations
- Verify compatibility with existing user configurations
- Test manual :TSC command and watch mode functionality
- Test new monorepo features (run_as_monorepo = true)
- Test Trouble integration (use_trouble_qflist = true)
- Test diagnostics mode (use_diagnostics = true)
- Comprehensive unit tests for all utility functions
- Test edge cases and error conditions
- Verify all new commands work (TSCStop, TSCOpen, TSCClose)

Before/After

Before: Plugin reported "No errors found" even when tsc showed errors
After: Plugin detects same errors as pnpm run typecheck or tsc directly

Files Changed

- lua/tsc/init.lua - Main plugin integration with monorepo support
- lua/tsc/utils.lua - Core utility functions with bug fixes
- lua/tsc/utils-test.lua - Comprehensive test suite (new file)
- README.md - Updated documentation with accurate configuration
- CLAUDE.md - Development notes and architecture documentation (new file)

The plugin now properly detects TypeScript errors while maintaining full backward compatibility and supporting all new monorepo, Trouble, and diagnostics features.

dmmulroy added 4 commits July 8, 2025 12:12
This commit fixes three critical issues that prevented tsc.nvim from detecting TypeScript errors that were visible when running tsc directly:

1. Auto-detection override: Removed hardcoded project function from default config to allow user configurations to take precedence while maintaining backward compatibility through conditional auto-detection in parse_flags()

2. ANSI color parsing: Added automatic --color false flag (unless user explicitly sets color) to ensure TypeScript outputs plain text that the regex parser can handle properly

3. Working directory mismatch: Set proper cwd option in jobstart() to run tsc from project root instead of current buffer directory, ensuring accurate type-checking context

Additional improvements:
- Enhanced error handling with validation for tsconfig.json existence and readability
- Added comprehensive test suite in utils-test.lua covering all utility functions and edge cases
- Updated documentation to reflect new behavior and configuration options
- Maintained full backward compatibility with existing user configurations

The plugin now properly detects TypeScript errors that match the output of running pnpm run typecheck or tsc directly.
- Updated find_nearest_tsconfig to return array format for monorepo support
- Integrated working directory fix with new monorepo architecture
- Updated auto-detection logic to work with array format
- Updated tests to match new API
- Maintained backward compatibility with new features
- Fix bin_path default value (nil, not utils.find_tsc_bin())
- Clarify that --color false is added automatically unless explicitly overridden
- Add note about color flag behavior in configuration section
- Improve accuracy of default configuration documentation
- Fix spacing and formatting issues in utils.lua
- Fix spacing and formatting issues in utils-test.lua
- Ensure consistency with .stylua.toml configuration
- All files now pass stylua --check validation
@dmmulroy dmmulroy closed this Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant