changeset 322:deb606f02fc4

Test if flake8, black are available before adding
author zegervdv <zegervdv@me.com>
date Mon, 21 Dec 2020 11:03:07 +0100
parents aa0a095f8759
children 3b25f3aa7014
files dot_config/nvim/config.lua
diffstat 1 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/dot_config/nvim/config.lua	Mon Dec 21 09:39:45 2020 +0100
+++ b/dot_config/nvim/config.lua	Mon Dec 21 11:03:07 2020 +0100
@@ -130,26 +130,31 @@
 end
 
 if (vim.fn.executable('efm-langserver') == 1) then
+  languages = {};
+
+  languages.python = {};
+  if (vim.fn.executable('black') == 1) then
+    table.insert(languages.python, {
+      formatCommand = "black -",
+      formatStdin = true
+    })
+  end
+  if (vim.fn.executable('flake8') == 1) then
+    table.insert(languages.python, {
+      lintCommand = "flake8 --stdin-display-name ${INPUT} -",
+      lintStdin = true,
+      lintIgnoreExitCode = true,
+      lintFormats = {"%f:%l:%c: %m"}
+    })
+  end
+
   lsp.efm.setup{
     on_attach = on_attach;
     init_options = {documentFormatting = true};
     root_dir = lsputil.root_pattern('.git', '.hg');
     settings = {
       rootMarkers = {".git/", ".hg/"},
-      languages = {
-        python = {
-          {
-            formatCommand = "black -",
-            formatStdin = true
-          },
-          {
-            lintCommand = "flake8 --stdin-display-name ${INPUT} -",
-            lintStdin = true,
-            lintIgnoreExitCode = true,
-            lintFormats = {"%f:%l:%c: %m"}
-          }
-        }
-      }
+      languages = languages
     };
   }
 end