Skip to content

Conversation

@yhk1038
Copy link
Contributor

@yhk1038 yhk1038 commented Dec 29, 2025

Summary

  • Add unified Diagnostic class for structured error representation
  • Implement DiagnosticFormatter with TypeScript-style output (file:line:col format)
  • Add ErrorReporter for collecting and formatting multiple diagnostics
  • Integrate new diagnostic system into CLI, Watcher, and LSP server
  • Fix watch mode incremental diagnostics caching to preserve errors across file saves
  • Add HashLiteralType IR node for hash literal type parsing
  • Improve colon spacing validation in TokenDeclarationParser
  • Support unicode identifiers (Korean function names)
  • Add Float to valid types, fix duplicate function detection across classes

Test plan

  • All existing tests pass
  • New spec files added: diagnostic_spec.rb, diagnostic_formatter_spec.rb, error_reporter_spec.rb, colon_spacing_spec.rb
  • Watch mode tested: errors preserved correctly when saving individual files

- Add Diagnostic class with code, message, file, line, column attributes
- Add factory methods: from_type_check_error, from_parse_error, from_scan_error
- Add comprehensive tests for all functionality
- TR1xxx codes for parser errors, TR2xxx for type errors
- Format errors as file:line:col - severity CODE: message
- Display source code snippets with line numbers
- Show error markers (~~~) under problem location
- Include Expected/Actual/Suggestion context
- Support ANSI colors with TTY auto-detection
- Format summary line: Found X errors and Y warnings
- Collect multiple diagnostics during compilation
- Convert TypeCheckError, ParseError, ScanError to Diagnostic
- Auto-load source from file when not provided
- Report formatted output using DiagnosticFormatter
- Track error vs warning counts
- Use ErrorReporter for TypeCheckError, ParseError, ScanError
- Display tsc-style formatted error output
- Include source code snippets and error markers
- Show Expected/Actual/Suggestion context
- Display summary line with error count
- Replace hash-based error format with Diagnostic objects
- Use DiagnosticFormatter for consistent tsc-style output
- Include source code snippets in watch mode errors
- Update tests to expect Diagnostic objects
- TokenDeclarationParser: capture def token's line/column
- Parser.parse_function_with_body: add line/column to func_info
- Parser.parse_method_in_class: add line/column to method_info
- IR CodeGenerator.build_method: pass location to MethodDef

Error messages now show exact line:column position:
  src/file.trb:18:1 - error TR2001: Type mismatch...
- Add @file_diagnostics cache to preserve errors across incremental compiles
- Use compile_with_diagnostics consistently in compile_file_with_ir
- Add update_file_hash method to EnhancedIncrementalCompiler
- Rename file_hash to compute_file_hash (private method)
- Fix error count calculation from cached diagnostics
- Fix various RuboCop offenses (guard clauses, multiple comparison)

This ensures that when saving a file in watch mode, errors from other
files are preserved and the total error count remains accurate.
- Add error_handler tests for Float type, unicode identifiers, class scoping
- Add colon_spacing tests for hash literal types and keyword arguments
- Add compiler tests for compile_with_diagnostics method
- Add method name validation for spaces (TR1003 error)
- Add extensive tests for parser_combinator (Lookahead, NotFollowedBy, FlatMap, Pure, Fail, token parsers)
- Add comprehensive SMT solver tests (Formula, BoolConst, Variable, Not, And, Or, Implies, Iff, TypeVar, etc.)
- Add IR node tests (children methods, TypeNode, LiteralType, HashLiteralType, Visitor)
- Add TypeChecker tests (TypeCheckError, TypeHierarchy, FlowContext, validate_type, etc.)
- Add new spec files for untested modules:
  - benchmark_spec.rb, doc_generator_spec.rb
  - docs_badge_generator_spec.rb, docs_example_extractor_spec.rb, docs_example_verifier_spec.rb
  - generic_type_parser_spec.rb, intersection_type_parser_spec.rb, union_type_parser_spec.rb
  - string_utils_spec.rb, type_env_spec.rb, version_checker_spec.rb
- Enhance existing specs: ast_type_inferrer, bundler_integration, cache, cli
  constraint_checker, error_handler, lsp_server, package_manager, type_inferencer, watcher
@yhk1038 yhk1038 merged commit 7ad4cf4 into main Dec 29, 2025
9 checks passed
@yhk1038 yhk1038 deleted the feature/improve-error-messages branch December 29, 2025 12:41
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.

2 participants