Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Remove dependency on [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions lua/roslyn/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local util = require("lspconfig.util")
local util = require("roslyn.util")

local function set_selected_target(bufnr, target)
vim.g["RoslynSelectedTarget" .. bufnr] = target
Expand All @@ -15,34 +15,22 @@ local function find_possible_targets(fname)
local prefered_target = nil
local targets = {}

local sln_dir = util.root_pattern("*sln")(fname)
if sln_dir then
vim.list_extend(targets, vim.fn.glob(util.path.join(sln_dir, "*.sln"), true, true))
for dir in vim.fn.parents(fname) do
for _, sln in ipairs(vim.fn.glob(vim.fs.joinpath(dir, "*.sln"), true, true)) do
local sln_stat = vim.uv.fs_stat(sln)
if sln_stat and sln_stat.type == "file" then
table.insert(targets, sln)
end
end
if #targets > 0 then
break
end
end

if #targets == 1 then
prefered_target = targets[1]
end

-- local csproj_dir = util.root_pattern("*csproj")(fname)
-- if csproj_dir then
-- table.insert(targets, csproj_dir)
-- end
--
-- local git_dir = util.root_pattern(".git")(fname)
-- if git_dir and not vim.tbl_contains(targets, git_dir) then
-- table.insert(targets, git_dir)
-- end
--
-- local cwd = vim.fn.getcwd()
-- if util.path.is_descendant(cwd, fname) and not vim.tbl_contains(targets, cwd) then
-- table.insert(targets, cwd)
-- end
--
-- if #targets == 1 then
-- prefered_target = targets[1]
-- end

return targets, prefered_target
end

Expand All @@ -59,7 +47,7 @@ M.targets_by_bufnr = {} ---@type table<number, string[]>

function M.init_buf_targets(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
if vim.api.nvim_buf_get_option(bufnr, "buftype") == "nofile" then
if vim.api.nvim_get_option_value("buftype", { buf = bufnr }) == "nofile" then
return
end

Expand All @@ -72,7 +60,7 @@ function M.init_buf_targets(bufnr)
return
end

local bufpath = util.path.sanitize(bufname)
local bufpath = util.sanitize(bufname)
local targets, prefered_target = find_possible_targets(bufpath)
if prefered_target then
set_selected_target(bufnr, prefered_target)
Expand Down
23 changes: 23 additions & 0 deletions lua/roslyn/util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local M = {}

function M.bufname_valid(bufname)
if
bufname:match("^/")
or bufname:match("^[a-zA-Z]:")
or bufname:match("^zipfile://")
or bufname:match("^tarfile:")
then
return true
end
return false
end

function M.sanitize(path)
if is_windows then
path = path:sub(1, 1):upper() .. path:sub(2)
path = path:gsub('\\', '/')
end
return path
end

return M