Skip to content
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

forge doc: links to functions or objects in other files don't work #9506

Open
2 tasks done
lilyanB opened this issue Dec 6, 2024 · 6 comments
Open
2 tasks done

forge doc: links to functions or objects in other files don't work #9506

lilyanB opened this issue Dec 6, 2024 · 6 comments
Labels
Cmd-forge-doc Command: forge doc P-low Priority: low T-bug Type: bug T-post-V1 Area: to tackle after V1 T-to-investigate Type: to investigate

Comments

@lilyanB
Copy link

lilyanB commented Dec 6, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0

What command(s) is the bug in?

forge doc --build --serve

Operating System

Linux

Describe the bug

Hello, I need help with the forge doc please.
When I build the doc, some links to functions/objects in the parent contract (when your contract is inherited from the library) don't work. I have created a repo to view a simple example of code: https://github.com/lilyanB/testFoundry/blob/master/src/libraries/lib.sol#L6

The result when I run forge doc --build --serve:
image

Thanks

@lilyanB lilyanB added T-bug Type: bug T-needs-triage Type: this issue needs to be labelled labels Dec 6, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Dec 6, 2024
@lilyanB lilyanB changed the title forge doc: links to functions or object in other files forge doc: links to functions or objects in other files don't work Dec 6, 2024
@grandizzy
Copy link
Collaborator

grandizzy commented Dec 6, 2024

Het @lilyanB that's not the way natspec inheritance work, please check https://docs.soliditylang.org/en/latest/natspec-format.html#inheritance-notes

Please open a ticket if you see problems with using inheritdoc. Thank you

@grandizzy grandizzy closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Dec 6, 2024
@lilyanB
Copy link
Author

lilyanB commented Dec 6, 2024

Het @lilyanB that's not the way natspec inheritance work, please check https://docs.soliditylang.org/en/latest/natspec-format.html#inheritance-notes

Please open a ticket if you see problems with using inheritdoc. Thank you

Thanks for your explanation. I have pushed code with another bug I think. there is no documentation in the function accessible directly to the parent of the current contract:

image

@grandizzy
Copy link
Collaborator

grandizzy commented Dec 6, 2024

that's still not how @inheritdoc works, should be something like

diff --git a/src/Counter.sol b/src/Counter.sol
index 2c0a207..90e9f27 100644
--- a/src/Counter.sol
+++ b/src/Counter.sol
@@ -10,8 +10,8 @@ contract Counter is ParentCounter, ICounter {
         return 100;
     }
 
-    /// @notice more info in {testParentFunction}
-    function testFunctionWithParent() public pure returns (uint256) {
-        return testParentFunction();
+    /// @inheritdoc ParentCounter
+    function testFunctionWithParent() public pure override returns (uint256) {
+        return super.testFunctionWithParent();
     }
 }
diff --git a/src/ParentCounter.sol b/src/ParentCounter.sol
index 4be1482..d48faeb 100644
--- a/src/ParentCounter.sol
+++ b/src/ParentCounter.sol
@@ -2,7 +2,8 @@
 pragma solidity ^0.8.13;
 
 contract ParentCounter {
-    function testParentFunction() public pure returns (uint256) {
+    /// @notice info for ParentCounter.testFunctionWithParent function
+    function testFunctionWithParent() public pure virtual returns (uint256) {
         return 100;
     }
 }

@lilyanB
Copy link
Author

lilyanB commented Dec 9, 2024

that's still not how @inheritdoc works, should be something like

diff --git a/src/Counter.sol b/src/Counter.sol
index 2c0a207..90e9f27 100644
--- a/src/Counter.sol
+++ b/src/Counter.sol
@@ -10,8 +10,8 @@ contract Counter is ParentCounter, ICounter {
         return 100;
     }
 
-    /// @notice more info in {testParentFunction}
-    function testFunctionWithParent() public pure returns (uint256) {
-        return testParentFunction();
+    /// @inheritdoc ParentCounter
+    function testFunctionWithParent() public pure override returns (uint256) {
+        return super.testFunctionWithParent();
     }
 }
diff --git a/src/ParentCounter.sol b/src/ParentCounter.sol
index 4be1482..d48faeb 100644
--- a/src/ParentCounter.sol
+++ b/src/ParentCounter.sol
@@ -2,7 +2,8 @@
 pragma solidity ^0.8.13;
 
 contract ParentCounter {
-    function testParentFunction() public pure returns (uint256) {
+    /// @notice info for ParentCounter.testFunctionWithParent function
+    function testFunctionWithParent() public pure virtual returns (uint256) {
         return 100;
     }
 }

Thanks for your example. But I want to create a link to the parent contract. When the user clicks on it, it will move directly to the ParentCounter.testparentfunction doc.
for example:

@notice This works: {testFunction}
@dev This does not: {testParentFunction}

@beeb
Copy link
Contributor

beeb commented Dec 12, 2024

@grandizzy the problem is that link resolution in generated docs does not work as it should.

The source code in https://github.com/foundry-rs/foundry/blob/539760c2d158c91c28cc3d3400963e09f49882ba/crates/doc/src/preprocessor/infer_hyperlinks.rs suggests that links in the format {Artifact-object} should resolve to a markdown link to the relevant item, even if they are located on other pages, but this does not work. Likewise, links to functions or structs/errors/enums which are declared in a parent contract (from which the current contract inherits) do not work.

As @lilyanB described, links to functions within the same file are resolved correctly, but links to functions in the parent contract are not resolved.

// file A.sol
contract A {
    function foo() external {}
}
// file B.sol
import { A } from "./A.sol";
contract B is A {
    /**
     * @notice You should call {foo} or {A-foo} before calling this function
     */
    function bar() external {}
}

The links to foo do not work.

Could you re-open the issue please?

@grandizzy
Copy link
Collaborator

Ah, I see, reopening to check above. Thanks

@grandizzy grandizzy reopened this Dec 12, 2024
@grandizzy grandizzy added T-to-investigate Type: to investigate T-post-V1 Area: to tackle after V1 P-low Priority: low Cmd-forge-doc Command: forge doc and removed T-needs-triage Type: this issue needs to be labelled labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cmd-forge-doc Command: forge doc P-low Priority: low T-bug Type: bug T-post-V1 Area: to tackle after V1 T-to-investigate Type: to investigate
Projects
Status: Done
Development

No branches or pull requests

3 participants