MCPcopy Create free account
hub / github.com/coder/coder / resolveStringExpr

Function resolveStringExpr

scripts/metricsdocgen/scanner/scanner.go:275–293  ·  view source on GitHub ↗

resolveStringExpr attempts to resolve an expression to a string value. Examples: - "my_metric": "my_metric" (string literal) - metricName: resolved value of metricName constant (identifier) - agentmetrics.LabelUsername: resolved from package constants (selector)

(expr ast.Expr, decls declarations)

Source from the content-addressed store, hash-verified

273// - metricName: resolved value of metricName constant (identifier)
274// - agentmetrics.LabelUsername: resolved from package constants (selector)
275func resolveStringExpr(expr ast.Expr, decls declarations) string {
276 switch e := expr.(type) {
277 case *ast.BasicLit:
278 return strings.Trim(e.Value, `"`)
279 case *ast.Ident:
280 return decls.strings[e.Name]
281 case *ast.BinaryExpr:
282 return resolveBinaryExpr(e, decls)
283 case *ast.SelectorExpr:
284 // Handle pkg.Const syntax.
285 if ident, ok := e.X.(*ast.Ident); ok {
286 if pkgConsts, ok := packageDeclarations[ident.Name]; ok {
287 return pkgConsts[e.Sel.Name]
288 }
289 }
290 }
291
292 return ""
293}
294
295// resolveBinaryExpr resolves a binary expression (string concatenation) to a string.
296// It recursively resolves the left and right operands.

Callers 4

resolveBinaryExprFunction · 0.85
extractStringSliceFunction · 0.85
extractNewDescMetricFunction · 0.85
extractOptsFunction · 0.85

Calls 1

resolveBinaryExprFunction · 0.85

Tested by

no test coverage detected