Skip to content

fix: Key construction in ExtractGoComments#112

Closed
candiduslynx wants to merge 1 commit intoinvopop:mainfrom
cloudquery:fix/add-go-comments-wals
Closed

fix: Key construction in ExtractGoComments#112
candiduslynx wants to merge 1 commit intoinvopop:mainfrom
cloudquery:fix/add-go-comments-wals

Conversation

@candiduslynx
Copy link
Copy Markdown
Contributor

The intended (from README.md) usage of ExtractGoComments(base, path string, commentMap map[string]string) error treats the params as following:

  • base – package import path
  • path – package location on the filesystem
  • commentMap output

If we pass "../" as path param the code will fail to load comments properly because of the path.Join used on the unverified input. Moreover, if the path is the absolute path, the code will join it with base so we end up with keys base + "/" + absPath (cleaned in the path.Clean func, but still).

This PR fixes the behavior in the following way:

  • renaming path to rootPath for better understanding the semantics & not allowing name clashes in the func
  • creating a root variable equal to the absolute path of the rootPath location
  • walking the root path
  • trimming the root prefix of the path prior to joining with the base value

@candiduslynx
Copy link
Copy Markdown
Contributor Author

candiduslynx commented Oct 18, 2023

@samlown I think this actually fixes the intended use of AddGoComments as well (see the fixed test code as well).

See cloudquery/cloudquery#14647 for usage example with both vendored code & path that includes "../".

@candiduslynx
Copy link
Copy Markdown
Contributor Author

Hi @samlown!

Is there a chance to get this PR (and the other PRs I opened t this repo) reviewed & merged?

@samlown samlown added the needs tests Not enough tests for this to be accepted label Feb 19, 2024
"go/doc"
"go/parser"
"go/token"
"golang.org/x/exp/maps"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure that we want to be using experimental stuff...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can copy the implementation as it's just a straightforward map[key]value -> []value func.

LMK if you think this is the way.

Copy link
Copy Markdown
Contributor

@samlown samlown left a comment

Choose a reason for hiding this comment

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

If I understand correctly, this proposal will break previous implementations, certainly the tests have changed suggesting old code would need to be modified. I do not think thats a good idea unless absolutely necessary.

@candiduslynx
Copy link
Copy Markdown
Contributor Author

If I understand correctly, this proposal will break previous implementations, certainly the tests have changed suggesting old code would need to be modified. I do not think thats a good idea unless absolutely necessary.

In this case it is just fixing the bug that exists in the mainline version.
It also allows for easier embedding of the cments from imported/censored structs.

@samlown as the test update suggests, the only issue seen here is adding the full pkg path for the import (or adding a root of vendored pkg to traverse correctly).

Could you please reassess this?

@candiduslynx
Copy link
Copy Markdown
Contributor Author

@samlown any updates?

@candiduslynx candiduslynx requested a review from samlown March 15, 2024 10:48
@candiduslynx
Copy link
Copy Markdown
Contributor Author

@samlown I'm closing this PR for 2 reasons:

  1. I no longer have access to the fork the PR was opened from
  2. It seems to me that you just don't have the capacity to get this reviewed and merged

If you'll be available for review & merging please tag me here & I'll reopen from my own fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs tests Not enough tests for this to be accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants