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

Help - Can't make basic setup with NeoVim for linting/diagnostics #89

Closed
weilbith opened this issue Jan 8, 2021 · 15 comments
Closed

Help - Can't make basic setup with NeoVim for linting/diagnostics #89

weilbith opened this issue Jan 8, 2021 · 15 comments

Comments

@weilbith
Copy link

weilbith commented Jan 8, 2021

Hey guys,
it was for a long time on my ToDo list. Now I started to migrate for using this general purpose language server as my primary linting and formatting tool within NeoVim. But unfortunately I do already fail for the first linter shellcheck (I tried others, but also without success). I tried now a while and searched for help. But I just don't get it working. Therefore I'm now sharing my current state here and hope someone can spot the mistake.

As I stated I'm using the NeoVim built-in language server client. In addition I use the nvim-lspconfig plugin.
First my binary versions:

  • nvim: v0.5.0-dev+1012-gfe1ebea33
  • efm-langserver: 0.0.26-1
  • shellcheck: 0.7.1

In my NeoVim configuration I have the following Lua snippet:

local shellcheck = {
 lintCommand = "shellcheck -f gcc -x -",
 lintStdin = true,
 lintFormats = {"%f=%l:%c: %trror: %m", "%f=%l:%c: %tarning: %m", "%f=%l:%c: %tote: %m"}
}

require('lspconfig').efm.setup({
 cmd = {"efm-langserver", "-logfile", "/tmp/efm.log", "-loglevel", "1" },
 settings = {
   languages = {
     sh = { shellcheck },
   }
 }
})

The test script I use is the following:

#!/bin/bash
var='foo  bar'
echo $var

Running shellcheck in the shell looks like that:

$ /bin/cat ./test.sh | shellcheck -f gcc -x -
-:3:6: note: Double quote to prevent globbing and word splitting. [SC2086]

