From 22151dfa9648401faf1961aa8f0bb21430665bfa Mon Sep 17 00:00:00 2001
From: rockerBOO <rockerboo@gmail.com>
Date: Thu, 7 Jan 2021 02:09:57 -0500
Subject: [PATCH 1/4] Add better support and docs for cmd

---
 README.md             |  3 +++
 lua/nlua/lsp/nvim.lua | 50 +++++++++++++++++++++++--------------------
 2 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/README.md b/README.md
index 6576abf..73f6923 100644
--- a/README.md
+++ b/README.md
@@ -48,6 +48,9 @@ require('nlua.lsp.nvim').setup(require('lspconfig'), {
     -- Colorbuddy
     "Color", "c", "Group", "g", "s",
   }
+
+  -- Optional command to run the sumneko lua language server
+	-- cmd = {"lua-language-server", "-E", "~/build/lua-language-server/main.lua"}
 })
 
 ```
diff --git a/lua/nlua/lsp/nvim.lua b/lua/nlua/lsp/nvim.lua
index 0925c7d..7403751 100644
--- a/lua/nlua/lsp/nvim.lua
+++ b/lua/nlua/lsp/nvim.lua
@@ -1,5 +1,15 @@
 local cache_location = vim.fn.stdpath('cache')
-local bin_folder = jit.os
+
+local system_name
+if vim.fn.has("mac") == 1 then
+  system_name = "macOS"
+elseif vim.fn.has("unix") == 1 then
+  system_name = "Linux"
+elseif vim.fn.has('win32') == 1 then
+  system_name = "Windows"
+else
+  print("Unsupported system for nlua.nvim/sumneko")
+end
 
 local nlua_nvim_lsp = {
   base_directory = string.format(
@@ -10,7 +20,7 @@ local nlua_nvim_lsp = {
   bin_location = string.format(
     "%s/nlua/sumneko_lua/lua-language-server/bin/%s/lua-language-server",
     cache_location,
-    bin_folder
+    system_name
   ),
 }
 
@@ -26,22 +36,21 @@ local sumneko_command = function()
 end
 
 local function get_lua_runtime()
-    local result = {};
-    for _, path in pairs(vim.api.nvim_list_runtime_paths()) do
-        local lua_path = path .. "/lua/";
-        if vim.fn.isdirectory(lua_path) then
-            result[lua_path] = true
-        end
-    end
-
-    -- This loads the `lua` files from nvim into the runtime.
-    result[vim.fn.expand("$VIMRUNTIME/lua")] = true
-
-    -- TODO: Figure out how to get these to work...
-    --  Maybe we need to ship these instead of putting them in `src`?...
-    result[vim.fn.expand("~/build/neovim/src/nvim/lua")] = true
-
-    return result;
+  local result = {};
+  for _, path in pairs(vim.api.nvim_list_runtime_paths()) do
+      local lua_path = path .. "/lua/";
+      if vim.fn.isdirectory(lua_path) then
+          result[lua_path] = true
+      end
+  end
+
+  -- This loads the `lua` files from nvim into the runtime.
+  result[vim.fn.expand("$VIMRUNTIME/lua")] = true
+
+  -- This loads the `lsp` files into the runtime
+  result[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true
+
+  return result;
 end
 
 nlua_nvim_lsp.setup = function(nvim_lsp, config)
@@ -53,11 +62,6 @@ nlua_nvim_lsp.setup = function(nvim_lsp, config)
     return
   end
 
-  if vim.fn.filereadable(cmd[3]) == 0 then
-    print("Could not find resulting build files", cmd[3])
-    return
-  end
-
   nvim_lsp.sumneko_lua.setup({
     cmd = cmd,
 

From 039001ab56a7f142320bb2c3c7a999f69c2d94fb Mon Sep 17 00:00:00 2001
From: rockerBOO <rockerboo@gmail.com>
Date: Thu, 7 Jan 2021 02:15:37 -0500
Subject: [PATCH 2/4] Formatting

---
 README.md             | 2 +-
 lua/nlua/lsp/nvim.lua | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md
index 73f6923..551fde0 100644
--- a/README.md
+++ b/README.md
@@ -50,7 +50,7 @@ require('nlua.lsp.nvim').setup(require('lspconfig'), {
   }
 
   -- Optional command to run the sumneko lua language server
-	-- cmd = {"lua-language-server", "-E", "~/build/lua-language-server/main.lua"}
+  -- cmd = {"lua-language-server", "-E", "~/build/lua-language-server/main.lua"}
 })
 
 ```
diff --git a/lua/nlua/lsp/nvim.lua b/lua/nlua/lsp/nvim.lua
index 7403751..fe62fc6 100644
--- a/lua/nlua/lsp/nvim.lua
+++ b/lua/nlua/lsp/nvim.lua
@@ -38,10 +38,10 @@ end
 local function get_lua_runtime()
   local result = {};
   for _, path in pairs(vim.api.nvim_list_runtime_paths()) do
-      local lua_path = path .. "/lua/";
-      if vim.fn.isdirectory(lua_path) then
-          result[lua_path] = true
-      end
+    local lua_path = path .. "/lua/";
+    if vim.fn.isdirectory(lua_path) then
+      result[lua_path] = true
+    end
   end
 
   -- This loads the `lua` files from nvim into the runtime.

From 276ce9d3970e9e66137ff80e3e8be20a8a65c74f Mon Sep 17 00:00:00 2001
From: rockerBOO <rockerboo@gmail.com>
Date: Thu, 7 Jan 2021 02:21:34 -0500
Subject: [PATCH 3/4] Add back build file requirement

---
 lua/nlua/lsp/nvim.lua | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lua/nlua/lsp/nvim.lua b/lua/nlua/lsp/nvim.lua
index fe62fc6..d988f93 100644
--- a/lua/nlua/lsp/nvim.lua
+++ b/lua/nlua/lsp/nvim.lua
@@ -62,6 +62,11 @@ nlua_nvim_lsp.setup = function(nvim_lsp, config)
     return
   end
 
+  if vim.fn.filereadable(cmd[3]) == 0 then
+    print("Could not find resulting build files", cmd[3])
+    return
+  end
+
   nvim_lsp.sumneko_lua.setup({
     cmd = cmd,
 

From 8efefcf0c91c49afd2be3c182355dc862b413ae2 Mon Sep 17 00:00:00 2001
From: rockerBOO <rockerboo@gmail.com>
Date: Thu, 7 Jan 2021 13:07:34 -0500
Subject: [PATCH 4/4] Use full path

---
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 551fde0..f2e0490 100644
--- a/README.md
+++ b/README.md
@@ -50,7 +50,7 @@ require('nlua.lsp.nvim').setup(require('lspconfig'), {
   }
 
   -- Optional command to run the sumneko lua language server
-  -- cmd = {"lua-language-server", "-E", "~/build/lua-language-server/main.lua"}
+  -- cmd = {"lua-language-server", "-E", "/home/tjdevires/build/lua-language-server/main.lua"}
 })
 
 ```
