mason lsp pyright seems to be download but dosen't work on vim - neovim

I have a problem on my nvim LSP.
according to mason plugin the pyright is downloaded and I on other IDE the lsp works great.
when i open python file with neovim it didn't recognized import and basic functions.
someone can handle this situation?
maybe it's because Lspinfo tell me that it didn't get the python root directory?import don't auto complete pythonpyright is downloaded via masonLSPInfo description
on other languages it works so don't really understand the problem

Same as me, at the moment I solved like this (it happens in some languages for me too):
local status_ok, mason = pcall(require, "mason")
if not status_ok then
return
end
local status_masonlsp_ok, mason_lspconfig = pcall(require, "mason-lspconfig")
if not status_masonlsp_ok then
return
end
local servers = {
"sumneko_lua",
"rust_analyzer",
"tailwindcss",
"bashls",
"pyright",
-- "csharp_ls",
"html",
"omnisharp",
"gopls",
}
mason.setup(settings)
mason_lspconfig.setup({
ensure_installed = servers,
automatic_installation = true,
})
So when I open nvim they are installed automatically.

Related

Why pyright config with mason in nvim shows that package is not accessed

The pyright did not run well:
Although it completes properly, it cannot find the package location:
This is my config for pyright
--config python language server
lspconfig["pyright"].setup({
capabilities = capabilities,
on_attach = on_attach,
settings={
python = {
pythonPath="/usr/bin/python3"
},
pyright = {}
}
})
I hope someone can help me to fix the not accessed issue, I did not find a good solution on google.

How to apply multiple auto fixes with nvim LSP

In nvim, using LSP, i want to be able to apply a 'fix all of the same type' similar to what can be done in VSCode (see picture). How would one go about adding this to LSP code actions?
Edit: I know this can be done using COC. But i want it for LSP.
It depends on the language server you are using, in my current NeoVim configuration I'm running both ESLint and tsserver and with a default configuration of ESLint in my root of my project, I get these types of code action.
Assuming you are using lspconfig plugin you need to make sure you have the server configured :
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require('lspconfig')['tsserver'].setup {
on_attach = function() end,
capabilities = capabilities,
}
require('lspconfig')['eslint'].setup {
on_attach = function() end,
capabilities = capabilities,
}
You can then run in neovim : :lua vim.lsp.buf.code_action() in command mode (n)
You need both LSP installed manually
Ref :
https://github.com/neovim/nvim-lspconfig#quickstart
https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#eslint
https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#tsserver
N.B. You should probably add your keymap related to LSP in the on_attach callback

Spawning language server with cmd`diagnostic-languageserver`failed. The language server is either not installed, missing from PATH, or not executable

enter image description here
" Spawning language server with cmd: diagnostic-languageserver failed. The language server is either not installed, missing from PATH, or not executable "
nvim problem
i copied devaslife's dotfiles and installed plugin
yesterday it work, but today i entered LSP info after that when i Enter shows that the error
I've resolved this problem by executing the below command
npm install -g diagnostic-languageserver
Use this:
yarn global add diagnostic-languageserver
Probably, it's because you have not set up the right programming language that you are using in the lspconfig.rc.vim, precisely in the nvim_lsp.tsserver.setup part.
I had the same problem because I was in javascript file (.js) and the lsp config that I was using from someone else only supports typescript files. So, I just had to add the javascript, javascriptreact and javascript.jsx. For example :
nvim_lsp.tsserver.setup {
on_attach = on_attach,
filetypes = { "typescript", "typescriptreact", "typescript.tsx", "javascript", "javascriptreact", "javascript.jsx" },
capabilities = capabilities
}
That is not working for me. In the lspconfig.re.vim, i had to delete the "javascipt", "javasriptreact", "javascript.jsx" types from the nvim_lsp.diagnosticls.setup/filetypes, and then put them in the nvim_lsp.tsserver.setup>filetypes
For windows you can use this:
nvim_lsp.tsserver.setup {
on_attach = on_attach,
filetypes = { "typescript", "typescriptreact", "typescript.tsx" },
cmd = { "typescript-language-server.cmd", "--stdio" }
}
This will make sure it will run the .cmd file that is along side the .ps1.

How do I setup elixir-ls using nvim-lspconfig with autocompletion in neovim?