Now I open the the file with NeoVim. Here some command output:

  • :echo &ft: sh
  • :lua print(vim.inspect(#vim.lsp.buf_get_clients())): 1
  • :lua vim.lsp.diagnostic.set_loclist() + :echo len(getloclist(0)): 0
  • :lua print(vim.inspect(vim.lsp.buf_get_clients()[1])):
    output
    {
    _on_attach = <function 1>,
    callbacks = <1>{
    ["client/registerCapability"] = <function 2>,
    ["window/logMessage"] = <function 3>,
    ["window/showMessage"] = <function 4>,
    ["workspace/configuration"] = <function 5>
    },
    cancel_request = <function 6>,
    config = {
    capabilities = {
    callHierarchy = {
    dynamicRegistration = false,
    = <2>{
    __tostring = <function 7>
    }
    },
    textDocument = {
    codeAction = {
    codeActionLiteralSupport = {
    codeActionKind = {
    valueSet = { "", "Empty", "QuickFix", "Refactor", "RefactorExtract", "RefactorInline", "RefactorRewrite", "Source", "SourceOrganizeImports", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" },
    = <table 2>
    },
    = <table 2>
    },
    dynamicRegistration = false,
    = <table 2>
    },
    completion = {
    completionItem = {
    commitCharactersSupport = false,
    deprecatedSupport = false,
    documentationFormat = { "markdown", "plaintext" },
    preselectSupport = false,
    snippetSupport = false,
    = <table 2>
    },
    completionItemKind = {
    valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 },
    = <table 2>
    },
    contextSupport = false,
    dynamicRegistration = false,
    = <table 2>
    },
    declaration = {
    linkSupport = true,
    = <table 2>
    },
    definition = {
    linkSupport = true,
    = <table 2>
    },
    documentHighlight = {
    dynamicRegistration = false,
    = <table 2>
    },
    documentSymbol = {
    dynamicRegistration = false,
    hierarchicalDocumentSymbolSupport = true,
    symbolKind = {
    valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 },
    = <table 2>
    },
    = <table 2>
    },
    hover = {
    contentFormat = { "markdown", "plaintext" },
    dynamicRegistration = false,
    = <table 2>
    },
    implementation = {
    linkSupport = true,
    = <table 2>
    },
    publishDiagnostics = {
    relatedInformation = true,
    tagSupport = {
    valueSet = { 1, 2 },
    = <table 2>
    },
    = <table 2>
    },
    references = {
    dynamicRegistration = false,
    = <table 2>
    },
    rename = {
    dynamicRegistration = false,
    prepareSupport = true,
    = <table 2>
    },
    signatureHelp = {
    dynamicRegistration = false,
    signatureInformation = {
    documentationFormat = { "markdown", "plaintext" },
    = <table 2>
    },
    = <table 2>
    },
    synchronization = {
    didSave = true,
    dynamicRegistration = false,
    willSave = false,
    willSaveWaitUntil = false,
    = <table 2>
    },
    typeDefinition = {
    linkSupport = true,
    = <table 2>
    },
    = <table 2>
    },
    window = {
    showDocument = {
    support = false,
    = <table 2>
    },
    showMessage = {
    messageActionItem = {
    additionalPropertiesSupport = false,
    = <table 2>
    },
    = <table 2>
    },
    workDoneProgress = true,
    = <table 2>
    },
    workspace = {
    applyEdit = true,
    configuration = true,
    symbol = {
    dynamicRegistration = false,
    hierarchicalWorkspaceSymbolSupport = true,
    symbolKind = {
    valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 },
    = <table 2>
    },
    = <table 2>
    },
    workspaceFolders = true,
    = <table 2>
    }
    },
    cmd = { "efm-langserver" },
    flags = {},
    handlers = <table 1>,
    init_options = vim.empty_dict(),
    log_level = 2,
    message_level = 2,
    name = "efm",
    on_attach = <function 8>,
    on_exit = <function 9>,
    on_init = <function 10>,
    root_dir = "/tmp/tmp.2hNc8BEJhu",
    settings = {
    languages = {
    sh = { {
    lintCommand = "shellcheck -f gcc -x -",
    lintFormats = { "%f=%l:%c: %trror: %m", "%f=%l:%c: %tarning: %m", "%f=%l:%c: %tote: %m" },
    lintStdin = true
    } },
    = <table 2>
    },
    = <table 2>
    },
    = <table 2>
    },
    handlers = <table 1>,
    id = 1,
    initialized = true,
    is_stopped = <function 11>,
    messages = {
    messages = {},
    name = "efm",
    progress = {},
    status = {}
    },
    name = "efm",
    notify = <function 12>,
    offset_encoding = "utf-16",
    request = <function 13>,
    resolved_capabilities = {
    call_hierarchy = false,
    code_action = false,
    completion = false,
    declaration = false,
    document_formatting = false,
    document_highlight = false,
    document_range_formatting = false,
    document_symbol = false,
    execute_command = false,
    find_references = false,
    goto_definition = true,
    hover = false,
    implementation = false,
    rename = false,
    signature_help = false,
    signature_help_trigger_characters = {},
    text_document_did_change = 1,
    text_document_open_close = true,
    text_document_save = false,
    text_document_save_include_text = false,
    text_document_will_save = false,
    text_document_will_save_wait_until = false,
    type_definition = false,
    workspace_folder_properties = {
    changeNotifications = true,
    supported = true
    },
    workspace_symbol = false
    },
    rpc = {
    handle = <userdata 1>,
    notify = <function 14>,
    pid = 1359845,
    request = <function 15>
    },
    server_capabilities = {
    definitionProvider = true,
    textDocumentSync = 1,
    workspace = {
    workspaceFolders = {
    changeNotifications = true,
    supported = true
    }
    }
    },
    stop = <function 16>,
    supports_method = <function 17>,
    workspaceFolders = { {
    name = "/tmp/tmp.2hNc8BEJhu",
    uri = "file:///tmp/tmp.2hNc8BEJhu"
    } },
    workspace_did_change_configuration = <function 18>
    }

The log file get created but is empty.


Thanks for any help in advance! 🙏

@weilbith weilbith changed the title Help - Can't make basic setup Help - Can't make basic setup with NeoVim for linting/diagnostics Jan 8, 2021
@gegoune
Copy link

gegoune commented Jan 8, 2021

This works for me:

local spellcheck =  {
  lintCommand = "shellcheck -f gcc -x -",
  lintStdin = true,
  lintFormats = {"%f:%l:%c: %trror: %m", "%f:%l:%c: %tarning: %m", "%f:%l:%c: %tote: %m"}
}

