Skip to content

Conversation

grandizzy
Copy link
Collaborator

@grandizzy grandizzy commented Oct 6, 2025

Motivation

  • closes bug(doc): forge doc seg faults #11966
  • include only fn sig in doc (func.loc_prototype no body) + add ; at the end of sig to match prev behavior
  • remove extra indent of 4 spaces to fix format issue as
image image

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Comment on lines 91 to 96
// Remove extra indent from docs.
self.code = code
.lines()
.map(|line| line.strip_prefix(" ").unwrap_or(line))
.collect::<Vec<_>>()
.join("\n");
Copy link
Contributor

@0xrusowsky 0xrusowsky Oct 6, 2025

Choose a reason for hiding this comment

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

i think that we should make this more robust.

what i'd like to see is the following logic:

  1. get the source code from beginning of line to self.source.range().start
  2. strip the indentation of this source code (should be an empty string or just indentation) from all lines
function topLevel() public {
	// this needs 1 indentation level, none should be removed
}

contract TopLevel {
	function innerLevel() public {
		// this has 2 ind, 1 needs to be removed
	}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed the logic to remove only if starts with > 4 whitespaces (that is to proper format the free functions as in prev version), since we're going to remove solang anyways not sure if should spend more time on this, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think it is fine as a temp workaround as we need to drop the solang dep anyways.
once we do that, we can do it properly

@grandizzy grandizzy marked this pull request as ready for review October 6, 2025 08:31
@grandizzy grandizzy requested a review from 0xrusowsky October 6, 2025 08:31
0xrusowsky
0xrusowsky previously approved these changes Oct 6, 2025
@0xrusowsky
Copy link
Contributor

let's wait for @DaniPopes to have a look before we merge

@grandizzy grandizzy self-assigned this Oct 6, 2025
let mut files = vec![];

// Read and parse source file
if let Some(ast) = gcx.sources.iter().find(|source| {
Copy link
Member

Choose a reason for hiding this comment

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

gcx.get_ast_source

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

self.code = code
.lines()
.map(|line| {
if line.chars().take_while(|c| c.is_whitespace()).count() > 4 {
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just trim_start always

Copy link
Contributor

@0xrusowsky 0xrusowsky Oct 6, 2025

Choose a reason for hiding this comment

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

this is what he did initially, but that's inaccurate.

see the reasoning here: #11980 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

indeed, however I just realized the count check should have been >= 4 so it didn't apply format properly, hence I am in favour of trim_start always, this affects only free functions which will be displayed as below but I don't think it's a biggie

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@grandizzy grandizzy enabled auto-merge (squash) October 6, 2025 13:56
@grandizzy grandizzy merged commit e5078c5 into foundry-rs:master Oct 6, 2025
16 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Oct 6, 2025
@grandizzy grandizzy deleted the issue-11966 branch October 6, 2025 14:02
grandizzy added a commit to grandizzy/foundry that referenced this pull request Oct 6, 2025
* fix(doc): reuse solar sema compiler

* fix: include only fn sig in docs

* proper format docs, remove extra indent & append ; at enf of fn

* changes after review: use get_ast_source, strip prefix always
grandizzy added a commit that referenced this pull request Oct 6, 2025
* fix(doc): reuse solar sema compiler (#11980)

* fix(doc): reuse solar sema compiler

* fix: include only fn sig in docs

* proper format docs, remove extra indent & append ; at enf of fn

* changes after review: use get_ast_source, strip prefix always

* fix(chisel): disable compiler optimizations (#11990)

Add --ir-minimum like in `forge coverage`, and disable optimizations
since we rely on source maps to inspect expressions.

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(doc): forge doc seg faults

3 participants