sg.nvim
sg.nvim copied to clipboard
No valid auth strategy detected
Hi, first of all thank you very much for developing this plugin! Sourcegraph is a game changer. I love it.
I get the No valid auth strategy detected
error upon running :checkhealth sg
, despite running (apparently fine) the SourcegraphLogin
command.
This is the full output of the :checkhealth sg
command:
sg: require("sg.health").check()
sg.nvim report ~
- Machine: x86_64, sysname: Linux
- OK Valid nvim version: table: 0x7f50b3ad9398
- OK Found `cargo` (cargo 1.74.1 (ecb9851af 2023-10-18)) is executable
- Use `:SourcegraphDownloadBinaries` to avoid building locally.
- OK Found `sg-nvim-agent`: "/home/marco/.local/share/nvim/lazy/sg.nvim/dist/sg-nvim-agent"
- OK Found `node` (config.node_executable) is executable.
Version: '18.18.2'
- OK Found `cody-agent`: /home/marco/.local/share/nvim/lazy/sg.nvim/dist/cody-agent.js
- ERROR No valid auth strategy detected. See ':help |sg'| for more info.
- ERROR Cannot check Cody Status, not logged in
- ERROR sg.nvim has issues that need to be resolved
When I run :SourcegraphLogin
, I confirm the endpoint url as https://sourcegraph.com/
, upon hitting <CR>
, a browser TAB opens with the following url:
https://sourcegraph.com/users/h0pes/settings/tokens/new/callback?requestFrom=NEOVIM-52068
.
I click Confirm
on the form button. A new tab is opened with this url:
http://localhost:52068/api/sourcegraph/token?token=sgp_[redacted]_[redacted]
and the message:
Credentials have been saved to Neovim. Restart Neovim now.
.
If I restart Neovim, I experience the same behavior as not logged in per checkhealth
.
I'm authenticated on my browser session to https://sourcegraph.com
, if that matters.
If I run :SourcegraphLogin!
and I paste the access token created in nvim command bar, after having confirmed the endpoint, no errors or messages appear.
I can see the personal access token under just created under the Settings page in Sourcegraph.
This is my config:
{
"sourcegraph/sg.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function(_, opts)
require("sg").setup(opts)
status.cody = true
end,
opts = require("custom.configs.sg").opts,
keys = require("custom.configs.sg").keys,
},
local M = {}
M.opts = {
-- ... other configuration options ...
-- Disable LSP suggestions
on_attach = function(client)
local buffer_name = vim.fn.expand "%:t"
if buffer_name ~= "COMMIT_EDITMSG" then
if client.supports_method "textDocument/formatting" then
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format { bufnr = bufnr }
end,
})
end
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec(
[[
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]],
false
)
end
end
end,
}
M.keys = {
{
"<leader>ai",
":CodyChat<CR>",
mode = "n",
desc = "AI Assistant",
},
{
"<leader>ad",
function()
local line = vim.fn.getline "."
local start = vim.fn.col "."
local finish = vim.fn.col "$"
local text = line:sub(start, finish)
vim.fn.setreg('"', text)
vim.cmd [[CodyTask 'Write document for current context']]
end,
mode = "n",
desc = "Generate Document with AI",
},
-- some other custom keymaps...
return M
I attach some screens.
NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1702233742
I've been able to get a green check on :checkhealth sg
after using the src
binary from Sourcegraph and authenticating setting the SRC_ENDPOINT
and SRC_ACCESS_TOKEN
env variables.
I still would like to know why the SourcegraphLogin
command was not working though...
Do you happen to be on Arch? Or rather, what's your distro?
The way that I'm storing the access tokens in Rust uses some system libraries that may not be available by default (so I may have to pursue a different strategy, or find some other way to store if the configuration doesn't work)
Hi, thanks for the reply. Yes, I'm on Arch :blush:
One thing I noticed is that I don't get an sg_token
in my plenary cache dir (plenary installed, loaded and writable by neovim). Anyway, even manually setting the cache token file, makes no difference.
Let me know if I can help you to investigate it more. Thanks a lot for your help.
Ah, I figure out something that was definitely a problem on my side. I was not passing the error from attempting to save the credentials to the user -- can you try doing it again? Hopefully this time it surfaces an error to you (or works haha)
Hi, I updated the plugin to the latest version which includes this commit, but nothing seems to have changed.
:SourcegraphLogin
successfully completes its tasks, I get the
Credentials have been saved to Neovim. Restart Neovim now.
message in my browser tab and inspecting the Access tokens section of my sourcegraph.com profile, I can find the newly created token.
I then restart neovim, running :checkhealth sg
still shows the same error.
Trying to manually input the endpoint and token with :SourcegraphLogin!
seems to work fine, I mean no errors nor notifications are shown, but still showing as not authenticated (in fact CodyChat
and other commands tell me I'm not authenticated).
I can confirm same error on MacOS, I cannot authenticate using SourcegraphLogin
nor token saved in env variable.
I also have this issue on WSL, I cannot authenticate using SourcegraphLogin nor token saved in env variable.
Same error on WSL, oof.
I have the same issue on Termux, to solve It I've set the SRC_ENDPOINT
and SRC_ACCESS_TOKEN
env variables on a file that I source on my shell profile.
Hi @tjdevries did you have the chance to take a look into this? I still experience the same issue. Thanks