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

Elmls not working: Root directory not found #1990

Closed
JasterV opened this issue Jul 7, 2022 · 3 comments
Closed

Elmls not working: Root directory not found #1990

JasterV opened this issue Jul 7, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@JasterV
Copy link

JasterV commented Jul 7, 2022

Description

I installed the elmls language server and I'm using it like the following on my lua file:

require('lspconfig')['elmls'].setup{
       on_attach = on_attach,
       flags = lsp_flags,
       capabilities = capabilities,                                     
       settings = {
           ['elmls'] = {}
       }
   }

Then, when I access an elm project and I open an elm file, I get the following error from LSP:

root directory: Not found. Searched for: root_pattern("elm.json").

Any solution? Thanks!

Neovim version

NVIM v0.8.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Nvim-lspconfig version

No response

Operating system and version

PopOs 22.04

Affected language servers

elmls

Steps to reproduce

Open an elm project, thats it.

Use the default configuration for the elmls

Actual behavior

When executing :LspInfo we can see there is an error message for the root directory

Expected behavior

No response

Minimal config

local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local install_path = join_paths(package_root, 'packer', 'start', 'packer.nvim')
local compile_path = join_paths(install_path, 'plugin', 'packer_compiled.lua')

local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      'neovim/nvim-lspconfig',
    },
    config = {
      package_root = package_root,
      compile_path = compile_path,
    },
  }
end

_G.load_config = function()
  vim.lsp.set_log_level 'trace'
  if vim.fn.has 'nvim-0.5.1' == 1 then
    require('vim.lsp.log').set_format_func(vim.inspect)
  end
  local nvim_lsp = require 'lspconfig'
  local on_attach = function(_, bufnr)
    local function buf_set_option(...)
      vim.api.nvim_buf_set_option(bufnr, ...)
    end

    buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

    -- Mappings.
    local opts = { buffer = bufnr, noremap = true, silent = true }
    vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
    vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
    vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
    vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
    vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
    vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
    vim.keymap.set('n', '<space>wl', function()
      print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
    end, opts)
    vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
    vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
    vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
    vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
    vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
    vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
    vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
  end

  -- Add the server that troubles you here
  local name = 'elmls'
  local cmd', 'elm-language-server' } -- needed for elixirls, omnisharp, sumneko_lua
  if not name then
    print 'You have not defined a server name, please edit minimal_init.lua'
  end
  if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
    print [[You have not defined a server default cmd for a server
      that requires it please edit minimal_init.lua]]
  end

  nvim_lsp[name].setup {
    cmd = cmd,
    on_attach = on_attach,
  }

  print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
  load_plugins()
  require('packer').sync()
  vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
else
  load_plugins()
  require('packer').sync()
  _G.load_config()
end

LSP log

[START][2022-07-06 15:58:12] LSP logging initiated [START][2022-07-06 16:01:30] LSP logging initiated

@JasterV JasterV added the bug Something isn't working label Jul 7, 2022
@justinmk
Copy link
Member

justinmk commented Jul 7, 2022

root directory: Not found. Searched for: root_pattern("elm.json").

do you have a elm.json or not? nvim lsp needs some sort of project marker.

This is also configurable. Why report this as a bug?

@justinmk justinmk closed this as completed Jul 7, 2022
@davilera
Copy link

I'm facing the same issue, and I do have an elm.json file in my root directory. What could be amiss?

@davilera
Copy link

Okay, so it took me some googling but... I fixed the issue by downgrading to node 16. See this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants