Commit 7ad4cf4
authored
feat: improve error messages with tsc-style diagnostics (#30)
* feat: add Diagnostic class for unified error structure
- 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
* feat: add DiagnosticFormatter with tsc-style output
- 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
* feat: add ErrorReporter for collecting and reporting errors
- 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
* feat: integrate ErrorReporter into CLI
- 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
* refactor: use DiagnosticFormatter in Watcher
- 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
* feat: add location info to MethodDef for better error messages
- 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...
* fix: improve watch mode incremental diagnostics caching
- 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.
* test: add coverage tests for new diagnostic features
- 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
* test: improve test coverage to 93%+ with comprehensive spec additions
- 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, watcher1 parent a7c451d commit 7ad4cf4
File tree
44 files changed
+10546
-261
lines changed- lib
- t_ruby
- parser_combinator/token
- spec
- e2e
- t_ruby
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
44 files changed
+10546
-261
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
| 336 | + | |
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
368 | 373 | | |
369 | 374 | | |
370 | | - | |
| 375 | + | |
371 | 376 | | |
372 | 377 | | |
373 | 378 | | |
| |||
683 | 688 | | |
684 | 689 | | |
685 | 690 | | |
| 691 | + | |
686 | 692 | | |
687 | 693 | | |
688 | | - | |
| 694 | + | |
689 | 695 | | |
690 | 696 | | |
691 | 697 | | |
692 | | - | |
693 | | - | |
694 | | - | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
695 | 717 | | |
696 | 718 | | |
697 | 719 | | |
698 | 720 | | |
699 | 721 | | |
700 | | - | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
701 | 731 | | |
702 | 732 | | |
703 | 733 | | |
704 | 734 | | |
705 | | - | |
706 | | - | |
| 735 | + | |
| 736 | + | |
707 | 737 | | |
708 | 738 | | |
709 | 739 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
225 | 230 | | |
226 | 231 | | |
227 | 232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
79 | 234 | | |
80 | 235 | | |
81 | 236 | | |
| |||
0 commit comments