question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lspconfig: Autostart for emmet_ls failed: matching root directory not detected

See original GitHub issue

After a recent update, “emmet_ls” just stopped working completely and prompted the following error message whenever an html or css file is opened:

Screen Shot 2021-12-01 at 1 13 43 AM

The following is my config file:

-- Setup lspconfig.
  local capabilities = vim.lsp.protocol.make_client_capabilities()
  capabilities.textDocument.completion.completionItem.snippetSupport = true  
  
-- Emmet 
  require'lspconfig/configs'.emmet_ls = {
    default_config = {
      cmd = { 'emmet-ls', '--stdio' };
      filetypes = { 'html', 'css', 'scss', 'xml', 'pug', 'sass'};
      root_dir = function(fname)
        return vim.loop.cwd()
      end;
      settings = {};
    };
  }

-- Language Servers:
  local langservers = {
    'cssls',
    'html',
    'emmet_ls',
    'pylsp',
    'tsserver',
  } 

  for _, server in ipairs(langservers) do
    require'lspconfig'[server].setup {
      capabilities = capabilities
    }
  end

To troubleshoot this, I did clear out my config file and pasted in only the suggested configuration code below from GitHub but the same error message still pop-up indicating “root directory not detected”

local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'    

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true

if not lspconfig.emmet_ls then    
  configs.emmet_ls = {    
    default_config = {    
      cmd = {'emmet-ls', '--stdio'};
      filetypes = {'html', 'css', 'blade'};
      root_dir = function(fname)    
        return vim.loop.cwd()
      end;    
      settings = {};    
    };    
  }    
end    
lspconfig.emmet_ls.setup{ capabilities = capabilities; }

All the other language servers are working properly except “emmet_ls.” Any reply would be great appreciated, million thanks in advance.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
carlituxcommented, Nov 30, 2021

@mondenoir not sure if will work but you can try, next will use your current working directory as your root_dir.

local lspconfig = require'lspconfig'

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
lspconfig.emmet_ls.setup{ 
    capabilities = capabilities,
    root_dir = function(fname)    
        return vim.loop.cwd()
    end,
}
1reaction
mondenoircommented, Nov 30, 2021

@carlitux You did it again my friend 😃

Due to your reply, I was able to tweaked my config file and now everything works just like before the update 👍👍👍 As a newcomer to the Vim community, you have no clue how much these replies means to me. Thanks a million carlitux 🙏🙏🙏

PS: I will leave a copy of the configuration below to illustrate what I did wrong and what carlitux did to help me correct the mistakes:

-- Defining lspconfig + capabilities 
  local lspconfig = require'lspconfig'
  local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
  capabilities.textDocument.completion.completionItem.snippetSupport = true

-- Emmet 
  lspconfig.emmet_ls.setup{ 
      capabilities = capabilities,
      filetypes = { 'html', 'css', 'scss', 'xml', 'pug', 'sass'};
      root_dir = function(fname)    
          return vim.loop.cwd()
      end,
  }

-- Language Servers:
  local langservers = {
    'cssls',
    'html',
    'pylsp',
    'tsserver',
  } 

-- Setting up lspconfig
  for _, server in ipairs(langservers) do
    lspconfig[server].setup {
      capabilities = capabilities
    }
  end
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting error matching root directory not detected ... - GitHub
Description If I open a file through netrw, I get the error Autostart for failed: matching root directory not detected while trying to...
Read more >
LSP not working with inline_edit.vim or NrrwRgn (Autostart for ...
Once I git init , i.e. .git in project_root, the error Autostart for omnisharp failed: matching root directory not detected went away and...
Read more >
Lsp disable autostart message - Neovim Discourse
Autostart for angularls failed: matching root directory not detected. ... (from lspconfig) saying we couldn't autostart angularls because we can't detect ...
Read more >
null-ls autostart - You.com | The search engine you control.
First, the :LspInfo command comes from nvim-lspconfig, and autostart is only valid ... `Autostart for null-ls failed: matching root directory not detected.
Read more >
Updates based on Chris's lunarvim - dotfiles
If it is not found revert to global Prettier where needed. -local M = {} - -M.setup = function() - local tsserver_args =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found