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

neovim setup #13

Open
vivere-dally opened this issue Oct 17, 2023 · 5 comments
Open

neovim setup #13

vivere-dally opened this issue Oct 17, 2023 · 5 comments

Comments

@vivere-dally
Copy link

Hi. I am trying to follow your neovim setup recommendation, however I am struggling a bit to make the setup work. This is how I do it using lsp-zero:

    local lsp_config = require("lspconfig.configs")
    if not lsp_config.laravel_ls then
        lsp_config.laravel_ls = {
            default_config = {
                name = "laravel_ls",
                cmd = { vim.fn.expand("$HOME/.local/share/nvim/laravel/laravel-dev-tools"), "lsp", "-vvv" },
                filetypes = { "blade" },
                root_dir = function(pattern)
                    local util = require("lspconfig.util")
                    local cwd = vim.loop.cwd()
                    local root = util.root_pattern("composer.json", ".git", ".phpactor.json", ".phpactor.yml")(pattern)

                    -- prefer cwd if root is a descendant
                    return util.path.is_descendant(cwd, root) and cwd or root
                end,
            },
        }
    end

    local lsp_zero = require("lsp-zero")
    require("lspconfig").laravel_ls.setup({
        capabilities = lsp_zero.get_capabilities(),
    })

    lsp_zero.default_setup("laravel_ls")

I am able to start the lsp (i.e., I can see it by running :LspInfo), however I am getting no LSP completions. Is this lsp dependent on any other piece of particular setup?

@WingHaa
Copy link

WingHaa commented Nov 12, 2023

I got it working after cloning the project and build it. The path for cmd is pointed to the compiled binary.

@t0mri
Copy link

t0mri commented Dec 8, 2023

i cant compile!

image

@jeromeluciano
Copy link

i cant compile!

image

you need to "composer install" first to install dependencies and autoloader

@t0mri
Copy link

t0mri commented Jan 8, 2024

Just to be clear this lsp provides autocomplete just for components (at least in my case), if you expect something like coo-blade, i dont think this is capable of that.

Please correct me if im wrong

@Fsmash
Copy link

Fsmash commented Apr 2, 2024

@t0mri

What it is capable of is in the readme. It provides some diagnostics and the ability to jump to components as well as other things.

@vivere-dally

Your config looks correct. I stole how you handled determining the root directory so here is mine for reference in case you need it. You can replace/ignore all the lines with "lvim" specific stuff.

local configs = require("lspconfig.configs")

configs.blade = {
  default_config = {
    name = "blade",
    cmd = { "/home/bdinh/.local/bin/laravel-dev-tools/laravel-dev-tools", "lsp" },
    filetypes = { 'blade' },
    root_dir = function(pattern)
      local util = require("lspconfig.util")
      local cwd = vim.loop.cwd()
      local root = util.root_pattern("composer.json", ".git", ".phpactor.json", ".phpactor.yml")(pattern)
      return util.path.is_descendant(cwd, root) and cwd or root -- prefer cwd if root is a descendant
    end,
    settings = {},
  },
}

local lsp_zero = require("lsp-zero")
require("lspconfig").blade.setup({
  on_attach = require("lvim.lsp").common_on_attach,
  on_init = require("lvim.lsp").common_on_init,
  on_exit = require("lvim.lsp").common_on_exit,
  -- capabilities = require("lvim.lsp").common_capabilities(),
  capabilities = lsp_zero.get_capabilities(),
})

lsp_zero.default_setup("blade")

I was running into a weird issue with getting the autocomplete to work as well though but after setting some breakpoints in I found out it was because I was naming a livewire component file "Index.php" which the livewire componentregistry will ignore as part of the class name when you call "classToName" for some reason.

You can test this out yourself by just creating a livewire component like "App\Livewire\Test\Index.php" or something. I fixed this by just renaming my file to "Page.php".

@haringsrob
"nameToClass" is invoked here in "app/helpers/SubCommands/Snippets.php"
image

And because only the "Index" portion is cut off, the "class_exists" doesn't throw so when you hit the line to create a new reflection class object an exception is thrown.
image

Adding another try catch could fix this but at the same time I think just telling people not to name their livewire components index is fine. This was honestly such a marginal edge case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants