How to configure QTCreator to use bash-language-server?
-
I'm using QTCreator 17.02 on MSYS2.
I need to edit some Bash scripts, and would like to use tooling like shfmt, ShellCheck, etc - all from within QTCreator.
Luckily, bash-language-server (https://github.com/bash-lsp/bash-language-server) exists to solve this.Unfortunately, I cannot seem to get this to work. When I open a bash file, QTCreator reports:
LanguageClient Bash Language Server: Unexpectedly finished.The language server itself seems to be implemented as a shell script that has a special case for MSYS:
#!/bin/sh basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") case `uname` in *CYGWIN*|*MINGW*|*MSYS*) if command -v cygpath > /dev/null 2>&1; then basedir=`cygpath -w "$basedir"` fi ;; esac if [ -x "$basedir/node" ]; then exec "$basedir/node" "$basedir/../lib/node_modules/bash-language-server/out/cli.js" "$@" else exec node "$basedir/../lib/node_modules/bash-language-server/out/cli.js" "$@" fiSo at the moment in QTCreator, I'm accessing the language server as follows:
- Startup Behavior: Requires an Open File
- Initialization options: (empty)
- Executable: C:\msys64\usr\bin\sh.exe
- Arguments: C:\msys64\ucrt64\bin\bash-language-server
I'm not really sure how to fix this. It's possible this language server just isn't compatible with QTCreator?
I also tried running the server with "start" before trying to open QTCreator, but that did not help.
I've also tried setting it to use C:/msys64/ucrt64/bin/bash-language-server.cmd, with no arguments - but I have the same error.
EDIT: I tried this on a Rocky 9 machine as well, and here I do get some useful output:
kf.syntaxhighlighting: Unable to resolve external include rule for definition "reStructuredText" in "Bash" qtc.languageserverprotocol.parse: Unexpected header line: "Usage:\n" qtc.languageserverprotocol.parse: Unexpected header line: " bash-language-server start Start listening on stdin/stdout\n" qtc.languageserverprotocol.parse: Unexpected header line: " bash-language-server -h, --help Display this help and exit\n" qtc.languageserverprotocol.parse: Unexpected header line: " bash-language-server -v, --version Print the version and exit\n" qtc.languageserverprotocol.parse: Unexpected header line: "\n" qtc.languageserverprotocol.parse: Unexpected header line: "Environment variables:\n" qtc.languageserverprotocol.parse: Unexpected header field "BASH_IDE_LOG_LEVEL Set the log level (default" in " BASH_IDE_LOG_LEVEL Set the log level (default: info)\n" qtc.languageserverprotocol.parse: Unexpected header line: "\n" qtc.languageserverprotocol.parse: Unexpected header field "Further documentation" in "Further documentation: https://github.com/bash-lsp/bash-language-server\n"So it looks like the issue is that it's interacting with the language server in the wrong way? That's the output I would expect if I just ran the executable with no arguments. I'm not sure how to resolve that though.
-
Hi @Tyler-Shellberg,
on my Ubuntu Linux 24 I installed the
bash-language-serverwithsnapand then setup the language client as follows:
and this works for me. If you have to set
sh.exeas executable, then please try to addstartas argument.Regards