Skip to content

Remove dead fragmentation state and duplicate source reads#71

Merged
Vladyslav-Kuksiuk merged 7 commits into
masterfrom
remove-unused-code
Jun 23, 2026
Merged

Remove dead fragmentation state and duplicate source reads#71
Vladyslav-Kuksiuk merged 7 commits into
masterfrom
remove-unused-code

Conversation

@Vladyslav-Kuksiuk

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

This PR removes unused fragmentation state and duplicate source reads, and simplifies encoding validation because ASCII is already valid UTF-8.

Resolves this issue.

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk self-assigned this Jun 23, 2026
…-unused-code

# Conflicts:
#	indent/indent_test.go
Comment thread fragmentation/encoding.go Outdated
Configuration config.Configuration
SourcesRoot _type.NamedPath
CodeFile string
fragmentBuilders map[string]*FragmentBuilder

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's document this prop.

Comment thread fragmentation/encoding.go Outdated
)

const lastASCIIchar = 127
var errUnsupportedEncoding = errors.New("unsupported source encoding: expected UTF-8")

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.

Please capitalize the sentence and add a period at the end.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This follows the Go error-handling convention: errors are combined into a single line using :.

Comment thread indent/indent_test.go
"return;",
}))
})

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.

Consider removing this empty line.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is removed.

Comment thread fragmentation/encoding.go Outdated
)

const lastASCIIchar = 127
var errUnsupportedEncoding = errors.New("unsupported source encoding: expected UTF-8")

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.

Document it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've moved it into the method, and it is documented there.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

According to this comment: #71 (comment), it's better to use this error extracted(because it must be checked in another place), so I've added own type for it.

Comment thread fragmentation/fragmentation.go Outdated
type Fragmentation struct {
Configuration config.Configuration
SourcesRoot _type.NamedPath
CodeFile string

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.

Why is this capitilized?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was part of the public API, but it no longer is, so we can change it to lowercase.

@Oleg-Melnik Oleg-Melnik requested a review from Copilot June 23, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR simplifies the fragmentation/ path by removing unused fragmentation state, avoiding duplicate reads of source files during encoding validation, and relying on UTF-8 validation only (ASCII is a subset of UTF-8). It aligns with the intent of issue #58 by making source resolution and fragmentation easier to reason about.

Changes:

  • Removed unused fragmentation state (Fragmentation.Configuration, Fragmentation.SourcesRoot) and simplified NewFragmentation to take only a file path.
  • Reworked fragmentation to read a source file once (os.ReadFile), validate UTF-8, then scan from memory.
  • Updated resolver/source selection to skip non-UTF-8 sources and added a regression test for trying the next code root.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
indent/indent_test.go Removes an extraneous blank line from the indent test.
fragmentation/resolver.go Replaces resolved-path struct with an absolute-path key; resolves sources by attempting cached fragmentation and skipping unsupported encodings.
fragmentation/fragmentation.go Removes unused config/root fields and eliminates duplicate file reads by validating encoding on already-loaded content.
fragmentation/fragmentation_test.go Adds a test ensuring non-UTF-8 sources are skipped in favor of the next configured code root; updates NewFragmentation call sites.
fragmentation/encoding.go Simplifies encoding validation to UTF-8-only via utf8.Valid.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fragmentation/encoding.go

@Oleg-Melnik Oleg-Melnik left a comment

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.

@Vladyslav-Kuksiuk LGTM with Copilot’s comments addressed.

@Vladyslav-Kuksiuk Vladyslav-Kuksiuk merged commit 1296a36 into master Jun 23, 2026
3 checks passed
@Vladyslav-Kuksiuk Vladyslav-Kuksiuk deleted the remove-unused-code branch June 23, 2026 11:22
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.

Remove dead fragmentation state and duplicate source reads

4 participants