Skip to content

Commit 3749d24

Browse files
committed
refactor(doclink): rearrange some doclink comment processing logic to make it easier to understand.
1 parent e8de65b commit 3749d24

2 files changed

Lines changed: 20 additions & 23 deletions

File tree

internal/client_testsuite.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ type (
1919

2020
// NewTestClientEnvironment creates a new TestClientEnvironment with the given
2121
// interceptors chained before a no-op terminal interceptor.
22-
//
23-
// Exposed as: [go.temporal.io/sdk/testsuite.ClientTestSuite.NewTestClientEnvironment]
2422
func (s *ClientTestSuite) NewTestClientEnvironment(interceptors ...ClientInterceptor) *TestClientEnvironment {
2523
var chain ClientOutboundInterceptor = &noopClientOutboundInterceptor{}
2624
for _, interceptor := range interceptors {

internal/cmd/tools/doclink/doclink.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,26 @@ func processInternal(cfg config, file *os.File, pairs map[string]map[string]stri
390390
trimmedNextLine = nextLine
391391
}
392392

393-
// Only check top-level definitions.
394-
// Example: on a line like "func f() {", inFunc is still false here.
395-
// Without the explicit func check, the next line could be treated like a top-level definition.
396-
if !inFunc && !inInterface && !strings.HasPrefix(trimmedLine, "func ") && isValidDefinition(trimmedNextLine, &inGroup, &inStruct) {
393+
// Track whether nextLine is inside a function or interface block.
394+
// We update this first so the first line inside a block is not treated
395+
// as a top-level definition.
396+
if strings.HasPrefix(trimmedLine, "func ") {
397+
funcSpaces = indentSize
398+
inFunc = true
399+
} else if inFunc && trimmedLine == "}" && funcSpaces == indentSize {
400+
funcSpaces = -1
401+
inFunc = false
402+
}
403+
if strings.HasSuffix(trimmedLine, "interface {") {
404+
interfaceSpaces = indentSize
405+
inInterface = true
406+
} else if inInterface && trimmedLine == "}" && interfaceSpaces == indentSize {
407+
interfaceSpaces = -1
408+
inInterface = false
409+
}
410+
411+
// Check for new doc links to add on top-level definitions only.
412+
if !inFunc && !inInterface && isValidDefinition(trimmedNextLine, &inGroup, &inStruct) {
397413
// Find the "Exposed As" line in the doc comment
398414
var existingDoclink string
399415
comScanner := bufio.NewScanner(strings.NewReader(commentBlock))
@@ -453,23 +469,6 @@ func processInternal(cfg config, file *os.File, pairs map[string]map[string]stri
453469
}
454470
}
455471

456-
// update inFunc after we actually check for doclinks to allow us to check
457-
// a function's definition, without checking anything inside the function
458-
if strings.HasPrefix(trimmedLine, "func ") {
459-
funcSpaces = indentSize
460-
inFunc = true
461-
} else if inFunc && trimmedLine == "}" && funcSpaces == indentSize {
462-
funcSpaces = -1
463-
inFunc = false
464-
}
465-
if strings.HasSuffix(trimmedLine, "interface {") {
466-
interfaceSpaces = indentSize
467-
inInterface = true
468-
} else if inInterface && trimmedLine == "}" && interfaceSpaces == indentSize {
469-
interfaceSpaces = -1
470-
inInterface = false
471-
}
472-
473472
newFile += line + "\n"
474473
}
475474

0 commit comments

Comments
 (0)