Skip to content

feat(lsp): add gopls navigation + Go semantic trace#1

Merged
BrainBuzzer merged 2 commits intomainfrom
codex/go-lsp-gopls-trace
Feb 26, 2026
Merged

feat(lsp): add gopls navigation + Go semantic trace#1
BrainBuzzer merged 2 commits intomainfrom
codex/go-lsp-gopls-trace

Conversation

@BrainBuzzer
Copy link
Owner

Summary

  • Adds sx lsp … read-only Go navigation via gopls (def/refs/impl/calls/symbols/ws-symbol/sig/highlight/check).
  • Makes sx trace semantically accurate for Go call edges using gopls call_hierarchy (auto when available), with --lsp/--no-lsp overrides and heuristic fallback.
  • Adds disk caching for Go call hierarchy keyed by (symbol_id, file content_hash) under .sx/cache/gopls/call_hierarchy/.
  • Supports single + multi-module repos (prefer go.work, else nearest go.mod).
  • Improves trace path diversity so multiple flows are shown (not just the top path).
  • Invalidates trace cache on re-index using meta.index_generation.

Testing

  • cargo test

- Add sx lsp read-only Go navigation commands
- Use gopls call_hierarchy for Go call edges in sx trace with caching
- Support multi-module (go.work / nearest go.mod) workspaces
- Improve trace path diversity + cache invalidation on reindex
@BrainBuzzer
Copy link
Owner Author

@codex please review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 14ade84f52

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +61 to +63
let cache_path = self
.cache_dir
.join(format!("{}-{}.json", sym.symbol_id, file_hash));

Choose a reason for hiding this comment

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

P2 Badge Include broader invalidation inputs in gopls call cache key

The call-hierarchy cache key is built from only symbol_id and the caller file hash, so after reindexing changes in other files (e.g., moved/renamed callees) this code can reuse stale cached callee locations and emit outdated or mis-resolved call edges until the caller file itself changes. That directly affects trace accuracy because call_edges_for_symbol trusts cached callee_path/callee_def_line when rebuilding edges.

Useful? React with 👍 / 👎.

Comment on lines 482 to 486
if let Some(stripped) = uri.strip_prefix("file://") {
// file:///a/b/c.go
let s = stripped.trim_start_matches('/');
let path = format!("/{}", s);
return Ok(PathBuf::from(path));

Choose a reason for hiding this comment

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

P2 Badge Decode file URIs before path conversion

This conversion treats a file:// URI as a plain string path and does not percent-decode it, so URIs like file:///repo/My%20Dir/main.go become non-existent filesystem paths. In repositories with spaces or non-ASCII characters, sx lsp def can therefore return unusable locations (and downstream normalization/path classification can be wrong).

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f204c0b6f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +219 to +220
let should_attempt_gopls = if call_edges.is_empty() {
false

Choose a reason for hiding this comment

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

P1 Badge Bypass heuristic gate when --lsp forces gopls call edges

The --lsp flag is documented to force Go call-edge resolution via gopls, but this gate unconditionally sets should_attempt_gopls to false when no heuristic call edges are present, so forced mode can still skip call_edges_for_symbol entirely and return incomplete traces. This is especially visible for functions where the heuristic extractor misses calls (or only yields unresolved externals): sx trace --lsp will silently omit call edges instead of forcing LSP-derived ones.

Useful? React with 👍 / 👎.

@BrainBuzzer BrainBuzzer merged commit 1d59b8d into main Feb 26, 2026
4 checks passed
@BrainBuzzer BrainBuzzer deleted the codex/go-lsp-gopls-trace branch February 26, 2026 02:16
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.

1 participant