aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorOtto Ahoniemi <otto@ottoahoniemi.fi>2022-11-28 03:04:33 +0200
committerGitHub <noreply@github.com>2022-11-28 09:04:33 +0800
commit9f722fb8601b1f5e6d4b034d30eb328e1bb9c526 (patch)
treea808e8b7ec8574edb8438b96985e6b7fcea4081f /lua
parentperf: use alias api variable (#2260) (diff)
downloadnvim-lspconfig-9f722fb8601b1f5e6d4b034d30eb328e1bb9c526.tar
nvim-lspconfig-9f722fb8601b1f5e6d4b034d30eb328e1bb9c526.tar.gz
nvim-lspconfig-9f722fb8601b1f5e6d4b034d30eb328e1bb9c526.tar.bz2
nvim-lspconfig-9f722fb8601b1f5e6d4b034d30eb328e1bb9c526.tar.lz
nvim-lspconfig-9f722fb8601b1f5e6d4b034d30eb328e1bb9c526.tar.xz
nvim-lspconfig-9f722fb8601b1f5e6d4b034d30eb328e1bb9c526.tar.zst
nvim-lspconfig-9f722fb8601b1f5e6d4b034d30eb328e1bb9c526.zip
Try to get sourcery auth token from config file (#2240)
* feat: try to get sourcery token from config file * fix: support windows * fix: only check for token if it's not in options
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/server_configurations/sourcery.lua28
1 files changed, 26 insertions, 2 deletions
diff --git a/lua/lspconfig/server_configurations/sourcery.lua b/lua/lspconfig/server_configurations/sourcery.lua
index 608a816f..bde18a15 100644
--- a/lua/lspconfig/server_configurations/sourcery.lua
+++ b/lua/lspconfig/server_configurations/sourcery.lua
@@ -9,6 +9,25 @@ local root_files = {
'pyrightconfig.json',
}
+local token_in_auth_file = function()
+ local is_windows = vim.fn.has 'win32' == 1
+ local path_sep = is_windows and '\\' or '/'
+
+ local config_home = is_windows and vim.fn.getenv 'APPDATA' or vim.fn.expand '~/.config'
+ local auth_file_path = config_home .. path_sep .. 'sourcery' .. path_sep .. 'auth.yaml'
+
+ if vim.fn.filereadable(auth_file_path) == 1 then
+ local content = vim.fn.readfile(auth_file_path)
+ for _, line in ipairs(content) do
+ if line:match 'sourcery_token: (.+)' then
+ return true
+ end
+ end
+ end
+
+ return false
+end
+
return {
default_config = {
cmd = { 'sourcery', 'lsp' },
@@ -24,9 +43,12 @@ return {
single_file_support = true,
},
on_new_config = function(new_config, _)
- if not new_config.init_options.token then
+ if not new_config.init_options.token and not token_in_auth_file() then
local notify = vim.notify_once or vim.notify
- notify('[lspconfig] The authentication token must be provided in config.init_options', vim.log.levels.ERROR)
+ notify(
+ '[lspconfig] The authentication token must be provided in config.init_options or configured via "sourcery login"',
+ vim.log.levels.ERROR
+ )
end
end,
docs = {
@@ -54,6 +76,8 @@ require'lspconfig'.sourcery.setup {
},
}
```
+
+Alternatively, you can login to sourcery by running `sourcery login` with sourcery-cli.
]],
},
}