Skip to content

Commit

Permalink
Merge branch 'main' into getting_started
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavEikaas authored Jan 2, 2025
2 parents 182633a + b0a1fa6 commit af2583f
Show file tree
Hide file tree
Showing 27 changed files with 216 additions and 120 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Formatting check

on:
pull_request:

jobs:

lint:
name: lint
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --check .
version: latest
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ As a developer transitioning from Rider to Neovim, I found myself missing the si

## Features

- Solution, csproj and fsproj support: Whether its a single project or a solution containing multiple projects easy-dotnet has you covered.
- Solution, slnx, csproj and fsproj support: Whether its a single project or a solution containing multiple projects easy-dotnet has you covered.
- Action Commands: Execute common tasks like building, running, testing, cleaning and restoring with ease.
- User Secrets Management: Edit, create, and preview .NET user secrets directly within Neovim.
- Debugging Helpers: While easy-dotnet.nvim doesn't set up DAP (Debugger Adapter Protocol) for you, it provides useful helper functions for debugging. These include resolving the DLL you are debugging and rebuilding before launching DAP, ensuring a smooth debugging experience.
Expand Down
16 changes: 9 additions & 7 deletions lua/easy-dotnet/actions/build.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local M = {
pending = false,
}

local logger = require("easy-dotnet.logger")
local picker = require("easy-dotnet.picker")
local parsers = require("easy-dotnet.parsers")
local messages = require("easy-dotnet.error-messages")
Expand All @@ -17,7 +19,7 @@ local function select_project(solution_file_path, cb, use_default)
local projects = sln_parse.get_projects_from_sln(solution_file_path)

if #projects == 0 then
vim.notify(error_messages.no_projects_found)
logger.error(error_messages.no_projects_found)
return
end
local choices = {
Expand All @@ -37,7 +39,7 @@ end
local function csproj_fallback(term)
local csproj_path = csproj_parse.find_project_file()
if csproj_path == nil then
vim.notify(error_messages.no_project_definition_found)
logger.error(error_messages.no_project_definition_found)
return
end
picker.picker(nil, { { name = csproj_path, display = csproj_path, path = csproj_path } }, function(i) term(i.path, "build", "") end, "Build project(s)")
Expand Down Expand Up @@ -101,7 +103,7 @@ M.build_project_quickfix = function(use_default, dotnet_args)
dotnet_args = dotnet_args or ""

if M.pending == true then
vim.notify("Build already pending...", vim.log.levels.ERROR)
logger.error("Build already pending...")
return
end
local data_dir = require("easy-dotnet.constants").get_data_directory()
Expand All @@ -111,7 +113,7 @@ M.build_project_quickfix = function(use_default, dotnet_args)
if solutionFilePath == nil then
local csproj = csproj_parse.find_project_file()
if csproj == nil then
vim.notify(messages.no_project_definition_found)
logger.error(messages.no_project_definition_found)
return
end
local command = string.format("dotnet build %s /flp:v=q /flp:logfile=%s %s", csproj, logPath, dotnet_args or "")
Expand All @@ -120,9 +122,9 @@ M.build_project_quickfix = function(use_default, dotnet_args)
on_exit = function(_, b, _)
M.pending = false
if b == 0 then
vim.notify("Built successfully")
logger.info("Built successfully")
else
vim.notify("Build failed")
logger.info("Build failed")
populate_quickfix_from_file(logPath)
end
end,
Expand Down Expand Up @@ -157,7 +159,7 @@ M.build_solution = function(term, args)

local solutionFilePath = sln_parse.find_solution_file() or csproj_parse.find_project_file()
if solutionFilePath == nil then
vim.notify(error_messages.no_project_definition_found)
logger.error(error_messages.no_project_definition_found)
return
end
term(solutionFilePath, "build", args or "")
Expand Down
7 changes: 4 additions & 3 deletions lua/easy-dotnet/actions/clean.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local M = {}
local parsers = require("easy-dotnet.parsers")
local logger = require("easy-dotnet.logger")
local csproj_parse = parsers.csproj_parser
local sln_parse = parsers.sln_parser
local error_messages = require("easy-dotnet.error-messages")
Expand All @@ -8,7 +9,7 @@ M.clean_solution = function(args)
args = args or ""
local solutionFilePath = sln_parse.find_solution_file() or csproj_parse.find_project_file()
if solutionFilePath == nil then
vim.notify(error_messages.no_project_definition_found)
logger.error(error_messages.no_project_definition_found)
return
end

Expand All @@ -24,9 +25,9 @@ M.clean_solution = function(args)
end,
on_exit = function(_, code)
if code ~= 0 then
vim.notify("Command failed " .. command)
logger.error("Command failed " .. command)
else
vim.notify(solutionFilePath .. " cleaned")
logger.info(solutionFilePath .. " cleaned")
end
end,
})
Expand Down
62 changes: 33 additions & 29 deletions lua/easy-dotnet/actions/new.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local polyfills = require("easy-dotnet.polyfills")
local logger = require("easy-dotnet.logger")
local M = {}

