Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Map Inline Comments with best effort
- Loading branch information
1 parent
8cedbed
commit b1d8db3
Showing
14 changed files
with
735 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Comment Handling | ||
|
||
This plugin attempts to find the original location of a comment and reattach it. If it cannot determine the correct location, it will add a section to the bottom of the page and place the comment there. | ||
|
||
# Comment Matching Process | ||
|
||
## No matches found | ||
If no matches for the text the comment was attached to are found, the comment is moved to the unmatched comment section. | ||
|
||
## Exact Match | ||
The plugin first tries to find an exact match for the comment by comparing the text before and after the comment. If an exact match is found, the comment is attached at that location. | ||
|
||
## Distance of whole before and after | ||
If an exact match is not found, the plugin calculates the "distance" between the text before and after the comment in the original location and each potential new location. This distance is calculated using the Levenshtein distance algorithm, which measures the number of changes (insertions, deletions, or substitutions) required to transform one string into another. If there are more than 40 changes before and after the comment text the node is excluded from being a viable option. The potential matches are sorted based on the calculated distances, and the match with the smallest distance is chosen. | ||
|
||
## Distance of 2 words before and after | ||
If there are still multiple matches with similar distances, the plugin narrows down the selection by comparing only the words immediately surrounding the comment. The Levenshtein distance is calculated again, and the best match is chosen based on the smallest distance. | ||
|
||
## No ability to match | ||
If no suitable match is found, the function returns undefined. | ||
|
||
## Flow chart | ||
```mermaid | ||
flowchart TD | ||
Start --> DoesCommentTextExist{Does comment text exist on page?} | ||
DoesCommentTextExist -->|Yes| DoesExactMatchExist{Does exact match before and after comment text?} | ||
DoesCommentTextExist -->|No| UnmatchedCommentSection[Unmatched Comment Section] | ||
DoesExactMatchExist -->|Yes| AttachComment[Attach Comment To This ADF Node] | ||
DoesExactMatchExist -->|No| CalculateLevenshtein | ||
subgraph WholeBeforeAfter | ||
CalculateLevenshtein[Calculate Levenshtein Distance Between Before and After text] --> SortByMinimumDistance[Sort by minimum distance] | ||
SortByMinimumDistance --> IsFirstItemMinimumDistanceUnder40{Is first item minimum distance under 40 changes?} | ||
end | ||
IsFirstItemMinimumDistanceUnder40 -->|Yes| AttachComment | ||
IsFirstItemMinimumDistanceUnder40 -->|No| GetXWordsBeforeAfterComment[Get X Words before and after comment] | ||
subgraph WordsBeforeAfter | ||
GetXWordsBeforeAfterComment --> TrimBeforeAndAfterToSameLength | ||
TrimBeforeAndAfterToSameLength --> CalculateWordsLevenshtein | ||
CalculateWordsLevenshtein --> IsDistanceLessThan50percentCharacters{IsDistanceLessThan50percentCharacters} | ||
IsDistanceLessThan50percentCharacters -->|Yes| AddToChecks | ||
IsDistanceLessThan50percentCharacters -->|Yes| CalculateWordsLevenshtein | ||
IsDistanceLessThan50percentCharacters -->|No| CalculateWordsLevenshtein | ||
AddToChecks --> SortByWordsMinimumDistance | ||
SortByWordsMinimumDistance --> IsThereAnyItems{IsThereAnyItems} | ||
end | ||
IsThereAnyItems -->|Yes| AttachComment | ||
IsThereAnyItems -->|No| UnmatchedCommentSection |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.