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 not working #57

Closed
Josh-Piper opened this issue Nov 10, 2023 · 4 comments
Closed

Neovim setup not working #57

Josh-Piper opened this issue Nov 10, 2023 · 4 comments

Comments

@Josh-Piper
Copy link

Hey!

found this plugin from Bran van der Meer latest video on ubiquitous languages.

I was able to get the plugin working using Visual Studio Code pretty much immediately.

However, I could not get the neovim set up working.

Describe the bug
When typing a word such as "definition/alias" I expect an autocomplete to popup with the definition, instead I am getting nothing.

To Reproduce
I have installed the LSP server using the osx arm build for an M1 Mac. It is located in /usr/local/bin and can be executed (had to accept the run anyway in the Apple security settings).

I am able to run the following lua commands listed in the README.md file without any errors using :lua [command].

require("lspconfig.configs").contextive = { default_config = { cmd = { "Contextive.LanguageServer" }, root_dir = require("lspconfig").util.root_pattern('.contextive', '.git'), } }
require("lspconfig").contextive.setup{}

I tried this since my configuration in lsp.luawithin my Neovim nvim repository wasn't loading it either. Note I am using LazyVim
plugins/lsp.lua

return {
  {
    "VonHeikemen/lsp-zero.nvim",
    branch = "v2.x",
    dependencies = {

      {
        "williamboman/mason.nvim",
        opts = {
          ui = { border = "rounded" },
        },
      },
      { "williamboman/mason-lspconfig.nvim" },

      --cmp
      { "hrsh7th/nvim-cmp" },
      { "hrsh7th/cmp-buffer" },
      { "hrsh7th/cmp-path" },
      { "saadparwaiz1/cmp_luasnip" },
      { "hrsh7th/cmp-nvim-lsp" },
      { "hrsh7th/cmp-nvim-lua" },

      --snip
      { "L3MON4D3/LuaSnip" },
      { "rafamadriz/friendly-snippets" },
    },
    config = function()
      local lsp = require("lsp-zero")

      lsp.preset("recommended")

      lsp.ensure_installed({
        "tsserver",
        "lua_ls",
        "eslint",
      })

      -- Fix Undefined global 'vim'
      lsp.configure("lua_ls", {
        settings = {
          Lua = {
            diagnostics = {
              globals = { "vim" },
            },
          },
        },
      })

      local cmp = require("cmp")
      local cmp_select = { behavior = cmp.SelectBehavior.Select }
      local cmp_mappings = lsp.defaults.cmp_mappings({
        ["<C-n>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
        ["<C-p>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
        ["<C-b>"] = cmp.mapping.scroll_docs(-4),
        ["<C-f>"] = cmp.mapping.scroll_docs(4),
        ["<C-Space>"] = cmp.mapping.complete(),
        ["<C-e>"] = cmp.mapping.abort(),
        ["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
        ["<S-CR>"] = cmp.mapping.confirm({
          behavior = cmp.ConfirmBehavior.Replace,
          select = true,
        }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
      })

      lsp.setup_nvim_cmp({
        preselect = cmp.PreselectMode.None,
        mapping = cmp_mappings,
      })

      lsp.set_preferences({
        suggest_lsp_servers = false,
      })

      lsp.setup()

      vim.diagnostic.config({
        virtual_text = false,
      })
    end,
  },
  {
    "hrsh7th/nvim-cmp",
    dependencies = { "hrsh7th/cmp-emoji" },
    ---@param opts cmp.ConfigSchema
    opts = function(_, opts)
      local cmp = require("cmp")
      opts.sources = cmp.config.sources(vim.list_extend(opts.sources, { { name = "emoji" } }))
    end,
  },
  --lsp support
  {
    "neovim/nvim-lspconfig",
    dependencies = { "jose-elias-alvarez/typescript.nvim" },
    config = function()
      local lspconfig = require("lspconfig")

      local lspconfig_configs = require("lspconfig.configs")

      lspconfig_configs.contextive = {
        default_config = {
          cmd = { "Contextive.LanguageServer" },
          root_dir = lspconfig.util.root_pattern(".contextive", ".git"),
        },
      }

      lspconfig.contextive.setup({})
    end,
    opts = {
      autoformat = false,
      servers = {
        tsserver = {
          settings = {
            typescript = {
              inlayHints = {
                -- taken from https://github.com/typescript-language-server/typescript-language-server#workspacedidchangeconfiguration
                includeInlayEnumMemberValueHints = true,
                includeInlayFunctionLikeReturnTypeHints = true,
                includeInlayFunctionParameterTypeHints = true,
                includeInlayParameterNameHints = "all",
                includeInlayParameterNameHintsWhenArgumentMatchesName = true, -- false
                includeInlayPropertyDeclarationTypeHints = true,
                includeInlayVariableTypeHints = true,
                includeInlayVariableTypeHintsWhenTypeMatchesName = true, -- false
              },
            },
            javascript = {
              inlayHints = {
                includeInlayEnumMemberValueHints = true,
                includeInlayFunctionLikeReturnTypeHints = true,
                includeInlayFunctionParameterTypeHints = true,
                includeInlayParameterNameHints = "all",
                includeInlayParameterNameHintsWhenArgumentMatchesName = true,
                includeInlayPropertyDeclarationTypeHints = true,
                includeInlayVariableTypeHints = true,
                includeInlayVariableTypeHintsWhenTypeMatchesName = true,
              },
            },
          },
        },
      },
    },
  },
}

Expected behavior
I believe I should see the definition popup when adding the word inside the IDE
photo-11-10 at 12 58 06@2x
photo-11-10 at 12 58 24@2x

I would also assume I would be able to see Contextive being attached to the buffer when using :LspInfo

45856

Desktop (please complete the following information):

  • OS: OSX Sonoma 14.1
  • Neovim: v0.9.4

Additional context
Would be easier if this could be installed directly using lspzero

@chrissimon-au
Copy link
Contributor

Hi @Josh-Piper, thanks for your report.

The neovim documentation is a pretty recent addition to Contextive thanks to contributions from @erikjuhani - you can see a screenshot of it working in their pull request: #49 so in theory it should work for you.

Unfortunately I don't have a replication environment setup myself just yet.

One thing to check - I'm not sure the hover appears by default as you're typing - according to https://neovim.io/doc/user/lsp.html#lsp-config a number of keymaps are setup by default (unless you have overwritten them) and by default K is bound to the hover function.

Could you give that a try? I suspect you have to not be in insert mode...

If that doesn't work, I note from the screenshot above it says that the languageclient log is in .local/state/nvim/lsp.log - could you check what's in there?

If still no luck, I wonder if @erikjuhani, would be so kind as to take a look at the above and see if anything jumps out?

Thanks!
Chris

@Josh-Piper
Copy link
Author

Got it working based on the lsp.log.
Neovim did not have access to Mac's /usr/local/bin. I should have just put the binary elsewhere... (your readme states to put it in $HOME so that's my bad).

I was trying to get the intellisense working, that's what I was in insert mode. It's working now
photo-11-10 at 15 42 58@2x

Leaving this here since many might try using a neovim distro. For a simple LazyVim distro config all I needed was

return {
  "neovim/nvim-lspconfig",
  opts = function()
    local lspconfig = require("lspconfig")

    local lspconfig_configs = require("lspconfig.configs")

    lspconfig_configs.contextive = {
      default_config = {
        cmd = { "Contextive.LanguageServer" },
        root_dir = lspconfig.util.root_pattern(".contextive", ".git"),
      },
    }

    lspconfig.contextive.setup({})
  end,
}

@chrissimon-au
Copy link
Contributor

Thanks @Josh-Piper, glad you got it sorted!

In other vim world updates, @erikjuhani has prepped a contribution to nvm-lspconfig - neovim/nvim-lspconfig@master...erikjuhani:nvim-lspconfig:feat/contextive-language-server - I think he's waiting on my review before merging it, and I'm waiting until I've resolved an issue with contextive's config approach in case it affects the configuration (see #55 and possibly #54).

While the neovim config works fine with the default definitions.yml file location, it doesn't yet work if you try and leverage the contextive.path setting to change the location.

Thanks also for the LazyVim contribution - I'll update the main readme docs to include it shortly 🙂

@erikjuhani
Copy link
Contributor

erikjuhani commented Nov 10, 2023

Hey! I’m glad you got it sorted out! I’ve been working on to add the neovim configuration to nvim lsp-config like @chrissimon-au mentioned! I’ve been extremely busy with work recently so my work in this regard has slowed down to a halt. I was planning on revisiting the work this weekend.

After the changes you would not have to install the LSP manually, but use mason to provide it for you! Mason is already included with LazyVim.

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

3 participants