diff options
author | crupest <crupest@outlook.com> | 2023-10-30 22:29:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-10-30 22:29:25 +0800 |
commit | 78c906b053d233e19d0b4ba005ab6836c7bb84b3 (patch) | |
tree | 34f2ee14454041de0d8289e622f6a99791db80df /configs/nvim/lua | |
parent | 376f33a464c5b4d3dfd48c36a48443126c004f82 (diff) | |
download | crupest-78c906b053d233e19d0b4ba005ab6836c7bb84b3.tar.gz crupest-78c906b053d233e19d0b4ba005ab6836c7bb84b3.tar.bz2 crupest-78c906b053d233e19d0b4ba005ab6836c7bb84b3.zip |
Update nvim config, more detect for omnisharp.
Diffstat (limited to 'configs/nvim/lua')
-rw-r--r-- | configs/nvim/lua/crupest/nvim/lsp/csharp.lua | 17 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/system.lua | 4 | ||||
-rw-r--r-- | configs/nvim/lua/crupest/system/find.lua | 21 |
3 files changed, 31 insertions, 11 deletions
diff --git a/configs/nvim/lua/crupest/nvim/lsp/csharp.lua b/configs/nvim/lua/crupest/nvim/lsp/csharp.lua index 413e41d..066f305 100644 --- a/configs/nvim/lua/crupest/nvim/lsp/csharp.lua +++ b/configs/nvim/lua/crupest/nvim/lsp/csharp.lua @@ -2,15 +2,24 @@ local lspconfig = require("lspconfig"); local capabilities = require("cmp_nvim_lsp").default_capabilities() local is_win = require("crupest.system").is_win +local is_mac = require("crupest.system").is_mac +local first_exe = require("crupest.system.find").first_exe + +local win_paths = { "C:/Users/crupest/Programs/omnisharp-win-x64/OmniSharp.exe" } +local mac_paths = { "/usr/local/opt/omnisharp/OmniSharp" } local function setup_lsp_csharp() - local omnisharp_cmd = nil + local paths = {} if is_win then - omnisharp_cmd = { "C:/Users/crupest/Programs/omnisharp-win-x64/OmniSharp.exe" } + paths = win_paths + elseif is_mac then + paths = mac_paths end - if omnisharp_cmd then + local omnisharp_path = first_exe(paths) + + if omnisharp_path then lspconfig.omnisharp.setup { capabilities = capabilities, @@ -18,7 +27,7 @@ local function setup_lsp_csharp() ["textDocument/definition"] = require('omnisharp_extended').handler, }, - cmd = omnisharp_cmd, + cmd = { omnisharp_path }, -- Enables support for reading code style, naming convention and analyzer -- settings from .editorconfig. diff --git a/configs/nvim/lua/crupest/system.lua b/configs/nvim/lua/crupest/system.lua index f05b230..982aaa4 100644 --- a/configs/nvim/lua/crupest/system.lua +++ b/configs/nvim/lua/crupest/system.lua @@ -1,5 +1,7 @@ local is_win = vim.fn.has("win32") ~= 0 +local is_mac = vim.fn.has("mac") ~= 0 return { - is_win = is_win + is_win = is_win, + is_mac = is_mac } diff --git a/configs/nvim/lua/crupest/system/find.lua b/configs/nvim/lua/crupest/system/find.lua index 16237ec..a2631a6 100644 --- a/configs/nvim/lua/crupest/system/find.lua +++ b/configs/nvim/lua/crupest/system/find.lua @@ -5,12 +5,12 @@ local function get_exe(path) if system.is_win then local exts = { "exe", "CMD", "cmd", "ps1" } for _, ext in ipairs(exts) do - if string.find(path, "%."..ext.."$") and fs.isfile(path) then + if string.find(path, "%." .. ext .. "$") and fs.isfile(path) then return path end end for _, ext in ipairs(exts) do - local p = path.."."..ext + local p = path .. "." .. ext if fs.isfile(p) then return p end end return nil @@ -23,9 +23,18 @@ local function get_exe(path) return nil end +local function first_exe(paths) + for _, v in ipairs(paths) do + local exe = get_exe(v) + if exe then return exe end + end + + return nil +end + local function find_node_modules(path) - return fs.walk_up(path, function (current_path) - local node_modules_path = current_path.."/node_modules" + return fs.walk_up(path, function(current_path) + local node_modules_path = current_path .. "/node_modules" if fs.isdir(node_modules_path) then return node_modules_path end @@ -36,7 +45,7 @@ end local function find_npm_exe(path, exe) local node_modules_path = find_node_modules(path) if not node_modules_path then return nil end - local try_exe_path = node_modules_path.."/.bin/"..exe + local try_exe_path = node_modules_path .. "/.bin/" .. exe local exe_path = get_exe(try_exe_path) if exe_path then return exe_path end return nil @@ -44,7 +53,7 @@ end return { get_exe = get_exe, + first_exe = first_exe, find_node_modules = find_node_modules, find_npm_exe = find_npm_exe, } - |