Seems like your lintFormats does not match shellcheck's output (no = in output).

@weilbith
Copy link
Author

weilbith commented Jan 8, 2021

Good catch. I'm sorry I just copied the format.
But it still does not work. Now (not sure why) I get this message in the log each time I open the file in NeoVim:
2021/01/08 14:06:54 lint for LanguageID not supported: sh.

Except of having other looking on my configuration and search for errors, how could I further investigate here? Is there an option do to some kind of JSON-RPC requests to the server with curl or similar? Thinking about adding a custom handler for the diagnostic handling to NeoVim to get the direct response of the server and see if there is something in the "middleware" that goes wrong.

@weilbith
Copy link
Author

weilbith commented Jan 8, 2021

I the linting command fails "inside" the efm server, can I somehow see this? Or if the output parsing fails (also after @cloggier his fix that shouldn't be the case) can I see the original output? In fact get some debugging linting. The log is very silent...

@samkatt
Copy link

samkatt commented Jan 9, 2021

@weilbith I had similar issues in getting a linter to work with markdown (same error msg anyways). I ended up having no configurations within the nvim setup

require "lspconfig".efm.setup { }

But made sure the configurations were specified in $HOME/.config/efm-langserver/config.yaml. Not sure if you can make efm-langserver use spellcheck through such a config file, YMMV.

I also noticed you can try to increase the log level. I set it arbitrarily to 10 (as opposed to 1, that I saw in an example), which gave more information than just "languageID not supported".

# ..../config.yaml
log-file: /path/to/file
log-level: 10

languages:
    sh: ....

@weilbith
Copy link
Author

weilbith commented Jan 9, 2021

Thanks for the kind hint!
I'll definitely give this a try to see if I can make it work this way. But in the end I would highly prefer to not have this configuration file. Especially because I need the update settings functionality to alternate linters and formatters on project basis.

@weilbith
Copy link
Author

weilbith commented Jan 9, 2021

Alright.Thanks for you help. I must admit that I can't tell what the exact issue was. But NeoVim still lacks in propagating Lua syntax errors in vim scripts. 😑
But it works now and I'm super happy and excited to use this language server now! 🥳

@weilbith weilbith closed this as completed Jan 9, 2021
@kabouzeid
Copy link

@weilbith did you get it to work without the yaml config file? I have the same exact issue as you are describing.

@weilbith
Copy link
Author

@weilbith did you get it to work without the yaml config file? I have the same exact issue as you are describing.

Yes. It does work. Though I must admit that I have not found the time/pressure to add many linter/formatter yet. Here the lspconfig part and here the actual configurations. But only stuff I have actually yet commited. 🙈
But that should be enough for you as example to follow. I hope it helps.

PS: The LspInfo command is quite useful to check things.

@kabouzeid
Copy link

Thank you! I'm already doing the same thing as in your config; I can't figure out why it's not working. The log always tells me lint for LanguageID not supported: sh...

@kabouzeid
Copy link

Configuring via config.yaml makes it work immediately, but this is not what I want :/

@weilbith
Copy link
Author

Yes, as I wrote I had similar issues and then it kinda resolved itself. Sorry for that stupid statement. But I work on the AUR nightly binary package for NeoVim and update my plugins daily. And as both are under heavy development... 🤷🏾
Also it probably don't help, here my version:

  • efm-langserver 0.0.26 (rev: HEAD/go1.15.6)
  • NVIM v0.5.0-dev+1160-g0f7b6b2ef
  • lspconfig 26c499916ddac29675d316a099b376abf6a0aeaf

@kabouzeid
Copy link

Thanks for the version info. This is so weird, I'll look further into this and tell you when I find something :)

@kabouzeid
Copy link

Ok I fixed it, found an unmarshal error in the log. Thanks again for your help!

I had lintFormats = '%f:%l:%c: %m' in a linter for a different language. Changing it to lintFormats = { '%f:%l:%c: %m' } fixed it.

@weilbith
Copy link
Author

I'm glad you managed to resolve your issue. 🤗

@dhruvinsh
Copy link

I has similar issue as well, but turns out it was just config issue. #158

issue described here: #158 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants