fix: resolve TypeScript error detection issues#69
Closed
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes three critical issues that prevented tsc.nvim from detecting TypeScript errors that were visible when running
pnpm run typecheckortscdirectly, while maintaining 100%backward compatibility with existing configurations.
Root Causes Fixed
Auto-detection override: The default config always called
find_nearest_tsconfig()for the project flag, overriding user configurations. Now auto-detection only occurs when noexplicit project is configured.
ANSI color parsing: TypeScript outputs colored text by default, but the regex parser expected plain text. Fixed by automatically adding
--color falseflag (unless user explicitlysets
color = true).Working directory mismatch: The plugin ran from the current buffer directory instead of project root. Fixed by setting
cwdoption injobstart()to the project root directory.Key Changes
lua/tsc/init.lua:lua/tsc/utils.lua:parse_flags()--color falseflag (respects user override)find_nearest_tsconfig()to return absolute paths in array formatget_project_root()helper functionlua/tsc/utils-test.lua:Documentation:
Monorepo Integration
This PR has been updated to work seamlessly with the new monorepo features:
run_as_monorepo = trueuse_trouble_qflist = true)use_diagnostics = true)TSCStop,TSCOpen,TSCClose)Backward Compatibility
✅ 100% backward compatible - all existing configurations continue to work:
flags = "--noEmit --watch"✅project = function() return "path" end✅flags = { noEmit = true, project = "/path" }✅flags = { noEmit = true }(auto-finds tsconfig) ✅flags = { color = true }✅Migration Path
Users can migrate gradually: