tjdevries / nlua.nvim

Lua Development for Neovim
MIT License
262 stars 21 forks source link

Make cmd configurable #10

Closed shadmansaleh closed 3 years ago

shadmansaleh commented 3 years ago

I'm using neovim-0.5 beta from ubuntu ppa. the function that determines cmd value by default uses jit.os . But jit.os is not available in global namespace in my neovim . So the plugin fails to load . Making cmd a configurable option solves any issue regrding that specific function .

The change is minimal it now checks if cmd was passed with the setup call if it was it uses the cmd value that was passed otherwise uses its default function to determine cmd value.

This small change gives more control to user to determine what command is executed to start the lsp server.

F4IL3D commented 3 years ago

That option would be great. I have the same problem. If you, like me, install the lua-language-server via pacman in Arch linux, the cmd must look like this: {"/usr/sbin/lua-language-server", "-E", "/usr/share/lua-language-server/main.lua"}

shadmansaleh commented 3 years ago

That option would be great. I have the same problem. If you, like me, install the lua-language-server via pacman in Arch linux, the cmd must look like this: {"/usr/sbin/lua-language-server", "-E", "/usr/share/lua-language-server/main.lua"}

I was wondering about that situation too . In my case I installed the lsp-server with neovim . But the path genaration wasn't working . If you install lsp-server from a different source this plugin cann't work without editing source code . I found it weird that it didn't allow user to specify cmd . It's a small change hopefuly tjdevries approves :) . Do you know what's the actual purpose of this plugin ? I cann't seem to figure that part out .

F4IL3D commented 3 years ago

I am not a programmer and have zero experience with lua or the neovim internal lsp. The best prerequisites for trying to convert the nvim config to lua or to experiment with such plugins. ;) That's why it probably took me 2 days to find out that the path is hard coded. XD

I was also surprised that he did not provide this option, but the plugin is still at an early stage. So I think/hope TJ will approve your change.

As I said, I'm not a programmer but to answer your question i would say that nlua.nvim is more of an addon for the lua language server than a plugin for neovim. According to my understanding it extends the lua language server with the Neovim api and enables auto-completion for Neovim specific lua functions. I think TJ would like to simplify the plugin development in lua.

I mainly use it to port my VimL code to Lua.

shadmansaleh commented 3 years ago

I might be wrong in this case But the nevim specific api completion happens because of this line https://github.com/tjdevries/nlua.nvim/blob/fffbebee4c778deae52d78a5db154e45fcca5683/lua/nlua/lsp/nvim.lua#L76

with this line and the following line in lsp configuration I think any lsp-client will complete nvim_api. I've tried it with coc.nvim and nvim_lsp . when configured with those parameters api completion works without this plugin . You can try that and see if it works on your device .

coc.nvim config I'm using

"lua-language-server": {
                 "cwd": "/home/shadman/.cache/nvim/nvim_lsp/sumneko_lua/lua-language-server/",
                 "command": "/home/shadman/.cache/nvim/nvim_lsp/suneko_lua/lualanguageserver/bin/Linux/lualanguage-server",
                 "args": ["-E","/home/shadman/.cache/nvim/nvim_lsp/smneko_lua/lua-language-server/main.lua"],
                 "filetypes": ["lua"],
                 "settings":{
                     "Lua":{
                         "runtime":{
                            "version": "LuaJIT"
                         },
                         "diagnostics":{
                             "enable": true,
                             "globals":[ "vim","vimp","spoon","hs" ]
                         },
              "workspace" : {
                "maxPreload" : 1000,
                "preloadFileSize" : 1000
              }
                     }
                 }
}

nvim-lsp (neovim 5.0)

settings = {
        Lua = {
             runtime={
                   version="LuaJIT",
              },                                                                    diagnostics={
enable=true,
globals={"vim", "spoon", "hs"}
},
workspace = {
           --library=vim.list_extend(get_lua_runtime(),{}),
            maxPreload = 1000,
            preloadFileSize = 1000,
          },
        }
      },

