+
Skip to content

Improve line matching mechanism by introducing line ids #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

T2L
Copy link

@T2L T2L commented Jan 13, 2020

This change allows for matching lines that were edited.

T2L added 2 commits January 13, 2020 23:31
This change allows for matching lines that were edited.
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.6%) to 98.438% when pulling 6403f88 on T2L:patch-1 into 908832c on consolidation:master.

@coveralls
Copy link

coveralls commented Jan 13, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling 4d4df53 on T2L:patch-1 into a27cf1c on consolidation:master.

@T2L
Copy link
Author

T2L commented Jan 13, 2020

AppVeyor fails due to issues with configuration

@greg-1-anderson, please review

@greg-1-anderson
Copy link
Member

Don't worry about the Appveyor failure; the cause is that they only offer one version of PHP at a time, and they recently switched from 7.3 to 7.4 as their one version. We'd have to add PHP 7.4 support here to bring back Appveyor testing. Probably not hard, but optional.

Copy link
Member

@greg-1-anderson greg-1-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you better explain how getLineId is working, and how that helps identify and re-assemble the content and comment lines?

@T2L
Copy link
Author

T2L commented Jan 14, 2020

As far as I understand the existing code is not able to match comments with edited lines. Such comments will be lost.

My patch tries to work around this issue by introducing line ids. Let's go with the slightly changed example from tests:

# Top comments
top:
  # Top one
  one:
    # Top two
    two: two
# Bottom comments
bottom:
  # Bottom one
  one:
    # Bottom two
    two: 2

My code generates ids based on keys (discarding values). Additionally, duplicating keys are taken into account as well. The following ids will be generated:

1|top
1|  one
1|    two
1|bottom
2|  one
2|    two

This approach (partially) handles this issue:

> Comments that appear before sections of yaml that are edited may
> be inadvertently lost. It is recommended to always place comments
> immediately before identifier lines (i.e. "foo:").

As a result, I was able to preserve all comments in my interactively edited yaml file.

Hope my explanations are clear :)

@T2L T2L requested a review from greg-1-anderson January 15, 2020 20:49
@greg-1-anderson
Copy link
Member

That explanation is good; could you make it a code comment or part of the documentation, though?

Also, somewhere it would be good to compare/contrast what happens if this remapping is not done. For example, in the existing implementation of this code, I think that maybe the comment "Bottom two" would end up being attached to both "two:" elements.

@greg-1-anderson
Copy link
Member

The README implies that the existing code works in the same way as the new code. Maybe you could move just the test to another PR, so that we can see a failing test?

@T2L
Copy link
Author

T2L commented Jan 20, 2020

hi @greg-1-anderson:

@T2L
Copy link
Author

T2L commented Feb 12, 2020

hi @greg-1-anderson - any updates on this one?

@T2L
Copy link
Author

T2L commented Mar 11, 2020

hi @greg-1-anderson - are you planning to commit this PR?

@T2L T2L requested a review from greg-1-anderson March 16, 2020 09:21
@T2L
Copy link
Author

T2L commented Apr 24, 2020

hi @greg-1-anderson - any chance this would be committed? It's been almost half of a year now :) Just let me know. Don't want to fork but unless this is the only option - I will.

Thanks!

P.S. Hope, you are safe

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.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载