when i open nvim show me error massage from ast-grep

145 Views Asked by At

machine : arch linux

there is an error massage show when i open neovim from ast-grep lsp :

the error massage: LSP[ast_grep] Failed to load rules: Cannot read configuration.. No such file or directory (os error 2)

so what is meaning and how slove the problem in ast-grep lsp

2

There are 2 best solutions below

0
iltg On

Do you have a sgconfig.y[a]ml in the project root directory?

If you are using lspconfig to manage your language servers take a look here https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#ast_grep

1
Herrington Darkholme On

This error means the ast-grep lsp command starts at a directory without a proper project setup.

ast-grep's language server requires project setup though, so the best way is to start lsp only if it is in a project.

A better ast-grep setup is like this, in your init.lua or so.

local configs = require 'lspconfig.configs'
configs.ast_grep = {
  default_config = {
    cmd = {'ast-grep', 'lsp'};
    single_file_support = false;
    root_dir = nvim_lsp.util.root_pattern('sgconfig.yml');
  };
}

The root_dir will find where the sgconfig.yml exist, and the single_file_support will stop initializing the lsp if no project file is found.

See also editor configuration doc.