local function sln_add_project(sln_path, project)
vim.fn.jobstart(string.format("dotnet sln %s add %s", sln_path, project), {
stdout_buffered = true,
on_exit = function(_, b)
if b ~= 0 then vim.notify("Failed to link project to solution") end
if b ~= 0 then logger.error("Failed to link project to solution") end
end,
})
end
Expand All @@ -15,8 +16,9 @@ local function get_dotnet_new_args(name)
local sln_path = sln_parse.find_solution_file()
if sln_path == nil then return nil end

local folder_path = sln_path:gsub("[\\/][^\\/]*%.sln$", "")
local project_name = sln_path:match("[^\\/]+%.sln$"):gsub("%.sln$", "") .. "." .. name
local folder_path = vim.fs.dirname(sln_path)
local solution_name = vim.fn.fnamemodify(sln_path, ":t:r")
local project_name = solution_name .. "." .. name
local output = polyfills.fs.joinpath(folder_path, project_name)
return {
sln_path = sln_path,
Expand All @@ -38,9 +40,9 @@ local function create_and_link_project(name, type)
stdout_buffered = true,
on_exit = function(_, code)
if code ~= 0 then
vim.notify("Failed to create project", vim.log.levels.ERROR)
logger.error("Failed to create project")
else
vim.notify("Project created")
logger.info("Project created")
if args.sln_path ~= nil then sln_add_project(args.sln_path, args.output) end
end
end,
Expand All @@ -51,21 +53,21 @@ local function create_config_file(type)
local sln_parse = require("easy-dotnet.parsers.sln-parse")
local sln_path = sln_parse.find_solution_file()

local folder_path = sln_path ~= nil and sln_path:gsub("[\\/][^\\/]*%.sln$", "") or nil
local folder_path = sln_path ~= nil and vim.fs.dirname(sln_path) or nil
local output_arg = folder_path ~= nil and string.format("-o %s", folder_path) or ""
vim.fn.jobstart(string.format("dotnet new %s %s", type, output_arg), {
stdout_buffered = true,
on_exit = function(_, code)
if code ~= 0 then
vim.notify("Command failed")
logger.error("Command failed")
else
vim.notify("Config file created")
logger.info("Config file created")
end
end,
})
end

local projects = {
local templates = {
{
display = "Solution file",
type = "config",
Expand All @@ -84,9 +86,9 @@ local projects = {
stdout_buffered = true,
on_exit = function(_, code)
if code ~= 0 then
vim.notify("Command failed")
logger.error("Command failed")
else
vim.notify(".gitignore file created")
logger.info(".gitignore file created")
end
end,
})
Expand Down Expand Up @@ -206,30 +208,31 @@ local projects = {

M.new = function()
local picker = require("easy-dotnet.picker")
picker.picker(nil, projects, function(i)
if i.type == "project" then
vim.cmd("startinsert")
vim.ui.input({ prompt = string.format("Enter name for %s", i.display) }, function(input)
if input == nil then
vim.notify("No name provided")
return
end
vim.cmd("stopinsert")
i.run(input)
end)
else
i.run()
end
end, "Select type")
local template = picker.pick_sync(nil, templates, "Select type")
if template.type == "project" then
vim.cmd("startinsert")
--TODO: telescope
vim.ui.input({ prompt = string.format("Enter name for %s", template.display) }, function(input)
if input == nil then
logger.error("No name provided")
return
end
vim.cmd("stopinsert")
coroutine.wrap(function() template.run(input) end)()
end)
else
template.run()
end
end

local function name_input_sync()
local name = ""
local co = coroutine.running()
vim.cmd("startinsert")
--TODO: telescope
vim.ui.input({ prompt = "Enter name" }, function(input)
if input == nil then
vim.notify("No name provided")
logger.error("No name provided")
return
end
vim.cmd("stopinsert")
Expand All @@ -246,6 +249,7 @@ M.create_new_item = function(path, cb)
path = path or "."
local template = require("easy-dotnet.picker").pick_sync(nil, {
{ value = "buildprops", display = "MSBuild Directory.Build.props File", type = "MSBuild/props" },
{ value = "packagesprops", display = "MSBuild Directory.Packages.props File", type = "MSBuild/props" },
{ value = "buildtargets", display = "MSBuild Directory.Build.targets File", type = "MSBuild/props" },
{ value = "apicontroller", display = "Api Controller", type = "Code" },
{ value = "interface", display = "Interface", type = "Code" },
Expand Down Expand Up @@ -286,13 +290,13 @@ M.create_new_item = function(path, cb)
vim.fn.jobstart(cmd, {
on_stderr = function(_, data)
for _, value in ipairs(data) do
vim.notify(value, vim.log.levels.ERROR)
logger.error(value)
end
end,
on_exit = function(_, code)
if code == 0 then
else
vim.notify("Command failed")
logger.error("Command failed")
end
if cb then cb() end
end,
Expand Down
3 changes: 2 additions & 1 deletion lua/easy-dotnet/actions/restore.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local M = {}
local parsers = require("easy-dotnet.parsers")
local logger = require("easy-dotnet.logger")
local csproj_parse = parsers.csproj_parser
local sln_parse = parsers.sln_parser
local error_messages = require("easy-dotnet.error-messages")
Expand All @@ -10,7 +11,7 @@ M.restore = function(term, args)
term = term or require("easy-dotnet.options").options.terminal
local project = sln_parse.find_solution_file() or csproj_parse.find_project_file()
if project == nil then
vim.notify(error_messages.no_project_definition_found)
logger.error(error_messages.no_project_definition_found)
return
end

Expand Down
13 changes: 7 additions & 6 deletions lua/easy-dotnet/actions/run.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local M = {}
local picker = require("easy-dotnet.picker")
local parsers = require("easy-dotnet.parsers")
local logger = require("easy-dotnet.logger")
local csproj_parse = parsers.csproj_parser
local sln_parse = parsers.sln_parser
local error_messages = require("easy-dotnet.error-messages")
Expand All @@ -13,7 +14,7 @@ local function pick_project(use_default)
local solution_file_path = sln_parse.find_solution_file()
if solution_file_path == nil then
local csproject_path = csproj_parse.find_project_file()
if not csproject_path then vim.notify(error_messages.no_runnable_projects_found) end
if not csproject_path then logger.error(error_messages.no_runnable_projects_found) end
local project = csproj_parse.get_project_from_project_file(csproject_path)
return project, nil
end
Expand All @@ -24,12 +25,12 @@ local function pick_project(use_default)
local projects = polyfills.tbl_filter(function(i) return i.runnable == true end, sln_parse.get_projects_from_sln(solution_file_path))

if #projects == 0 then
vim.notify(error_messages.no_runnable_projects_found)
logger.error(error_messages.no_runnable_projects_found)
return
end
local project = picker.pick_sync(nil, projects, "Run project")
if not project then
vim.notify("No project selected")
logger.error("No project selected")
return
end
default_manager.set_default_project(project, solution_file_path, "run")
Expand All @@ -40,7 +41,7 @@ end
local function csproj_fallback(term, args)
local csproj_path = csproj_parse.find_project_file()
if csproj_path == nil then
vim.notify(error_messages.no_project_definition_found)
logger.error(error_messages.no_project_definition_found)
return
end
picker.picker(nil, { { name = csproj_path, display = csproj_path, path = csproj_path } }, function(i) term(i.path, "run", args) end, "Run project")
Expand Down Expand Up @@ -69,7 +70,7 @@ M.run_project_picker = function(term, use_default, args)
local projects = polyfills.tbl_filter(function(i) return i.runnable == true end, sln_parse.get_projects_from_sln(solution_file_path))

if #projects == 0 then
vim.notify(error_messages.no_runnable_projects_found)
logger.error(error_messages.no_runnable_projects_found)
return
end
picker.picker(nil, projects, function(i)
Expand All @@ -84,7 +85,7 @@ local function pick_profile(project)
--In case of OUT OF MEM, this would be another way: cat launchSettings.json | jq '.profiles | to_entries[] | select(.value.commandName == \"Project\") | .key'
local success, content = pcall(function() return table.concat(vim.fn.readfile(path), "\n") end)
if not success then
vim.notify("No launchSettings file found", vim.log.levels.DEBUG)
logger.trace("No launchSettings file found")
return nil
end

Expand Down
7 changes: 4 additions & 3 deletions lua/easy-dotnet/actions/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ local M = {}
local picker = require("easy-dotnet.picker")
local error_messages = require("easy-dotnet.error-messages")
local parsers = require("easy-dotnet.parsers")
local logger = require("easy-dotnet.logger")
local csproj_parse = parsers.csproj_parser
local sln_parse = parsers.sln_parser
local polyfills = require("easy-dotnet.polyfills")

local function csproj_fallback(on_select)
local csproj_path = csproj_parse.find_project_file()
if csproj_path == nil then vim.notify("No .sln file or .csproj file found") end
if csproj_path == nil then logger.error("No .sln file or .csproj file found") end
picker.picker(nil, { { name = csproj_path, display = csproj_path, path = csproj_path } }, function(i) on_select(i.path, "test") end, "Run test")
end

Expand All @@ -20,7 +21,7 @@ local function select_project(solution_file_path, cb, use_default)
local projects = polyfills.tbl_filter(function(i) return i.isTestProject == true end, sln_parse.get_projects_from_sln(solution_file_path))

if #projects == 0 then
vim.notify(error_messages.no_test_projects_found)
logger.error(error_messages.no_test_projects_found)
return
end

Expand Down Expand Up @@ -59,7 +60,7 @@ M.test_solution = function(term, args)
args = args or ""
local solutionFilePath = sln_parse.find_solution_file() or csproj_parse.find_project_file()
if solutionFilePath == nil then
vim.notify(error_messages.no_project_definition_found)
logger.error(error_messages.no_project_definition_found)
return
end
term(solutionFilePath, "test", args or "")
Expand Down
4 changes: 3 additions & 1 deletion lua/easy-dotnet/commands.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local logger = require("easy-dotnet.logger")
---@type table<string,Command>
local M = {}

Expand Down Expand Up @@ -194,8 +195,9 @@ M.new = {
M.reset = {
handle = function()
local dir = require("easy-dotnet.constants").get_data_directory()
--TODO: error handling?
require("plenary.path"):new(dir):rm({ recursive = true })
vim.notify("Cached files deleted")
logger.info("Cached files deleted")
end,
}

Expand Down
Loading

0 comments on commit af2583f

Please sign in to comment.