GithubHelp home page GithubHelp logo

creativenull / efmls-configs-nvim Goto Github PK

View Code? Open in Web Editor NEW
252.0 5.0 39.0 242 KB

An unofficial collection of linters and formatters configured for efm-langserver for neovim.

License: MIT License

Lua 89.42% TypeScript 10.58%
nvim-lsp efm-langserver linters formatters nvim-plugin lua neovim

efmls-configs-nvim's Introduction

efmls-configs-nvim

Configs on dotfyle

An unofficial collection of linters and formatters configured for efm-langserver for neovim.

Supported linters and formatters

doc/SUPPORTED_LIST.md

Features

  • Out-of-box configurations for 90+ tools (linters and formatters)
  • Intelligently detect tools installed project-wide or system-wide - works only for node/npm, php/composer and ruby/bundler (additional support for other build tools coming soon, welcome any contributions)
  • :checkhealth integration for status check

Documentation

Documentation can be accessed via :help efmls-configs or further below.

Requirements

Installation

Install with your favorite plugin manager or just use builtin packages.

lazy.nvim

{
  'creativenull/efmls-configs-nvim',
  version = 'v1.x.x', -- version is optional, but recommended
  dependencies = { 'neovim/nvim-lspconfig' },
}

packer.nvim

use {
  'creativenull/efmls-configs-nvim',
  tag = 'v1.*', -- tag is optional, but recommended
  requires = { 'neovim/nvim-lspconfig' },
}

vim-plug

Plug 'neovim/nvim-lspconfig'
Plug 'creativenull/efmls-configs-nvim', { 'tag': 'v1.*' } " tag is optional, but recommended

Setup

See also :help efmls-configs-setup to view docs inside neovim.

To get started, make a languages table that will define configurations for the language of your choice. Or use the defaults provided by this plugin.

-- Register linters and formatters per language
local eslint = require('efmls-configs.linters.eslint')
local prettier = require('efmls-configs.formatters.prettier')
local stylua = require('efmls-configs.formatters.stylua')
local languages = {
  typescript = { eslint, prettier },
  lua = { stylua },
}

-- Or use the defaults provided by this plugin
-- check doc/SUPPORTED_LIST.md for the supported languages
--
-- local languages = require('efmls-configs.defaults').languages()

local efmls_config = {
  filetypes = vim.tbl_keys(languages),
  settings = {
    rootMarkers = { '.git/' },
    languages = languages,
  },
  init_options = {
    documentFormatting = true,
    documentRangeFormatting = true,
  },
}

require('lspconfig').efm.setup(vim.tbl_extend('force', efmls_config, {
  -- Pass your custom lsp config below like on_attach and capabilities
  --
  -- on_attach = on_attach,
  -- capabilities = capabilities,
}))

Default Configurations

See also :help efmls-configs-defaults to view docs inside neovim.

Default configurations are an opt-in feature. To see all the configurations provided by default go to doc/SUPPORTED_LIST.md.

You can use a list of defaults provided by this plugin, in-case you don't want to specify configuration for each language.

local languages = require('efmls-configs.defaults').languages()

To add additional tools which are not provided by default you can extend via vim.tbl_extend(). This can also be used as a way to override defaults.

local languages = require('efmls-configs.defaults').languages()
languages = vim.tbl_extend('force', languages, {
  -- Custom languages, or override existing ones
  html = {
    require('efmls-configs.formatters.prettier'),
  },
})

Tips and Tricks

Format on save

There are couple ways you can format your code on save.

  1. Register an autocmd to run format on save:
local lsp_fmt_group = vim.api.nvim_create_augroup('LspFormattingGroup', {})
vim.api.nvim_create_autocmd('BufWritePost', {
  group = lsp_fmt_group,
  callback = function(ev)
    local efm = vim.lsp.get_active_clients({ name = 'efm', bufnr = ev.buf })

    if vim.tbl_isempty(efm) then
      return
    end

    vim.lsp.buf.format({ name = 'efm' })
  end,
})
  1. If you do not want to write and maintain the code above, then you can rely on a plugin like lukas-reineke/lsp-format.nvim which makes it easier to format on save.

Troubleshooting

See also :help efmls-configs-issues to view docs inside neovim.

Always run :checkhealth to see if there are any issue, when you get no response from the linter or formatter as you expected.

If you get "no executable found" issues in :checkhealth, this means that the linter or formatter was not found in the provided filepath. Ensure that it is installed globally or in a valid filepath.

For nodejs/npm, php/composer, ruby/bundler: check if the linter or formatter is installed in your node_modules (npm), vendor (composer/bundler) project folder, or installed globally.

Mason setup issue (:help efmls-configs-mason)

If you use mason, then you don't need to add anything extra for efmls-configs for it to work. But if you are having problems setting up then check the following:

  1. Make sure you call mason setup() before efm setup()
  2. Run :!which <tool> to check if the path is provided by mason

Alternatives

Credits

Credits goes to the following projects for inspiration:

  • efm-langserver for this awesome language server to provide an interface to run linters/formatters through a LSP protocol
  • ALE for a huge list of linters/formatters to look through and add them in here

efmls-configs-nvim's People

Contributors

1256-bits avatar anthony-fiddes avatar chiel avatar chrisgrieser avatar creativenull avatar custompro98 avatar davidosomething avatar dimitrisdimitropoulos avatar doums avatar gaetanlepage avatar hero3s avatar itaranto avatar j-barnak avatar jwilner avatar kuator avatar llllvvuu avatar mariasolos avatar mohamad-supangat avatar mrjones2014 avatar mskelton avatar nguymin4 avatar noamsto avatar ohakutsu avatar ojii3 avatar phantasimay avatar phrmendes avatar rorynesbitt avatar syyyr avatar trevors avatar whoissethdaniel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

efmls-configs-nvim's Issues

`luacheck` should have `ignoreExitCode = true`

Luacheck was sometimes failing for me and looking at :LspLog I get this:

command `/nix/store/x1r2nxl26vk1kj8kh4zw7pjjn949yn59-luajit2.1-luacheck-1.1.0-1/bin/luacheck --codes --no-color --quiet -` exit with zero. probably you forgot to specify `lint-ignore-exit-code: true`.

Any interest in merging support for sql-formatter?

Hey all! I love using efmls-configs, and I recently used it to add support for sql-formatter in my editor. The code is very simple and I was wondering if you would be interested in me opening a PR to contribute the change (obviously I would run the formatter with the repo's stylua and review the contributing guidelines).

The one thing I thought might be odd/nonstandard is how I added support for configuring the tool with a JSON file in the std config path. If there's a better way to accomplish that I'm definitely open to feedback.

Here's the snippet:

-- Metadata
-- languages: sql
-- url: https://github.com/sql-formatter-org/sql-formatter

local fs = require("efmls-configs.fs")
local ok, Path = pcall(require, "plenary.path")

local args = ""
if ok then
  local cfg = Path:new(vim.fn.stdpath("config"), "sql-formatter.json")
  if cfg:exists() and cfg:is_file() then
    args = string.format("--config %s", cfg)
  end
end

local formatter = "sql-formatter"

local command = string.format("%s %s", fs.executable(formatter, fs.Scope.NODE), args)

return {
  formatCommand = command,
  formatStdin = true,
}

Formatter does not reflect changes to the buffer

Problem

If you ran any formatter that does not take a stdin (Also see #78 and #64) then you will run into problems where you won't see your formatted code changes.

The unfortunate part is that you will have to save the file and then run :edit! to see those changes, since those formatters will only work on files saved on the system.

Solution

One solution would be to run the format command after save, for example (for a better version see the last code block):

local function efm_fmt(buf)
  local matched_clients = vim.lsp.get_active_clients({ name = 'efm', bufnr = buf })

  if vim.tbl_isempty(matched_clients) then
    return
  end

  local win_state = vim.call('winsaveview')

  vim.lsp.buf.format({ name = 'efm' })

  vim.cmd('silent edit!')
  vim.call('winrestview', win_state)
end

You will need winsaveview() and winrestview() so that the cursor and window position is saved before formatting the file. silent is needed so it does not error if it fails, we want to handle it gracefully.

Add this to your on_attach:

local function on_attach(client, buf)
  vim.keymap.set('n', '<Leader>lf', function() efm_fmt(buf) end, { buffer = buf, desc = 'Format the buffer' })

  -- ...
end

Or to your autocmd to format on save:

local lsp_fmt_group = vim.api.nvim_create_augroup('LspFormattingGroup', {})
vim.api.nvim_create_autocmd('BufWritePost', {
  group = lsp_fmt_group,
  callback = function(ev)
    efm_fmt(ev.buf)
  end,
})

Final Solution Code

We can take this one step further and account for when a formatter has formatStdin = false and only call :edit! or just format as is.

local function fmt_with_edit()
  local win_state = vim.call('winsaveview')

  vim.lsp.buf.format({ name = 'efm' })

  vim.cmd('edit!')
  vim.call('winrestview', win_state)
end

local function efm_fmt(buf)
  local matched_clients = vim.lsp.get_active_clients({ name = 'efm', bufnr = buf })

  if vim.tbl_isempty(matched_clients) then
    return
  end

  local efm = matched_clients[1]
  local ft = vim.api.nvim_buf_get_option(buf, 'filetype')
  local formatters = efm.config.settings.languages[ft]

  local matches = vim.tbl_filter(function(fmt)
    return not fmt.formatStdin
  end, formatters)

  if not vim.tbl_isempty(matches) then
    fmt_with_edit()
  else
    vim.lsp.buf.format({ name = 'efm' })
  end
end

[Question|Help] Why my stylua is not working?

My lsp config is:

local lspconfig = require('lspconfig')
local capabilities = require('plugins.lsp.capabilities')

local servers = {
  bashls = {},
  cssls = {},
  efm = require('plugins.lsp.servers.efm'),
  gopls = require('plugins.lsp.servers.gopls'),
  jqls = {},
  jsonls = {},
  jsonnet_ls = {},
  lua_ls = require('plugins.lsp.servers.lua_ls'),
  solargraph = require('plugins.lsp.servers.solargraph'),
  sqlls = {},
  yamlls = require('plugins.lsp.servers.yamlls'),
}

for server, opts in pairs(servers) do
  local config = vim.tbl_deep_extend('force', opts or {}, {
    single_file_support = true,
    capabilities = capabilities,
  })

  lspconfig[server].setup(config)
end

where, plugins.lsp.servers.efm is:

local languages = {
  lua = {
    require('efmls-configs.formatters.stylua'),
  },
  go = {
    require('efmls-configs.linters.golangci_lint'),
  },
  ruby = {
    require('plugins.lsp.servers.efm.rubocop'),
  },
  sh = {
    require('efmls-configs.formatters.shfmt'),
    require('efmls-configs.linters.shellcheck'),
  },
}

return {
  filetypes = vim.tbl_keys(languages),
  settings = {
    logLevel = vim.lsp.log_levels.ERROR,
    logFile = vim.lsp.get_log_path(),
    languages = languages,
  },
  init_options = {
    codeAction = true,
    completion = true,
    documentFormatting = true,
    documentRangeFormatting = true,
    documentSymbol = true,
    hover = true,
  },
}

I tried many different things, but can't find a reason why lua is not getting formatted. :/

I keep getting: INFO [LSP] Format request failed, no matching language servers.

Help?

eslint and eslint_d formatters not working on tsx files

It works perfectly for .js, .jsx, and .ts files, but not for .tsx files.

When I check LspInfo on tsx, it doesn't have efm attached.

formatter: eslint_d
linter: prettier_d

Config

local efmls = require 'efmls-configs'
efmls.init { 
-- Enable formatting provided by efm langserver
  default_config = false,
  init_options = { documentFormatting = true },
  cmd = { 'efm-langserver.cmd' },
}

efmls.setup {
  javascript = {
    linter = require 'efmls-configs.linters.eslint_d',
    formatter = require 'efmls-configs.formatters.prettier_d',
  },
  typescript = {
    linter = require 'efmls-configs.linters.eslint_d',
    formatter = require 'efmls-configs.formatters.prettier_d',
  },
  lua = {
    linter = require 'efmls-configs.linters.luacheck',
    formatter = require 'efmls-configs.formatters.stylua',
  },
}

Machine: Windows
Terminal: PowerShell
Editor: Neovim

how to create a new config

Hello,
thank you for the great work!
I think it would be helpful to have some documentation on how to create a new linter/formatter config.

For example, I have some small custom "linter" scripts that take a filename name as arg and output some diagnostics. E.g.
$ linter_name fname
1:1:some error

where the output has the convention %l:%c:%m. Just for the sake of making it as simple as possible, lets assume that the linter is
#include
#include
using namespace std;

int main(){
cout << "1:1:this is a message"<<endl;
// cout << "1:1:this is a message";
ofstream myfile;
myfile.open("/tmp/log_file");
myfile << "done" << endl;
myfile.close();
return 0;
}

Suppose that the above is compiled to /tmp/a.out

If I use

local fs = require('efmls-configs.fs')
local linter = '/tmp/a.out'
local command = string.format('%s', fs.executable(linter, fs.Scope.NODE))

return {
prefix = linter,
lintCommand = command,
lintStdin = false,
lintFormats = { "%l:%c:%m"},
}

Prettier config out of date

It seems like the prettier config might be out of date. The --stdin flag doesn't seem to be an option anymore with Prettier 3.1.0.

From :LspLog:

[ERROR][2023-11-17 16:46:59] .../vim/lsp/rpc.lua:675	"rpc"	"C:\\Users\\...\\AppData\\Local\\nvim-data\\mason\\bin\\efm-langserver.CMD"	"stderr"	"2023/11/17 16:46:59 C:\\Users\\...\\AppData\\Local\\nvim-data\\mason\\bin\\prettier.CMD --stdin --stdin-filepath '...'   --tab-width 4 : [warn] Ignored unknown option --stdin.\n[error] No parser could be inferred for file \"'...'\".\n\n"

clang format deletes changes on write

Hi and thanks for this plugin I have setup up efm and used your configs for setting up my linters and formatters.

Whenever I save/write a cpp file and a c file the changes, instead of being formatted, are removed for some reason. I was wondering if you know what might be causing this behaviour since I have not specifically configured clang_format on my end, just downloaded it through Mason. When I used clang_format with null-ls this did not happen.

Here is my config:

local prettier = require("efmls-configs.formatters.prettier")
local eslint_d = require("efmls-configs.linters.eslint_d")
local clang_format = require("efmls-configs.formatters.clang_format")
local black = require("efmls-configs.formatters.black")
local stylua = require("efmls-configs.formatters.stylua")
local golangci_lint = require("efmls-configs.linters.golangci_lint")
local gofmt = require("efmls-configs.formatters.gofmt")

local languages = {
	typescript = { eslint_d, prettier },
	typescriptreact = { eslint_d, prettier },
	javascript = { eslint_d, prettier },
	javascriptreact = { eslint_d, prettier },
	json = { prettier },
	html = { prettier },
	cpp = { clang_format },
	c = { clang_format },
	python = { black },
	lua = { stylua },
	go = { golangci_lint, gofmt },
}

and where I setup efm

require("lspconfig").efm.setup({
	init_options = {
		documentFormatting = true,
		documentRangeFormatting = true,
	},
	filetypes = vim.tbl_keys(languages),
	settings = {
		rootMarkers = { ".git/", "package.json" },
		languages = languages,
	},
	capabilities = capabilities,
	on_attach = on_attach,
})

Formatting setup (inside on_attach):

if current_client.supports_method("textDocument/formatting") then
		vim.api.nvim_create_autocmd("BufWritePre", {
			group = augroup,
			buffer = bufnr,
			callback = function()
				lsp_formatting(bufnr)
			end,
		})
	end

lsp_formatting function:

local augroup = vim.api.nvim_create_augroup("LspFormatting", { clear = true })

local lsp_formatting = function(bufnr)
	vim.lsp.buf.format({
		filter = function(client)
			return client.name == "efm"
		end,
		bufnr = bufnr,
	})
end

Thanks in advance ๐Ÿ’ฏ

Not detailed enough output for flake8

ะกะฝะธะผะพะบ ัะบั€ะฐะฝะฐ 2022-07-31 082207

local on_attach = function(client, bufnr)
    ...
end

local efmls = require('efmls-configs')
local black = require('efmls-configs.formatters.black')
local flake8 = require 'efmls-configs.linters.flake8'
efmls.init {
    on_attach = on_attach
}
efmls.setup {
    python = {
        linter = flake8,
        formatter =  black
    }
}

How to remove stdout ? (Trying to add my custom formatter)

Hi !
I'm actually trying to add my custom formatter for prisma.
Here's the code :

local fs = require('efmls-configs.fs')

local formatter = 'prisma'
local command = string.format("%s format", fs.executable(formatter, fs.Scope.NODE))

return {
  formatCommand = command,
  formatStdin = true,
  rootMarkers = {
    "schema.prisma"
  }
}

My problem comes from the command itself. At the end of the command prisma format it output things like this :

Prisma schema loaded from prisma/schema.prisma
Formatted /myproject/schema.prisma in 12ms ๐Ÿš€

And I end up with my buffer being changed to the output message.

Please see :

Enregistrement-2024-02-04-194247

More info : The prisma format command cannot take any other options like --stdout quiet since any other options doesn't exist.

So my question is : Is there any option from your plugin I can use to avoid this problem, or do you have any idea how I can ?

[ERROR][2023-10-10 13:12:33] .../vim/lsp/rpc.lua:675 "rpc" "/home/w/.local/share/nvim/mason/bin/efm-langserver" "stderr" "2023/10/10 13:12:33 nil --color Never -: sh:่กŒ1: nil๏ผšๆœชๆ‰พๅˆฐๅ‘ฝไปค\n\n"

Formatting lua doesn't work. I've installed stylua and the environment variables are correct. It doesn't seem to find the stylua command

[ERROR][2023-10-10 13:12:33] .../vim/lsp/rpc.lua:675    "rpc"   "/home/w/.local/share/nvim/mason/bin/efm-langserver"   "stderr" "2023/10/10 13:12:33 nil --color Never   -: sh:่กŒ1: nil๏ผšๆœชๆ‰พๅˆฐๅ‘ฝไปค\n\n"

my config

local eslint = require("efmls-configs.linters.eslint")
local stylelint = require("efmls-configs.linters.stylelint")
-- local prettier = require("efmls-configs.formatters.prettier")
local prettier_eslint = require("efmls-configs.formatters.prettier_eslint")
local shellcheck = require("efmls-configs.linters.shellcheck")
local shfmt = require("efmls-configs.formatters.shfmt")
local clang_tidy = require("efmls-configs.linters.clang_tidy")
local clang_format = require("efmls-configs.formatters.clang_format")
local rustfmt = require("efmls-configs.formatters.rustfmt")
local luacheck = require("efmls-configs.linters.luacheck")
local stylua = require("efmls-configs.formatters.stylua")
local golangci_lint = require("efmls-configs.linters.golangci_lint")
local gofmt = require("efmls-configs.formatters.gofmt")
local flake8 = require("efmls-configs.linters.flake8")
local autopep8 = require("efmls-configs.formatters.autopep8")
local vint = require("efmls-configs.linters.vint")
local phpcs = require("efmls-configs.linters.phpcs")
local phpcbf = require("efmls-configs.formatters.phpcbf")

local languages = {
	-- Custom languages, or override existing ones
	vim = { vint },
	html = { prettier_eslint },
	css = { stylelint, prettier_eslint },
	less = { stylelint, prettier_eslint },
	scss = { stylelint, prettier_eslint },
	sass = { stylelint, prettier_eslint },
	javascript = { eslint, prettier_eslint },
	javascriptreact = { eslint, prettier_eslint },
	typescript = { eslint, prettier_eslint },
	typescriptreact = { eslint, prettier_eslint },
	vue = { eslint, prettier_eslint },
	c = { clang_tidy, clang_format },
	cpp = { clang_tidy, clang_format },
	lua = { luacheck, stylua },
	php = { phpcs, phpcbf },
	go = { golangci_lint, gofmt },
	rust = { rustfmt },
	python = { flake8, autopep8 },
	sh = { shellcheck, shfmt },
	json = { prettier_eslint },
	jsonc = { prettier_eslint },
}

local efmls_config = {
	filetypes = vim.tbl_keys(languages),
	settings = {
		rootMarkers = { ".git/" },
		languages = languages,
	},
	init_options = {
		documentFormatting = true,
		documentRangeFormatting = true,
	},
}

lspconfig.efm.setup(vim.tbl_extend("force", efmls_config, {
	-- Pass your custom lsp config below like on_attach and capabilities
	--
	-- on_attach = on_attach,
	-- capabilities = capabilities,
}))

golangci_lint linter not working when used from efmls

When I remove '--out-format tab ' from the lint command it starts working

local golangci_lint = require("efmls-configs.linters.golangci_lint")
golangci_lint = vim.tbl_extend("force", golangci_lint, {
lintCommand = 'golangci_lint run --color never "${INPUT}"',
})

Sqlfluff linting does not seem to work

Hello :)

This is my current efm config:

lspconfig.efm.setup(require("lsp.settings.efm"))

-- in lsp/settings/efm.lua
local sqlfluff = require("efmls-configs.linters.sqlfluff")

return {
  filetypes = {
    "sql",
  },
  init_options = {
    documentFormatting = true,
    documentRangeFormatting = true,
    hover = true,
    documentSymbol = true,
    codeAction = true,
    completion = true,
  },
  settings = {
      sql = { sqlfluff },
    },
  },
}

which seems correct because all the other linters/formatted that I have attacched (and omitted in the previous snippet) work correctly.

This is a file that contains offenses:

Screenshot from 2024-05-05 14-06-44

As you see, efm does not report anything on my editor.

However, if I try to run the linter manually, with the flags specified in the config from this repo the warnings are reported.
Screenshot from 2024-05-05 14-08-55

Is there something that I am missing here?

cannot find global node executable if NVM is used

So, I'm using NVM, which is a node version manager that allows me to use different node versions.

my globals are installed in a path like

/home/lucatrazzi/.nvm/versions/node/v16.2.0/bin/eslint_d

using

:lua print(vim.fn.exepath('eslint_d')) 

returns me the correct path so I don't know what is doing wrong

ps: only node globals are giving me issues, the others like stylelua or shfmt works perfect.

can't work on virtual environment

In the default python environment, efmls works perfectly, but in a conda virtual environment, efmls breaks even install all linter and format tool just like in origin environment.

Prettier, Prettierd: tabWidth property in the config file's ignored

Hi, i'm trying to config efm using your config file for prettierd,
This is how i implemented my config before:

local eslint = require("efmls-configs.linters.eslint")
local prettier_d = require("efmls-configs.formatters.prettier_d")

local languages = {
	typescript = {eslint, prettier_d },
	javascript = { eslint, prettier_d },
}

local efmls_config = {
	filetypes = vim.tbl_keys(languages),
	settings = {
		rootMarkers = { ".git/" },
		languages = languages,
	},
	init_options = {
		documentFormatting = true,
		documentRangeFormatting = true,
	},
}

require("lspconfig").efm.setup(vim.tbl_extend("force", efmls_config, {}))

Everything's good so far except for the indent size.
I looked into the source code and noted that you are using the tabSize variable for tab-width argument. AFAIK the correct property for prettier's config file is tabWidth
By changing it to tabWidth i got the indent working properly:

local languages = {
	typescript = {eslint, 	
	{
			formatCommand = "prettierd ${INPUT} ${--tab-width:tabWidth} ${--use-tabs:!insertSpaces} ${--range-start=charStart} ${--range-start=charEnd}",
			formatStdin = true,
		},
	},
	javascript = { eslint, prettier_d },
}

Am i doing something wrong here?

:checkhealth makes the plugin look broken

When you run checkhealth efm-ls.nvim only shows errors, the oks are hidden

If you show OK "stylua": V1.0 etc it will give the happy feelings

Also if the executables aren't required for the plugin to function (e.g. phpcs shouldn't be needed when working in lua) then imo it should be a warning not an error

Generate machine-readable list of tools

Would it be possible to generate a machine readable list of tools in addition to the markdown documentation ?

I help maintain a project called nixvim that maps neovim lua configurations to nix, and to support nicely this plugin we extract from the files the metadata and export it to json (exporter and metadata).

This is a bit brittle, because the tool could break at any time due to upstream changes, and as there already is a generator could it be possible to add a json (or other format) document that lists all the available tools ?

`:checkhealth` is broken

Running healthchecks...
E5009: Invalid $VIMRUNTIME: /nix/store/minvn39fypkwayivr8w7w2ba0jlrsspl-neovim-unwrapped-9f32deb/share/nvim/runtime
Error executing lua: Vim:E117: Unknown function: health#efmls_configs#check
stack traceback:
	[C]: in function 'call'
	...-unwrapped-9f32deb/share/nvim/runtime/lua/vim/health.lua:303: in function <...-unwrapped-9f32deb/share/nvim/runtime/lua/vim/health.lua:271>

It prevents any other healthchecks from running.

Bug: `formatStdin = false` is being ignored

So I was trying to add some more formatters (which I'll happily add via PR, too, when I get them working), however I hit a roadblock with formatters that do not read from stdin.

codespell, for instance, can be used as a formatter to automatically fix misspellings across the whole buffer. This command works for that:

codespell --write-changes foobar.lua

However, when I try to set up the respective efm-config, it appears that formatStdin = false, is being ignored; instead the whole buffer is overwritten with codespell's stdout (which in this case is an empty string):

local fs = require("efmls-configs.fs")

local formatter = "codespell"
local args = "--write-changes ${INPUT}"
local command = string.format("%s %s", fs.executable(formatter), args)

return {
	formatCommand = command,
	formatStdin = false,
}

I tried other formatters with formatStdin = false, and it appears they share that issue. Or am I missing something here?

docs/usage: `lspconfig.setup` directly?

Is it possible to do directly?

require "lspconfig".efm.setup {
    init_options = {documentFormatting = true},
    settings = {
        rootMarkers = {".git/"},
        languages = {
            lua = {
                require('efmls-configs.linters.luacheck'),
                require('efmls-configs.formatters.stylua'),
            }
        }
    }
}

This way no need to go indirectly through efmls-configs-nvim setup API

Fish shell script linting with fish --no-execute

Creating this issue to track a couple things I've already tried.

There are a few issues I've identified why I think it doesn't work by default (but I'm not sure).

First, fish --no-execute outputs a code-window like so:

path/to/script.fish (line 5): Missing end to balance this function definition
function my-function
^~~~~~~^
warning: Error while reading file path/to/script.fish

But we only want to parse the first line with errorformat.

Second issue is that it only reports line, not column, but I think column is required? It also doesn't report an error level, which I think is also required.

null-ls worked around these by just defaulting column to 0 if it was nil, and skipping over any lines that fail to parse with errorformat.

I've got a modified lintCommand that attempt to fix these issues by:

  • prefix each output line with e: so we can parse the error level as error
  • modify the (line 5) to default column to 0 like (line 5, col 0)

The lintCommand I came up with is:

fish --no-execute path/to/script.fish 2>&1 >/dev/null | awk '/\(line [0-9]+):/ { sub(/\)/, ", col 0):"); print "e:" $0 }'

Which gives output like:

e:path/to/script.fish (line 5, col 0):: Missing end to balance this function definition

which I then tried to parse with lintFormats = { '%t:%f (line %l, col %c):: %m' }

But I am still not getting diagnostics in the editor.

Any ideas how I can further debug this?

[feature request] Exclude langs completely from default without `:checkhealth` complaining.

I'd like to use require'efmls-configs.defaults'.languages(), but there are a few languages I know I don't need.

My approach has been something like this:

local function efm_formatter(name)
	return require("efmls-configs.formatters." .. name)
end
local function efm_linter(name)
	return require("efmls-configs.linters." .. name)
end
local default_langs = require"efmls-configs.defaults".languages()
default_langs.python = nil
default_langs.php = nil
default_langs.nix = nil
default_langs.blade = nil
require'lspconfig'.efm.setup{
	on_attach = default_args.on_attach,
	capabilities = capabilities,
	settings = {
		rootMarkers = {".git/"},
		languages = vim.tbl_extend("force", default_langs, {
			rust = { efm_formatter"rustfmt" },
			-- We want both luacheck and selene.
			lua = vim.tbl_extend("keep", default_langs.lua, { efm_linter"selene" }),
			sh = { efm_formatter"shellharden" },
			fish = { efm_linter"fish", efm_formatter"fish_indent" }
		})
	}
}

But the problem is that this plugin seems to be checking for the executables at call-time of the languages function, so these tools (which aren't installed) are warned in the health check as being absent.

Perhaps some sort of argument could be given to not include a language? I'm not really sure.

Aside: It's totally fine if the answer is just "don't use the defaults".

More declarative approach to settings extra args?

https://github.com/creativenull/efmls-configs-nvim/blob/20fa61159a9a1c2b2d12e9d0a99bcfb0da8adf18/lua/efmls-configs/formatters/stylua.lua#L9C26-L9C26

I want to add --indent-type Spaces --indent-width 2 to the stylua command.

What I do now:

  local stylua = require("efmls-configs.formatters.stylua")
  local fs = require("efmls-configs.fs")

  local formatter = "stylua"

  local command = string.format(
    "%s  --indent-type Spaces --indent-width 2 --color Never ${--range-start:charStart} ${--range-end:charEnd} -",
    fs.executable(formatter)
  )

  stylua["command"] = command

Maybe there should be some extraArgs option which we can pass custom arguments to?

Golangci_Lint Lacks Ability to Run Against Package (Possible Configuration Error?)

Hey guys. Thank you for this repo that helps add linters and formatters into Neovim.

I was setting up golangci_lint and I seem to have hit a bit of a problem. I am trying to use it like I did in VSCode where it allowed you to specify that on lint you would lint the current package. I looked into how that would be done and from what I could gather it would be something like golangci_lint run without a file provided. So I tried looking into how things are currently being done and noticed that golangci_lint is configured to run on a single file which causes variables defined in other files in the same package to come back with errors.

Is there a way I can change this to run on the current package (i.e. the current folder) for my own use at the very least? I ask because I tried the following, but it does not seem to work as it does not remove the typecheck errors about variables not defined or does no linting at all:

	local golangci_lint = require("efmls-configs.linters.golangci_lint")

	golangci_lint.lintCommand = golangci_lint.lintCommand:gsub("INPUT", "ROOT") -- and completely removing ${INPUT} as well

I do see that the file replacement seems to happen here which does not seem to have the current folder as an option: https://github.com/mattn/efm-langserver/blob/d1e53448d16a2b20440faab406b625efe9792653/langserver/handler.go#L705-L708
But I am not sure if that is me misunderstanding things or if there truly is no option to run a linter on the current folder instead of the current file. If there is no option to lint the current folder, I can make an FR and possibly a PR for the efm language server.

If more info is needed, please let me know.

Unclear how to partially override `efmls-configs`

For example, I want to incorporate the following:

languages = {
    bash = {
        { formatCommand = "shfmt -i 2 -bn -kp", formatStdin = true }
    }

How do I correctly integrate it in:

local shellcheck = require('efmls-configs.linters.shellcheck')
local shfmt = require('efmls-configs.formatters.shfmt')
local languages = {
    bash = { shfmt, shellcheck },
}

P.S. Perhaps enable the "discussions" module at GitHub for issues like this one?

Use project installed ESLint

Shouldn't efmls recognize the ESLint executable installed on my project and use it to send diagnostics?

When I run :checkhealth efmls-configs it says that no local or global ESLint executables were found. Installing eslint_d from Mason doesn't work as well.

The Prettier installed from Mason is recognized.

I'm using Mason's emf and efmls-configs.defaults settings. Here are my configs:

require("mason-lspconfig").setup({
    ensure_installed = { "lua_ls", "tailwindcss", "efm", "eslint" },
})
require("mason-lspconfig").setup_handlers({
    function(server_name)
        require("lspconfig")[server_name].setup({
	    capabilities = require("cmp_nvim_lsp").default_capabilities(),
        })
    end,
    ["efm"] = function()
	local languages = require("efmls-configs.defaults").languages()

	require("lspconfig").efm.setup(vim.tbl_extend("force", {
	    filetypes = vim.tbl_keys(languages),
		settings = {
		    rootMarkers = { ".git/" },
		    languages = languages,
		},
		init_options = {
		    documentFormatting = true,
		    documentRangeFormatting = true,
		},
	}, {}))
    end,
})

I'm pretty noob with Neovim and tooling, so I'm not sure if this is actually unexpected behavior or if this issue should come here or in mattn/efm-langserver repo.

prettier_d fails `:healthcheck` because `prettier` cannot be found.

When using

require("efmls-configs.formatters.prettier_d"),

with

local languages = {
  javascript = {
    require("efmls-configs.formatters.prettier_d"),
  },
}

I'll fail :checkhealth with an error because the prettier executable cannot be found.

efmls-configs: require("efmls-configs.health").check()

- ERROR "prettier": no executable found, check |efmls-configs-issues| for help

Shouldn't it be looking for the prettierd executable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.