Skip to content

Commit

Permalink
feat: BREAKING CHANGES - simplify setup [v1] (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
creativenull authored Aug 21, 2023
1 parent c8474fb commit 3c274bb
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 263 deletions.
162 changes: 80 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@
<img src="https://dotfyle.com/plugins/creativenull/efmls-configs-nvim/shield" alt="Configs on dotfyle">
</a>

An unofficial collection of linters and formatters configured for [efm-langserver][efm-langserver] to work with the
built-in [nvim-lsp][nvim-lsp]. Works only for Neovim >= 0.5.
An unofficial collection of linters and formatters configured for [efm-langserver][efm-langserver] for neovim.

## Supported linters and formatters

Check out [SUPPORTED_LIST.md](./doc/SUPPORTED_LIST.md)
[doc/SUPPORTED_LIST.md](./doc/SUPPORTED_LIST.md)

## Features

+ Out-of-box configurations for 70+ linters & 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)
+ Use `:checkhealth` for a quick diagnostic on tools, to check if tool is available
+ Ability to customize configurations for your specific project use-cases (see [Advanced Setup](#advanced-configuration-setup))
- 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
- Customize configurations for your specific use-case (see [Advanced Setup](#advanced-configuration-setup))

## Vim Docs
## Documentation

Documentation can be accessed via [`:help efmls-configs`](./doc/efmls-configs.txt) or [further below](#documentation).
Documentation can be accessed via [`:help efmls-configs`](./doc/efmls-configs.txt) or [further below](#setup).

## Requirements

+ [Neovim 0.5 and up][neovim]
+ [nvim-lspconfig][lspconfig]
+ [efm-langserver][efm-langserver], installed globally - follow instructions on the repo
- [Neovim >= 0.7][neovim]
- [efm-langserver][efm-langserver] installed globally. If using [mason.nvim](https://github.com/williamboman/mason.nvim)
then install with `:MasonInstall efm`.

## Installation

Expand All @@ -38,7 +37,7 @@ Install with your favorite plugin manager or just use builtin packages.
```lua
{
'creativenull/efmls-configs-nvim',
version = 'v0.2.x', -- tag is optional
version = 'v1.x.x', -- version is optional, but recommended
dependencies = { 'neovim/nvim-lspconfig' },
}
```
Expand All @@ -48,7 +47,7 @@ Install with your favorite plugin manager or just use builtin packages.
```lua
use {
'creativenull/efmls-configs-nvim',
tag = 'v0.2.*', -- tag is optional
tag = 'v1.*', -- tag is optional, but recommended
requires = { 'neovim/nvim-lspconfig' },
}
```
Expand All @@ -57,107 +56,106 @@ use {

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

## Documentation

### Setup
## Setup

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

#### Step 1

You need to first initialize the plugin with the `init()` function, this is where you can pass your LSP options like
`on_attach`, `capabilities`, `init_options`, etc.
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.

```lua
local function on_attach(client)
print('Attached to ' .. client.name)
end
-- 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 },
}

local efmls = require 'efmls-configs'
efmls.init {
-- Your custom attach function
on_attach = on_attach,
-- Or use the defaults provided by this plugin
-- check doc/SUPPORTED_LIST.md for the supported languages
--
-- local languages = require('efmls-configs.defaults').languages()

-- Enable formatting provided by efm langserver
local efmls_config = {
filetypes = vim.tbl_keys(languages),
settings = {
rootMarkers = { '.git/' },
languages = languages,
},
init_options = {
documentFormatting = true,
documentRangeFormatting = true,
},
}
```

#### Step 2

Finally, register the linters and formatters you want to run on the specific filetypes with the `setup()` function.
Below is an example to setup eslint and prettier to work with a `javascript` filetype.

```lua
local eslint = require 'efmls-configs.linters.eslint'
local prettier = require 'efmls-configs.formatters.prettier'
efmls.setup {
javascript = {
linter = eslint,
formatter = prettier,
},
}
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 Configuration
### Default Configurations

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

A default configuration for the supported filetypes is provided but not activated by default.
Default configurations are an opt-in feature. To see all the configurations provided by default go to
[`doc/SUPPORTED_LIST.md`](./doc/SUPPORTED_LIST.md).

To activate the default configuration you can pass the `default_config` flag as true in the init function. Below are
the default values for `init()`:
You can use a list of defaults provided by this plugin, in-case you don't want to specify configuration
for each language.

```lua
efmls.init {
-- Use a list of default configurations
-- set by this plugin
-- (Default: false)
default_config = false,
}

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

You will still need to call the `setup()` after `init()` for the changes to take effect. You can still pass your custom
configurations to `setup()` as show in the [Setup section](#setup) and it will override any default configuration set
by `default_config` if it's the same filetype.
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.

### Advanced Configuration Setup
```lua
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'),
},
})
```

See also `:help efmls-configs-advanced` to view inside neovim.
## Troubleshooting

If you want to change some settings that are not provided in the default config, you can change them with `vim.tbl_extend`.
These configs take the same keys referenced in the [efm-langserver schema file][schema-file] in json format, aka
`camelCase`.
See also `:help efmls-configs-issues` to view docs inside neovim.

```lua
local eslint = require 'efmls-configs.linters.eslint'
eslint = vim.tbl_extend('force', eslint, {
prefix = 'new eslint prefix',
lintCommand = 'eslint --format visualstudio --stdin',
})
Always run `:checkhealth` to see if there are any issue, when you get no response from the linter or formatter
as you expected.

efmls.setup {
javascript = { linter = eslint },
}
```
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.

## Implementation Details (TODO)
## Alternatives

+ [ ] Testing
- ALE - [https://github.com/dense-analysis/ale](https://github.com/dense-analysis/ale)
- diagnostic-languageserver - [https://github.com/iamcco/diagnostic-languageserver](https://github.com/iamcco/diagnostic-languageserver)
- guard.nvim - [https://github.com/nvimdev/guard.nvim](https://github.com/nvimdev/guard.nvim)
- nvim-lint - [https://github.com/mfussenegger/nvim-lint](https://github.com/mfussenegger/nvim-lint)
- formatter.nvim - [https://github.com/mhartington/formatter.nvim](https://github.com/mhartington/formatter.nvim)

## Credits

Credits goes to the following projects for inspiration:

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

[efm-langserver]: https://github.com/mattn/efm-langserver
[schema-file]: https://github.com/mattn/efm-langserver/blob/master/schema.json
Expand Down
17 changes: 0 additions & 17 deletions autoload/health/efmls_configs.vim

This file was deleted.

Loading

0 comments on commit 3c274bb

Please sign in to comment.