Title: Autogenerated documentation: using LSP make call hierarchy graphs · Issue #71 · function61/turbobob · GitHub
Open Graph Title: Autogenerated documentation: using LSP make call hierarchy graphs · Issue #71 · function61/turbobob
X Title: Autogenerated documentation: using LSP make call hierarchy graphs · Issue #71 · function61/turbobob
Description: Motivation Automatically extract important use case call graphs from code to explain high-level flow of the program, perhaps bake that into autogenerated documentation. Implementation Options: Build on top of LSP Pro: lots of languages h...
Open Graph Description: Motivation Automatically extract important use case call graphs from code to explain high-level flow of the program, perhaps bake that into autogenerated documentation. Implementation Options: Buil...
X Description: Motivation Automatically extract important use case call graphs from code to explain high-level flow of the program, perhaps bake that into autogenerated documentation. Implementation Options: Buil...
Opengraph URL: https://github.com/function61/turbobob/issues/71
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Autogenerated documentation: using LSP make call hierarchy graphs","articleBody":"## Motivation\n\nAutomatically extract important use case call graphs from code to explain high-level flow of the program, perhaps bake that into autogenerated documentation.\n\n## Implementation\n\nOptions:\n\n### Build on top of LSP\n\nPro: lots of languages have LSP so we can build on top of giants.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"log/slog\"\n\t\"os/exec\"\n\n\t\"github.com/sourcegraph/jsonrpc2\"\n\tlsp \"github.com/toitware/go-lsp\"\n\t\"github.com/toitware/go-lsp/lspext\"\n)\n\n// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/\n\ntype CallHierarchyItem struct {\n\tName string `json:\"name\"`\n\tKind int `json:\"kind\"`\n\tTags []int `json:\"tags,omitempty\"`\n\tDetail string `json:\"detail,omitempty\"`\n\tURI lsp.DocumentURI `json:\"uri\"`\n\tRange lsp.Range `json:\"range\"`\n\tSelectionRange lsp.Range `json:\"selectionRange\"`\n\tData interface{} `json:\"data,omitempty\"`\n}\n\ntype CallHierarchyPrepareParams struct {\n\tlsp.TextDocumentPositionParams\n\n\tWorkDoneToken interface{} `json:\"workDoneToken,omitempty\"`\n}\n\ntype CallHierarchyIncomingCall struct {\n\tFrom CallHierarchyItem `json:\"from\"`\n\tFromRanges []lsp.Range `json:\"fromRanges\"`\n}\n\ntype CallHierarchyOutgoingCall struct {\n\tTo CallHierarchyItem `json:\"to\"`\n\tFromRanges []lsp.Range `json:\"fromRanges\"`\n}\n\n// Minimal stream wrapper for jsonrpc2\ntype stdioStream struct {\n\tio.Reader\n\tio.Writer\n\tio.Closer\n}\n\nvar _ interface {\n\tio.Reader\n\tio.Writer\n\tio.Closer\n} = (*stdioStream)(nil)\n\nfunc hailait() {\n\tctx := context.Background()\n\n\t// Start gopls in stdio mode\n\tcmd := exec.Command(\"bob\", \"tools\", \"langserver\")\n\tstdin, _ := cmd.StdinPipe()\n\tstdout, _ := cmd.StdoutPipe()\n\tcmd.Stderr = cmd.Stdout\n\n\tif err := cmd.Start(); err != nil {\n\t\tlog.Fatal(\"failed to start gopls:\", err)\n\t}\n\n\tstream := jsonrpc2.NewBufferedStream(\u0026stdioStream{stdout, stdin, stdin}, jsonrpc2.VSCodeObjectCodec{})\n\tconn := jsonrpc2.NewConn(ctx, stream, jsonrpc2.HandlerWithError(func(ctx context.Context, c *jsonrpc2.Conn, r *jsonrpc2.Request) (result interface{}, err error) {\n\t\tswitch r.Method {\n\t\tcase \"window/showMessage\":\n\t\t\tlogMessageParams := struct {\n\t\t\t\tMessage string `json:\"message\"`\n\t\t\t\tType int `json:\"type\"`\n\t\t\t}{}\n\t\t\tif err := json.Unmarshal(*r.Params, \u0026logMessageParams); err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\t\t\tslog.Info(\"LSP server\", \"kind\", \"show\", \"msg\", logMessageParams.Message, \"type\", logMessageParams.Type)\n\t\t\treturn nil, nil\n\t\tcase \"window/logMessage\":\n\t\t\tlogMessageParams := struct {\n\t\t\t\tMessage string `json:\"message\"`\n\t\t\t\tType int `json:\"type\"`\n\t\t\t}{}\n\t\t\tif err := json.Unmarshal(*r.Params, \u0026logMessageParams); err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\t\t\tslog.Info(\"LSP server\", \"kind\", \"log\", \"msg\", logMessageParams.Message, \"type\", logMessageParams.Type)\n\t\t\treturn nil, nil\n\t\tdefault:\n\t\t\tslog.Warn(\"returning error\", \"request\", r.Method, \"params\", string(*r.Params))\n\t\t\treturn nil, errors.New(\"requests not implemented\")\n\t\t}\n\t}))\n\tdefer stream.Close()\n\n\t// ---- Initialize ----\n\tinitReq := lsp.InitializeParams{\n\t\tRootURI: \"file:///workspace\",\n\t}\n\n\tvar initResp lsp.InitializeResult\n\tif err := conn.Call(ctx, \"initialize\", initReq, \u0026initResp); err != nil {\n\t\tlog.Fatal(\"initialize error:\", err)\n\t}\n\n\t// Tell server we're ready\n\t_ = conn.Notify(ctx, \"initialized\", struct{}{})\n\n\t// --- Prepare call hierarchy ---\n\tparams := CallHierarchyPrepareParams{\n\t\tTextDocumentPositionParams: lsp.TextDocumentPositionParams{\n\t\t\tTextDocument: lsp.TextDocumentIdentifier{\n\t\t\t\tURI: initReq.RootURI + \"/pkg/mypkg/example.go\",\n\t\t\t},\n\t\t\tPosition: lsp.Position{ // -1 because positions are 0-based\n\t\t\t\tLine: 114 - 1,\n\t\t\t\tCharacter: 6 - 1,\n\t\t\t},\n\t\t},\n\t}\n\n\tvar items []CallHierarchyItem\n\tif err := conn.Call(ctx, \"textDocument/prepareCallHierarchy\", params, \u0026items); err != nil {\n\t\tlog.Fatal(\"prepareCallHierarchy:\", err)\n\t}\n\n\tif len(items) == 0 {\n\t\tlog.Println(\"No call hierarchy items found at location\")\n\t\treturn\n\t}\n\n\titem := items[0]\n\tfmt.Println(\"Item:\", item.Name)\n\n\t_ = lspext.CacheSetParams{}\n\t// --- Incoming calls ---\n\tvar incoming []CallHierarchyIncomingCall\n\tif err := conn.Call(ctx, \"callHierarchy/incomingCalls\", struct {\n\t\tItem CallHierarchyItem `json:\"item\"`\n\t}{item}, \u0026incoming); err != nil {\n\t\tlog.Fatal(\"incomingCalls: \", err)\n\t}\n\n\tfmt.Println(\"\\nIncoming calls:\")\n\tfor _, c := range incoming {\n\t\tfmt.Println(\" from:\", c.From.Name)\n\t}\n\n\t// --- Outgoing calls ---\n\t// var outgoing []CallHierarchyOutgoingCall\n\t// if err := conn.Call(ctx, \"callHierarchy/outgoingCalls\", item, \u0026outgoing); err != nil {\n\t// \tlog.Fatal(\"outgoingCalls:\", err)\n\t// }\n\n\t// fmt.Println(\"\\nOutgoing calls:\")\n\t// for _, c := range outgoing {\n\t// \tfmt.Println(\" to:\", c.To.Name)\n\t// }\n}\n```\n\n`go.mod`:\n\n```\n\tgithub.com/sourcegraph/jsonrpc2 v0.2.1 // indirect\n\tgithub.com/toitware/go-lsp v0.0.0-20240220075859-6b0ca01316f0 // indirect\n```\n\n### SCIP\n\nNot popular implementation, backed by one company with unclear investment on it: https://sourcegraph.com/blog/the-future-of-scip","author":{"url":"https://github.com/joonas-fi","@type":"Person","name":"joonas-fi"},"datePublished":"2025-11-18T10:13:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/71/turbobob/issues/71"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8c63475e-1d0c-5b0d-5b43-ed57034b24ae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9394:299B2C:B75C72:FE895E:6A4BDC8F |
| html-safe-nonce | 94e1ed1b97fb27c6abd1f8de06f26632bdc8123e59caf15d614b4667deb43d1b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Mzk0OjI5OUIyQzpCNzVDNzI6RkU4OTVFOjZBNEJEQzhGIiwidmlzaXRvcl9pZCI6IjQ1ODIzOTY0NDM0OTEwMzIyMDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7a6f240aa4e43e4ca5ea0cc7f7450826e0657b86d82411f7cecad561dfddf53e |
| hovercard-subject-tag | issue:3637281918 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/function61/turbobob/71/issue_layout |
| twitter:image | https://opengraph.githubassets.com/724b4399dff6941c50e6876ee87782d14ee31dbbeaf7c19f1a203abfd01ef6fc/function61/turbobob/issues/71 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/724b4399dff6941c50e6876ee87782d14ee31dbbeaf7c19f1a203abfd01ef6fc/function61/turbobob/issues/71 |
| og:image:alt | Motivation Automatically extract important use case call graphs from code to explain high-level flow of the program, perhaps bake that into autogenerated documentation. Implementation Options: Buil... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | joonas-fi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9df996be9551ac02247d09a2f7f64ece66c35ca28885d346e98fdfda9cdaa37b |
| turbo-cache-control | no-preview |
| go-import | github.com/function61/turbobob git https://github.com/function61/turbobob.git |
| octolytics-dimension-user_id | 22049800 |
| octolytics-dimension-user_login | function61 |
| octolytics-dimension-repository_id | 146426259 |
| octolytics-dimension-repository_nwo | function61/turbobob |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 146426259 |
| octolytics-dimension-repository_network_root_nwo | function61/turbobob |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7242837c61fe4c8b774b83b9ee05b1881ba589f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width