bash-language-server icon indicating copy to clipboard operation
bash-language-server copied to clipboard

Add ability to not use --external-sources flag in shellcheck

Open mikesmithgh opened this issue 1 year ago • 1 comments

What is the problem this feature will solve?

When I am quickly modifying and saving shell scripts, especially those with references to other scripts, the number of shellcheck processes running in the background stack up. If I am not careful, it will use too much memory on my machine until they have completed or I pkill -9 shellcheck.

I'm on a Mac and using Neovim. Setup: I am using mason-lspconfig.nvim and nvim-lspconfig with the following configuration for bash-language-server

        ['bashls'] = function()
          lspconfig.bashls.setup({
            filetypes = { 'sh', 'bash' },
            settings = {
              -- see https://github.com/bash-lsp/bash-language-server/blob/main/server/src/config.ts
              bashIde = {
                backgroundAnalysisMaxFiles = 500,

                -- Glob pattern for finding and parsing shell script files in the workspace.
                -- Used by the background analysis features across files.

                -- Prevent recursive scanning which will cause issues when opening a file
                -- directly in the home directory (e.g. ~/foo.sh).
                --
                -- Default upstream pattern is "**/*@(.sh|.inc|.bash|.command)".
                globPattern = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)',
                shellcheckArguments = ''
              },
            }
          })

Demo of the problem when --external-soucres is set:

https://github.com/bash-lsp/bash-language-server/assets/10135646/22dd2f85-92a3-4cdd-91fd-af87cd7447a0

What is the feature you are proposing to solve the problem?

I would like to have an option to either

  1. not set --external-sources https://www.shellcheck.net/wiki/Directive#external-sources
  2. an option to override shellcheck arguments instead of appending arguments. Currently, shellCheckArguments appends to the existing defaults --shell --format --external-sources.

The --external-sources flag is being set at: https://github.com/bash-lsp/bash-language-server/blob/1740dd4aa1707ec2205252caeb1fb190222fca3a/server/src/shellcheck/index.ts#LL125C15-L125C15

What alternatives have you considered?

Workaround:

Add the following configuration to $XDG_CONFIG_HOME/shellcheckrc or ~/.shellcheckrc

# Allow opening any 'source'd file, even if not specified as input
external-sources=false

mikesmithgh avatar Jun 15 '23 14:06 mikesmithgh