I'm not a devloper either . I have little knowledge on programming . I also first thought it's purpose was neovim specific completion but thats just 2 lines of code . So that oviously cann't be the entire plugin.

F4IL3D commented 3 years ago

Very interesting. You are absolutely right. I tested your suggested setting for nvim_lsp without nlua and get auto completion like you.

But nlua does something. I get more suggestions with nlua than without. See the following screenshots

(without nlua) image

(with nlua) image

For example _nvim_get_hl_id_byname or _nvim_get_runtimefile I don't get displayed without nlua.

But I am honestly overwhelmed what nlua is doing exactly.

I think at this point only TJ DeVries can bring some light into the dark. :-)

shadmansaleh commented 3 years ago

Yes. Some of those are missing. I'll see if I can find out why .

shadmansaleh commented 3 years ago

Can you share the configuration you are using with nlua.nvim . It seems I'm not getting all completions even with nlua. Mine must be wrongly configured.

F4IL3D commented 3 years ago

Sorry for the late reply. As requested, here is my config.

.config/nvim/init.vim

lua require("init")

.config/nvim/lua/init.lua

-- basic settings
require("config/settings")
-- mappings
require("config/mappings")
-- plugins
require("plugins")

require("lsp")

.config/nvim/lua/plugins.lua

-- installation code copied from TJ DeVries
-- Only required if you have packer in your `opt` pack
local packer_exists = pcall(vim.cmd, [[packadd packer.nvim]])

if not packer_exists then
  -- TODO: Maybe handle windows better?
  if vim.fn.input("Download Packer? (y for yes)") ~= "y" then
    return
  end

  local directory = string.format(
    '%s/site/pack/packer/start/',
    vim.fn.stdpath('data')
  )

  vim.fn.mkdir(directory, 'p')

  local out = vim.fn.system(string.format(
    'git clone %s %s',
    'https://github.com/wbthomason/packer.nvim',
    directory .. '/packer.nvim'
  ))

  print(out)
  print("Downloading packer.nvim...")

  return
end

return require('packer').startup {
    function()

        --use {'wbthomason/packer.nvim', opt = true}
        use {'wbthomason/packer.nvim'}
        use {'joshdick/onedark.vim', config = 'vim.cmd [[ colorscheme onedark ]]'}
        use {'wellle/targets.vim'}
        use {'kyazdani42/nvim-web-devicons'}
        --use {'bfredl/nvim-luadev'}
        use {'neovim/nvim-lsp'}
        use {'neovim/nvim-lspconfig'}
        use {'haorenW1025/completion-nvim'}
        use {'tjdevries/nlua.nvim'}
        --use {'nvim-treesitter/nvim-treesitter', config = 'require("treesitter")'}
    end
}

.config/nvim/lua/lsp.lua

local function on_attach(_, bufnr)
    vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
    --print("LSP started.")
    require("completion").on_attach({
        sorting = 'alphabet',
        matching_strategy_list = {'exact', 'fuzzy'},
    })
end

require('nlua.lsp.nvim').setup(require("nvim_lsp"), {
  on_attach = on_attach,
  globals = {
   -- Colorbuddy
    "Color", "c", "Group", "g", "s",
  }
})

-- Use <Tab> and <S-Tab> to navigate through popup menu
vim.cmd [[inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"]]
vim.cmd [[inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"]]

-- Set completeopt to have a better completion experience
vim.cmd [[set completeopt=menuone,noinsert,noselect]]

-- Avoid showing message extra message when using completion
vim.cmd [[set shortmess+=c]]

I don't know if it all makes sense. It's more copy & paste and try & error. ;-P

Ich sehe gerade, dass completeopt und shortmess hier doppelt ist. Das habe ich schon global in den settings. X-D

I'm still at the beginning and still have to clean it up.

tjdevries commented 3 years ago

LGTM, we can chat about the confi here if desired.