feat(parser/diff): option to hide common prefix
This commit is contained in:
		
							parent
							
								
									7f7eead5f7
								
							
						
					
					
						commit
						ab41926fc0
					
				|  | @ -22,6 +22,7 @@ type Conf struct { | ||||||
| 			ForceQuitOnDiff  bool | 			ForceQuitOnDiff  bool | ||||||
| 			MaxDiffLength    int `default:"2048"` // just for reference
 | 			MaxDiffLength    int `default:"2048"` // just for reference
 | ||||||
| 			MaxDiffLines     int `default:"50"`   // just for reference
 | 			MaxDiffLines     int `default:"50"`   // just for reference
 | ||||||
|  | 			HideCommonPrefix bool | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -85,6 +85,23 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) ( | ||||||
| 						} | 						} | ||||||
| 						answerLines := strings.Split(answerStr, "\n") | 						answerLines := strings.Split(answerStr, "\n") | ||||||
| 						resultLines := strings.Split(resultStr, "\n") | 						resultLines := strings.Split(resultStr, "\n") | ||||||
|  | 						commonPreixLineCount := 0 | ||||||
|  | 						if output.HideCommonPrefix { | ||||||
|  | 							n := 0 | ||||||
|  | 							for ; n < len(answerLines) && | ||||||
|  | 								n < len(resultLines) && | ||||||
|  | 								stringsEqual( | ||||||
|  | 									answerLines[n], | ||||||
|  | 									resultLines[n], | ||||||
|  | 									output.CompareSpace, | ||||||
|  | 								); n += 1 { | ||||||
|  | 							} | ||||||
|  | 							if n > 0 { | ||||||
|  | 								answerLines = answerLines[n:] | ||||||
|  | 								resultLines = resultLines[n:] | ||||||
|  | 								commonPreixLineCount = n | ||||||
|  | 							} | ||||||
|  | 						} | ||||||
| 						if len(answerLines) > output.MaxDiffLines { | 						if len(answerLines) > output.MaxDiffLines { | ||||||
| 							answerLines = answerLines[:output.MaxDiffLines] | 							answerLines = answerLines[:output.MaxDiffLines] | ||||||
| 							truncated = true | 							truncated = true | ||||||
|  | @ -104,12 +121,18 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) ( | ||||||
| 						if truncated { | 						if truncated { | ||||||
| 							diffOutput += "\n\n(truncated)" | 							diffOutput += "\n\n(truncated)" | ||||||
| 						} | 						} | ||||||
|  | 						if commonPreixLineCount > 0 { | ||||||
|  | 							diffOutput = fmt.Sprintf( | ||||||
|  | 								"(%d line(s) of common prefix hidden)\n\n", | ||||||
|  | 								commonPreixLineCount, | ||||||
|  | 							) + diffOutput | ||||||
|  | 						} | ||||||
| 						comment += fmt.Sprintf( | 						comment += fmt.Sprintf( | ||||||
| 							"```diff\n%s\n```\n", | 							"```diff\n%s\n```\n", | ||||||
| 							diffOutput, | 							diffOutput, | ||||||
| 						) | 						) | ||||||
| 					} else { | 					} else { | ||||||
| 						comment += "(Content hidden.)\n" | 						comment += "(content hidden)\n" | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user