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

question: where to put configurations? #28

Open
chiefjester opened this issue Aug 13, 2020 · 11 comments
Open

question: where to put configurations? #28

chiefjester opened this issue Aug 13, 2020 · 11 comments
Labels
help wanted Extra attention is needed

Comments

@chiefjester
Copy link

Hi, Sorry for the naive question. I'm trying to use neovim's built-in LSP, and this plugin is in the readme for diagnostic. I was hoping I can use this to enable linting via eslint.

I do see the configuration, but I'm not sure where to put them? Is there an example repo on how this is setup? Thanks!

@iamcco
Copy link
Owner

iamcco commented Aug 14, 2020

in initializationOptions option

@chiefjester
Copy link
Author

hey @iamcco, what I meant was, where do I put this JSON file, do I reference it somewhere in vimrc? I get that coc has its own settings. I am more interested on how it's set up with just using neovim's built-in LSP?

@iamcco
Copy link
Owner

iamcco commented Aug 16, 2020

@thisguychris Where to config initializationOptions options is relative to neovim's built-in LSP client. I do not use the built-in LSP client, so I have no idea. It should be support to config initializationOptions for the LS.

@gorillamoe
Copy link

This lsp config is pretty rough, but should work (thanks @lithammer):

nvim_lsp.diagnosticls.setup{
	filetypes = { "javascript", "javascript.jsx" },
	init_options = {
		filetypes = {
			javascript = "eslint",
			["javascript.jsx"] = "eslint",
			javascriptreact = "eslint",
			typescriptreact = "eslint",
		},
		linters = {
			eslint = {
				sourceName = "eslint",
				command = "./node_modules/.bin/eslint",
				rootPatterns = { ".git" },
				debounce = 100,
				args = {
					"--stdin",
					"--stdin-filename",
					"%filepath",
					"--format",
					"json",
				},
				parseJson = {
					errorsRoot = "[0].messages",
					line = "line",
					column = "column",
					endLine = "endLine",
					endColumn = "endColumn",
					message = "${message} [${ruleId}]",
					security = "severity",
				};
				securities = {
					[2] = "error",
					[1] = "warning"
				}
			}
		}
	}
}

@gorillamoe
Copy link

You can see my current configuration here: https://github.com/walialu/neovimfiles/blob/e68391c1d98b3da2f8adfe1583f258a17295537b/nvim/lua/lsp_config.lua#L46

@smartding
Copy link

I'm using neivim's built-in LSP client, and I have a config as follows for checking shell scripts

local on_attach_vim = function(client)
  require'completion'.on_attach(client)
  require'diagnostic'.on_attach(client)
end

require'nvim_lsp'.diagnosticls.setup{
  on_attach=on_attach_vim,
  filetypes = { "sh", },
  init_options = {
    filetypes = {
      sh = "shellcheck",
    },
    formatFiletypes = {
      sh = "shfmt",
    },
    formatters = {
      shfmt = {
        command = "shfmt",
        args = {
          "-i",
          "2",
          "-bn",
          "-ci",
          "-sr",
        },
      }
    }
  }
}

I have the following plugins installed:

Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/completion-nvim'
Plug 'nvim-lua/diagnostic-nvim'

I open a shell script, nothing happens. Where am I supposed to find the diagnostic information?

@lithammer
Copy link

@smartding that config doesn't generate any diagnostics. I assume you want shellcheck to provide diagnostics, but you don't actually provide it any linter config for it (you only have a formatter configured). I think you need to take a look at the README again for an example of how to configure a linter. You can also search for "diagnosticls shellcheck" on GitHub to find some examples.

@gorillamoe
Copy link

Hey @smartding, you need to config shellcheck to check your files. You can look at my configuration over here (this is how I configured shellcheck):

https://github.com/walialu/neovimfiles/blob/e68391c1d98b3da2f8adfe1583f258a17295537b/nvim/lua/lsp_config.lua#L83

@smartding
Copy link

thank @lithammer @walialu , I figured it out after reading the README in diagnostic-languageserver. Here's my config:

require'nvim_lsp'.diagnosticls.setup{
  on_attach=on_attach_vim,
  filetypes = { "sh", },
  init_options = {
    filetypes = {
      sh = "shellcheck",
    },
    formatFiletypes = {
      sh = "shfmt",
    },
    formatters = {
      shfmt = {
        command = "shfmt",
        args = {
          "-i",
          "2",
          "-bn",
          "-ci",
          "-sr",
        },
      }
    },
    linters = {
      shellcheck = {
        command = "shellcheck",
        rootPatterns = {},
        isStdout = true,
        isStderr = false,
        debounce = 100,
        args = { "--format=gcc", "-"},
        offsetLine = 0,
        offsetColumn = 0,
        sourceName = "shellcheck",
        formatLines = 1,
        formatPattern = {
          "^([^:]+):(\\d+):(\\d+):\\s+([^:]+):\\s+(.*)$",
          {
            line = 2,
            column = 3,
            endline = 2,
            endColumn = 3,
            message = {5},
            security = 4
          }
        },
        securities  = {
          error  ="error",
          warning = "warning",
          note = "info"
        },
      }
    }
  }
}

@nyngwang
Copy link

nyngwang commented Mar 2, 2022

@smartding Do you know how to show diagnostic messages from formatters like isort?

@smartding
Copy link

@nyngwang
No, I don't use isort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants