Skip to content
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

feat: add support for sourcery #1495

Merged
merged 3 commits into from
Mar 8, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions lua/lspconfig/server_configurations/sourcery.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local util = require 'lspconfig/util'

local root_files = {
'pyproject.toml',
'setup.py',
'setup.cfg',
'requirements.txt',
'Pipfile',
'pyrightconfig.json',
}

return {
default_config = {
cmd = { 'sourcery', 'lsp' },
filetypes = { 'python' },
init_options = {
editor_version = 'vim',
extension_version = 'vim.lsp',
token = '<YOUR_TOKEN>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should a remove the token section, and instead require that people use the auth.yaml file in the ~/.config/sourcery/auth.yaml file. Sourcery even gives the user the command: sourcery login to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it not work with a local auth.yaml? otherwise, where's the path for Windows? I can't find that info on their site, could you please share the link?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I guess it can. But from what I see, I can't understand where the token is used, besides the variable assignment

token = "<YOUR_TOKEN>"

Unless I am wrong, and it is used inside the mechanics of lspconfig?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it not work with a local auth.yaml? otherwise, where's the path for Windows? I can't find that info on their site, could you please share the link?

What is considered a "local" auth.yaml file?
Also, output from sourcery login --help:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best docs I found.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was specifically asking about the docs where they mention ~/.config/sourcery/auth.yaml since I couldn't find it anywhere, because for Windows it would have to be something like ~/AppData/Local/sourcery/..

I guess the local file would be .sourcery.yaml? but I can't find if it has anything to do with storing the auth token.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. I'll have to look around. But why use the path? Once it is setup(i.e i am logged in), I dont have to use the Path again. Sourcery fetches the token and saves it for future usage. I.e the LSP works everything after the initial setup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. Turns out there are no docs on this...Which is a bad thing. Opened an issue regarding this.

kylo252 marked this conversation as resolved.
Show resolved Hide resolved
},
root_dir = function(fname)
return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname)
end,
single_file_support = true,
},
docs = {
description = [[
https://github.com/sourcery-ai/sourcery

Refactor Python instantly using the power of AI.

It requires the initializationOptions param to be populated as shown below and will respond with the list of ServerCapabilities that it supports.

init_options = {
--- The Sourcery token for authenticating the user.
--- This is retrieved from the Sourcery website and must be
--- provided by each user. The extension must provide a
--- configuration option for the user to provide this value.
token = <YOUR_TOKEN>

--- The extension's name and version as defined by the extension.
extension_version = 'vim.lsp'

--- The editor's name and version as defined by the editor.
editor_version = 'vim'
}
]],
},
}