Skip to content

Commit 36989b7

Browse files
authored
chore: remove redundant comments across the codebase (#1535)
1 parent 4ee665c commit 36989b7

28 files changed

Lines changed: 8 additions & 207 deletions

internal/adapter/accessibility/adapter.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ var elementSlicePool = sync.Pool{
5353
}
5454

5555
// Adapter implements ports.AccessibilityPort by wrapping the ax.Client.
56-
// It converts between domain models and infrastructure types.
5756
type Adapter struct {
58-
// logger for adapter.
5957
logger *zap.Logger
6058
client ax.Client
6159
excludedBundles map[string]bool
@@ -86,13 +84,11 @@ func NewAdapter(
8684
}
8785

8886
// Logger returns the logger for the adapter.
89-
// It is used for testing mainly.
9087
func (a *Adapter) Logger() *zap.Logger {
9188
return a.logger
9289
}
9390

9491
// ClickableRoles returns the list of clickable roles.
95-
// It is used for testing mainly.
9692
func (a *Adapter) ClickableRoles() []string {
9793
return a.clickableRoles
9894
}
@@ -179,7 +175,6 @@ func (a *Adapter) PerformAction(
179175
element *element.Element,
180176
actionType action.Type,
181177
) error {
182-
// Check context
183178
select {
184179
case <-ctx.Done():
185180
return derrors.Wrap(ctx.Err(), derrors.CodeContextCanceled, "operation canceled")
@@ -283,8 +278,6 @@ func (a *Adapter) IsAppExcluded(_ context.Context, bundleID string) bool {
283278
}
284279

285280
// ReleaseHeldButtons releases any mouse button this process still holds down.
286-
// The per-platform release lives in element_<os>.go; it is unexported because
287-
// only this adapter and the infra client may reach it.
288281
func (a *Adapter) ReleaseHeldButtons(ctx context.Context) error {
289282
err := a.checkContext(ctx)
290283
if err != nil {
@@ -356,16 +349,14 @@ func (a *Adapter) processClickableNodes(
356349
clickableNodes []ax.Node,
357350
filter ports.ElementFilter,
358351
) ([]*element.Element, error) {
359-
// Get pooled slice and reset it
360352
elementsPtr, ok := elementSlicePool.Get().(*[]*element.Element)
361353
if !ok {
362354
s := make([]*element.Element, 0, TypicalElementCount)
363355
elementsPtr = &s
364356
}
365357

366-
elements := (*elementsPtr)[:0] // Reset to zero length but keep capacity
358+
elements := (*elementsPtr)[:0]
367359
defer func() {
368-
// Clear references before returning to pool
369360
for i := range elements {
370361
elements[i] = nil
371362
}
@@ -381,13 +372,11 @@ func (a *Adapter) processClickableNodes(
381372
)
382373
}()
383374

384-
// Concurrent processing for large number of nodes
385375
if len(clickableNodes) > ConcurrentProcessingThreshold {
386376
return a.processClickableNodesConcurrent(ctx, clickableNodes, filter)
387377
}
388378

389379
for index, node := range clickableNodes {
390-
// Check context periodically
391380
if index%contextCheckInterval == 0 {
392381
err := a.checkContext(ctx)
393382
if err != nil {
@@ -418,7 +407,6 @@ func (a *Adapter) processClickableNodes(
418407
}
419408
}
420409

421-
// Make a copy to return since we're returning the pooled slice
422410
result := make([]*element.Element, len(elements))
423411
copy(result, elements)
424412

@@ -432,9 +420,7 @@ func (a *Adapter) processClickableNodesConcurrent(
432420
filter ports.ElementFilter,
433421
) ([]*element.Element, error) {
434422
numWorkers := min(
435-
// Use available parallelism
436423
runtime.GOMAXPROCS(0),
437-
// Cap to avoid diminishing returns
438424
maxConcurrentWorkers)
439425

440426
chunkSize := (len(nodes) + numWorkers - 1) / numWorkers
@@ -464,7 +450,6 @@ func (a *Adapter) processClickableNodesConcurrent(
464450
go func(chunk []ax.Node) {
465451
defer waitGroup.Done()
466452

467-
// Use local slice to avoid locking
468453
localElements := make([]*element.Element, 0, len(chunk))
469454

470455
for idx, node := range chunk {
@@ -501,8 +486,6 @@ func (a *Adapter) processClickableNodesConcurrent(
501486
close(results)
502487
}()
503488

504-
// Collect results
505-
// Pre-allocate based on input size estimate (conservative)
506489
allElements := make([]*element.Element, 0, len(nodes)/EstimatedFilteringRatio)
507490

508491
for res := range results {

internal/adapter/accessibility/adapter_conversion.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@ func (a *Adapter) convertToDomainElement(node ax.Node) (*element.Element, error)
1212
return nil, derrors.New(derrors.CodeInvalidInput, "node is nil")
1313
}
1414

15-
// Create element ID from unique identifier
1615
elementID := element.ID(node.ID())
17-
18-
// Get bounds
1916
bounds := node.Bounds()
20-
21-
// Convert role
2217
role := element.Role(node.Role())
23-
24-
// Determine if clickable
2518
isClickable := node.IsClickable()
2619

2720
searchText := ""

internal/adapter/accessibility/adapter_filtering.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,22 @@ func (a *Adapter) MatchesFilter(
1616
elem *element.Element,
1717
filter ports.ElementFilter,
1818
) bool {
19-
// Check minimum size
2019
bounds := elem.Bounds()
2120
if bounds.Dx() < filter.MinSize.X || bounds.Dy() < filter.MinSize.Y {
2221
return false
2322
}
2423

25-
// Check role inclusion
2624
if len(filter.Roles) > 0 {
2725
found := slices.Contains(filter.Roles, elem.Role())
2826
if !found {
2927
return false
3028
}
3129
}
3230

33-
// Check role exclusion
3431
if slices.Contains(filter.ExcludeRoles, elem.Role()) {
3532
return false
3633
}
3734

38-
// Check title contains filter
39-
// NOTE: filter.TitleContains is expected to be pre-lowercased by the caller (e.g. ClickableElements).
40-
// Direct callers of MatchesFilter must also lowercase filter strings before passing them.
4135
titleMatched := false
4236
if filter.TitleContains != "" {
4337
title := elem.Title()
@@ -47,7 +41,6 @@ func (a *Adapter) MatchesFilter(
4741
}
4842
}
4943

50-
// Check description contains filter
5144
descMatched := false
5245
if filter.DescriptionContains != "" {
5346
description := elem.Description()
@@ -60,7 +53,6 @@ func (a *Adapter) MatchesFilter(
6053
}
6154
}
6255

63-
// Check value contains filter
6456
valueMatched := false
6557
if filter.ValueContains != "" {
6658
value := textForFilter(elem)
@@ -70,7 +62,6 @@ func (a *Adapter) MatchesFilter(
7062
}
7163
}
7264

73-
// Check any of the additional text substrings match (OR logic)
7465
textListMatched := false
7566
if len(filter.TextContainsList) > 0 {
7667
title := elem.Title()

internal/adapter/overlay/render/grid/overlay_darwin.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ func (o *Overlay) DrawGrid(grid *domainGrid.Grid, currentInput string, style Sty
370370
runtime.ReadMemStats(&msBefore)
371371
}
372372

373-
// Check if we can do incremental updates (always try if we have previous state)
374373
o.gridStateMu.RLock()
375374
canIncrementalUpdate := o.previousGrid != nil
376375
o.gridStateMu.RUnlock()
@@ -582,7 +581,6 @@ func (o *Overlay) drawGridIncremental(
582581
return false // No previous state to compare against
583582
}
584583

585-
// Check if only the input changed (common case for typing)
586584
if o.gridsAreStructurallyEqual(grid, previousGrid) && style == previousStyle {
587585
// Only input changed - we can do incremental match updates
588586
if currentInput != previousInput {
@@ -623,7 +621,6 @@ func (o *Overlay) gridsAreStructurallyEqual(a, b *domainGrid.Grid) bool {
623621
return false
624622
}
625623

626-
// Check if all cells have the same coordinates and bounds
627624
for i, aCell := range aCells {
628625
bCell := bCells[i]
629626
if aCell.Coordinate() != bCell.Coordinate() ||

internal/adapter/overlay/render/hints/overlay_darwin.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,6 @@ func (o *Overlay) drawHintsInternal(hints []*Hint, style StyleMode, showArrow bo
410410
}
411411
}
412412

413-
// Check if we can do incremental updates
414413
o.hintStateMu.RLock()
415414
canIncrementalUpdate := len(o.previousHints) > 0
416415
o.hintStateMu.RUnlock()
@@ -571,7 +570,6 @@ func (o *Overlay) drawHintsIncremental(
571570
return false // No previous state to compare against
572571
}
573572

574-
// Check if only the input changed (common case for typing)
575573
if o.hintsAreStructurallyEqual(hints, previousHints) && style == previousStyle {
576574
// Only input changed - we can do incremental match updates
577575
if currentInput != previousInput {

internal/adapter/overlay/render/overlayutil/util.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,16 @@ func releaseCallbackID(callbackID uint64) {
7575

7676
if !allocatedCallbackIDs[callbackID] {
7777
allocatedCallbackIDsMu.Unlock()
78-
// ID is not allocated, nothing to release
7978
return
8079
}
8180

8281
delete(allocatedCallbackIDs, callbackID)
8382
allocatedCallbackIDsMu.Unlock()
8483

85-
// Remove from global registry
8684
callbackManagerRegistryMu.Lock()
8785
delete(callbackManagerRegistry, callbackID)
8886
callbackManagerRegistryMu.Unlock()
8987

90-
// Return the ID to the free pool for reuse
9188
freeCallbackIDsMu.Lock()
9289

9390
freeCallbackIDs = append(freeCallbackIDs, callbackID)
@@ -127,16 +124,11 @@ func CompleteGlobalCallback(callbackID uint64, expectedGeneration uint64) {
127124
return
128125
}
129126

130-
// Atomically remove the registry entry so no concurrent deferred release
131-
// or new allocation can race with us on this callback ID.
132127
delete(callbackManagerRegistry, callbackID)
133128
callbackManagerRegistryMu.Unlock()
134129

135130
entry.manager.CompleteCallback(callbackID)
136131

137-
// Return the ID to the free pool. Since we already deleted the registry
138-
// entry above, releaseCallbackID will skip the registry delete (no-op)
139-
// but will still clear allocatedCallbackIDs and return the ID to the pool.
140132
releaseCallbackID(callbackID)
141133
}
142134

@@ -269,10 +261,7 @@ func (c *CallbackManager) CompleteCallback(callbackID uint64) {
269261
// This should be called when the overlay is being destroyed.
270262
// Safe to call multiple times - only executes cleanup once.
271263
func (c *CallbackManager) Cleanup() {
272-
// Use sync.Once to ensure cleanup only happens once
273-
// This prevents panic from double-close of the cancel channel
274264
c.cleanupOnce.Do(func() {
275-
// Close the cancel channel to stop all background goroutines
276265
close(c.cancelCh)
277266

278267
// Snapshot and clear callbackMap under callbackMu first, then remove

internal/adapter/overlay/render/recursivegrid/overlay_darwin.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ import (
3131

3232
//export recursiveGridResizeCompletionCallback
3333
func recursiveGridResizeCompletionCallback(context unsafe.Pointer) {
34-
// Read callback context from the C-heap-allocated CallbackContext
3534
ctx := *(*overlayutil.CallbackContext)(context)
36-
// Free the C-allocated context now that we've copied the values
3735
overlayutil.FreeCallbackContext(context)
3836
overlayutil.CompleteGlobalCallback(ctx.CallbackID, ctx.Generation)
3937
}
@@ -304,7 +302,6 @@ func (o *Overlay) DrawRecursiveGrid(
304302
dims = usableDims
305303
keyCount := dims.CellCount()
306304

307-
// Validate keys length matches grid dimensions
308305
keyRunes := []rune(keys)
309306
if len(keyRunes) != keyCount {
310307
o.logger.Warn(
@@ -316,7 +313,6 @@ func (o *Overlay) DrawRecursiveGrid(
316313
// draw call so that freeLabelCache cannot free labels mid-draw.
317314
o.drawMu.RLock()
318315

319-
// Compute cell positions using the shared helper (same as Divide()).
320316
cellRects := recursivegrid.ComputeGridCells(bounds, dims)
321317

322318
cells := make([]C.GridCell, keyCount)
@@ -339,9 +335,6 @@ func (o *Overlay) DrawRecursiveGrid(
339335
}
340336
}
341337

342-
// Build sub-key preview labels.
343-
// When a label char override is set, repeat it to match the grid cell count
344-
// so the native renderer gets the expected number of labels.
345338
subKeyLabel := style.SubKeyPreviewLabelChar()
346339
if subKeyLabel != "" {
347340
subKeyLabel = strings.Repeat(subKeyLabel, nextDims.CellCount())

internal/app/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,20 @@ func (a *App) SetConfigField(ctx context.Context, key, value string) error {
4040
return err
4141
}
4242

43-
// Validate the new config.
4443
valErr := newCfg.Validate()
4544
if valErr != nil {
4645
a.restoreHotkeysAfterFailedReload()
4746

4847
return derrors.Wrap(valErr, derrors.CodeInvalidConfig, "config-set validation")
4948
}
5049

51-
// Update the config service (notifies watchers with the new config).
5250
updateErr := a.configService.Update(newCfg, newWritten)
5351
if updateErr != nil {
5452
a.restoreHotkeysAfterFailedReload()
5553

5654
return updateErr
5755
}
5856

59-
// Build a LoadResult for the reconfiguration helpers.
6057
loadResult := &config.LoadResult{
6158
Config: newCfg,
6259
Written: newWritten,

internal/app/getters.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ func (a *App) IsOverlayHiddenForScreenShare() bool {
132132

133133
// SetOverlayHiddenForScreenShare sets whether the overlay should be hidden from screen sharing.
134134
func (a *App) SetOverlayHiddenForScreenShare(hide bool) {
135-
// Update app state (this will trigger callbacks)
136135
a.appState.SetHiddenForScreenShare(hide)
137136
}
138137

internal/app/ipcctrl/info.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ func (h *InfoHandler) ResolveConfigPath() string {
131131
return "using default config"
132132
}
133133

134-
// Check if the config file actually exists
135134
_, err := os.Stat(configPath)
136135
if os.IsNotExist(err) {
137136
return "using default config"

0 commit comments

Comments
 (0)