-
Notifications
You must be signed in to change notification settings - Fork 70
feat(lsp): expose Sourcegraph Precise code navigation through LSP #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jupblb
wants to merge
14
commits into
main
Choose a base branch
from
michal/lsp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c455489
cmd/src: add lsp command with textDocument/hover support
jupblb 93a65c2
lsp: add textDocument/definition support
jupblb 5743821
lsp: add textDocument/references support
jupblb 6b3046e
internal/lsp: add tests for query and server functions
jupblb e1c90b0
internal/lsp: fix formatting
jupblb bff155a
lsp: update help message with Neovim 0.11+ config example
jupblb 05065c3
lsp: return version in serverInfo
jupblb 96aee9a
lsp: add textDocument/documentHighlight support
jupblb e818cb4
Fix CI issues
jupblb 998631f
fix(lsp): handle Windows file URIs correctly
jupblb aba1226
fix(lsp): ensure Windows paths have leading slash in file URIs
jupblb d64b6e6
Remove unnecessary changes
jupblb 5cf9a1e
Stylistic changes
jupblb 8c293cb
fix: upgrade kutil to v0.3.27 for Windows termenv compatibility
jupblb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "io" | ||
|
|
||
| "github.com/sourcegraph/src-cli/internal/lsp" | ||
| ) | ||
|
|
||
| func init() { | ||
| usage := ` | ||
| 'src lsp' runs a Language Server Protocol server that proxies LSP | ||
| requests to Sourcegraph's code intelligence backend. | ||
|
|
||
| The server communicates over stdio (stdin/stdout) and is designed | ||
| to be used with editors like Neovim. | ||
|
|
||
| Prerequisites: | ||
| - The working directory must be inside a Git repository | ||
| - The repository must be indexed on your Sourcegraph instance | ||
| - SRC_ENDPOINT and SRC_ACCESS_TOKEN environment variables must be set | ||
|
|
||
| Supported LSP methods: | ||
| - textDocument/definition | ||
| - textDocument/references | ||
| - textDocument/hover | ||
| - textDocument/documentHighlight | ||
|
|
||
| Example Neovim configuration (0.11+): | ||
|
|
||
| vim.lsp.config['src-lsp'] = { | ||
| cmd = { 'src', 'lsp' }, | ||
| root_markers = { '.git' }, | ||
| filetypes = { 'go', 'typescript', 'python' }, | ||
| } | ||
| vim.lsp.enable('src-lsp') | ||
| ` | ||
|
|
||
| flagSet := flag.NewFlagSet("lsp", flag.ExitOnError) | ||
| usageFunc := func() { | ||
| fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src %s':\n", flagSet.Name()) | ||
| flagSet.PrintDefaults() | ||
| fmt.Println(usage) | ||
| } | ||
|
|
||
| handler := func(args []string) error { | ||
| if err := flagSet.Parse(args); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| client := cfg.apiClient(nil, io.Discard) | ||
|
|
||
| srv, err := lsp.NewServer(client) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return srv.Run() | ||
| } | ||
|
|
||
| commands = append(commands, &command{ | ||
| flagSet: flagSet, | ||
| handler: handler, | ||
| usageFunc: usageFunc, | ||
| }) | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to pass flagSet in here?