I would like to set up the Elixir language server in Neovim using the built-in language server client and nvim-lspconfig.
Documentation for this seems to be spread out in multiple places:
nvim-lspconfig README
nvim-lspconfig wiki about autocomplete
nvim-lspconfig elixir-ls server configuration documentation
elixir-ls installation instructions
I am a little overwhelmed and have made multiple attempts to do this, but always give up without success. I also found a useful looking guide: How to Set Up Neovim for Elixir Development, but it makes quite a few assumptions, seems to eroneously do some configuration twice, and also switches config format halfway through, so wasn't a usable summary for me (after following the instructions, documentation popups were not working, and I was unable to scroll inside the autocomplete popups - I also had a lot of copy/pasted config I didn't understand).
So far I understand the required steps are:
Install neovim
Install elixir-ls manually (it doesn't seem to be possible currently to install via asdf due to a lack of ability to ask elixir-ls for its version)
Install required neovim plugins: nvim-lspconfig + whatever is required for autocomplete
Set up necessary config for nvim-lspconfig and autocomplete.
I have managed to do up to part-way through step 3, but have not sucesfully worked out the required dependencies and configuration for autocomplete.
What do I need to do to have a working elixir-ls setup in neovim, with autocomplete, using nvim-lspconfig and neovim's built-in language server client?
I managed to get everything working with the combination of some plugins for completion in neovim. They are:
hrsh7th/nvim-cmp - the autocompletion plugin
hrsh7th/cmp-nvim-lsp - the integration of nvim-cmp with neovim's LSP
L3MON4D3/LuaSnip - a snippets plugin
saadparwaiz1/cmp_luasnip - the snippets source for nvim-cmp
This is the same list of plugins from the nvim-cmp recommendation of neovim's Wiki.
I'm using packer to manage the plugins. I'm also installing the plugins before configuring them.
Here is the installation lines:
use 'neovim/nvim-lspconfig'
use 'nvim-treesitter/completion-treesitter' -- Only if you are using TS
use 'hrsh7th/nvim-cmp' -- Autocompletion plugin
use 'hrsh7th/cmp-nvim-lsp' -- LSP source for nvim-cmp
use 'saadparwaiz1/cmp_luasnip' -- Snippets source for nvim-cmp
use 'L3MON4D3/LuaSnip' -- Snippets plugin
And then the configuration part:
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- Configure ElixirLS as the LSP server for Elixir.
require'lspconfig'.elixirls.setup{
cmd = { "/home/my-user/path-to/elixir-ls/release/language_server.sh" },
-- on_attach = custom_attach, -- this may be required for extended functionalities of the LSP
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
},
elixirLS = {
dialyzerEnabled = false,
fetchDeps = false,
};
}
local luasnip = require 'luasnip'
-- nvim-cmp
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
You can find all my neovim config in my dotfiles repo: https://github.com/philss/dotfiles
For reference, here is the nvim version I'm using (installed from source):
NVIM v0.7.0-dev+864-g2818de8b7
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Features: +acl +iconv +tui
In addition to the accepted answer, I suggest installing language server via Homebrew or similar instead of cloning repo and compiling. Philip's answer is correct. Just make your life easier by using a package manager for language server installation.
If you use LunarVim, which is like a NeoVim IDE, the configuration is minimal.
Nearly all dependencies for completion are already installed.
I also found it is better for Mac users to use Homebrew to install Elixir Language Server like so:
brew install elixir-ls
You don't need to keep track of the updates manually. It is usually upgraded along with other dev dependencies via brew update && brew upgrade.
Try this for LunarVim:
-- generic LSP settings
--
-- ---#usage disable automatic installation of servers
-- lvim.lsp.automatic_servers_installation = false
local lspconfig = require("lspconfig")
-- Neovim doesn't support snippets out of the box, so we need to mutate the
-- capabilities we send to the language server to let them know we want snippets.
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
-- ---configure a server manually. !!Requires `:LvimCacheReset` to take effect!!
-- ---see the full default list `:lua print(vim.inspect(lvim.lsp.automatic_configuration.skipped_servers))`
-- vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "pyright" })
-- local opts = {} -- check the lspconfig documentation for a list of all possible options
-- require("lvim.lsp.manager").setup("pyright", opts)
-- Elixir LS
lspconfig.elixirls.setup {
cmd = { "/usr/local/Cellar/elixir-ls/0.10.0/libexec/language_server.sh" },
-- on_attach = custom_attach, -- this may be required for extended functionalities of the LSP
capabilities = capabilities,
flags = {
debounce_text_changes = 150,
},
elixirLS = {
dialyzerEnabled = false,
fetchDeps = false,
};
}

VSCode extension testing: Use `vscode.executeDefinitionProvider` in test

Background
I'm trying to auto-test my VSCode extension. The extension works with python files and uses vscode.executeDefinitionProvider and vscode.executeDocumentSymbolProvider on them.
Problem
vscode.executeDefinitionProvider always returns [], vscode.executeDocumentSymbolProvider always returns undefined.
Notes
When running the same code in a debug session of the extension (no test session), the commands work flawless.
I ensured the extensions to be available during the test and even manually activated them with
let ext = vscode.extensions.getExtension("ms-python.python");
assert.notStrictEqual (ext, undefined);
await ext?.activate ();
ext = vscode.extensions.getExtension("ms-python.vscode-pylance");
assert.notStrictEqual (ext, undefined);
await ext?.activate ();
Question
How do I get the commands to succeed during automated test.
Edit: Workaround
Apparently VSCode takes its time to really activate the extensions. I could get it working placing a await sleep (10000); in index.ts::run () before return new Promise((c, e) => {.
While this is working, it's a really unstable workaround, Is there any way to make the code wait until the whole environment is fully loaded?
In the end nothing really stably worked for me, so I resorted to the following (perfectly fine working) solution.
My auto tests are run from the productive environment, like any other extension.
In package.json I created a new command _test.
the command would run ./test/suite/index.ts : run().
Extension<T>::activate(): Thenable<T>
Returns: Thenable<T> - A promise that will resolve when this extension has been activated.
await ext?.activate();