feat(lsp): expose Sourcegraph Precise code navigation through LSP by jupblb · Pull Request #1243 · sourcegraph/src-cli
added 8 commits
December 23, 2025 13:24Implements an LSP server that proxies requests to Sourcegraph's code intelligence backend via GraphQL. The server communicates over stdio and is designed for use with editors like Neovim. Supported LSP methods: - textDocument/hover The server infers repository name and commit from git at startup, then converts file:// URIs to repo-relative paths for GraphQL queries. New files: - cmd/src/lsp.go: Command registration - internal/lsp/server.go: LSP server using glsp - internal/lsp/query.go: GraphQL hover query Amp-Thread-ID: https://ampcode.com/threads/T-019b4b1e-e6ef-744e-b012-194d31ef16b4
- Add definitions GraphQL query to fetch go-to-definition data from Sourcegraph - Add handleTextDocumentDefinition handler in LSP server - Register DefinitionProvider capability - Use git merge-base to find a commit that exists on remote Sourcegraph
Tests cover: - queryHover: successful responses, missing data, null responses - queryDefinitions: single/multiple definitions, no definitions - queryReferences: multiple references, empty results - uriToRepoPath: path conversion from file:// URIs - getGitRoot and runGitCommand utilities
On Windows, file URIs must use the format file:///C:/path (with three slashes and forward slashes). The URL parser produces paths like /C:/path which need the leading slash stripped to be valid Windows paths. - Use url.URL to construct proper file:// URIs in tests - Handle leading slash before drive letter when parsing Windows file URIs - Normalize path separators for cross-platform compatibility
The url.URL with path 'D:/path' produces 'file://D:/path' which interprets D: as host:port. We need '/D:/path' to produce 'file:///D:/path'.
jupblb
marked this pull request as ready for review
The previous version (v0.3.11) depended on termenv v0.15.2 methods (EnableWindowsANSIConsole, RestoreWindowsConsole) that were removed in termenv v0.16.0 used by other dependencies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters