diff --git a/.github/labeler.yml b/.github/labeler.yml index b0c3635..be0c73e 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,45 +1,69 @@ # Labeler configuration for automatic PR labeling -# https://github.com/actions/labeler +# https://github.com/actions/labeler (v5 format) documentation: - - '**/*.md' - - 'docs/**/*' - - 'examples/**/*.md' + - changed-files: + - any-glob-to-any-file: + - '**/*.md' + - 'docs/**/*' + - 'examples/**/*.md' ci: - - '.github/workflows/**' - - '.github/**/*.yml' + - changed-files: + - any-glob-to-any-file: + - '.github/workflows/**' + - '.github/**/*.yml' core: - - 'lua/swift/init.lua' - - 'lua/swift/config.lua' - - 'plugin/**' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/init.lua' + - 'lua/swift/core/**' + - 'plugin/**' feature:lsp: - - 'lua/swift/features/lsp.lua' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/features/lsp.lua' feature:debugger: - - 'lua/swift/features/debugger.lua' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/features/debugger.lua' feature:formatter: - - 'lua/swift/features/formatter.lua' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/features/formatter.lua' feature:linter: - - 'lua/swift/features/linter.lua' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/features/linter.lua' feature:build: - - 'lua/swift/features/build_runner.lua' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/features/build_runner.lua' feature:xcode: - - 'lua/swift/features/xcode.lua' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/features/xcode.lua' feature:targets: - - 'lua/swift/features/target_manager.lua' + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/features/target_manager.lua' tests: - - 'tests/**' - - '**/*_spec.lua' + - changed-files: + - any-glob-to-any-file: + - 'tests/**' + - '**/*_spec.lua' -dependencies: - - 'package.json' - - '.github/workflows/**' +bug: + - changed-files: + - any-glob-to-any-file: + - 'lua/swift/health.lua' + - 'lua/swift/core/utils.lua' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41f1fc4..ac5e621 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,7 @@ jobs: with: use-quiet-mode: 'yes' use-verbose-mode: 'no' + github-token: ${{ secrets.GITHUB_TOKEN }} config-file: '.github/markdown-link-check.json' continue-on-error: true diff --git a/lua/swift/core/utils.lua b/lua/swift/core/utils.lua index 78411c9..3f5010d 100644 --- a/lua/swift/core/utils.lua +++ b/lua/swift/core/utils.lua @@ -39,7 +39,9 @@ function M.find_pattern_upwards(pattern, start_path) if handle then while true do local name, ftype = vim.uv.fs_scandir_next(handle) - if not name then break end + if not name then + break + end if (ftype == "directory" or ftype == "link") and name:sub(-#suffix) == suffix then table.insert(matches, path .. "/" .. name) end diff --git a/lua/swift/features/lsp.lua b/lua/swift/features/lsp.lua index fac0ec5..d347a96 100644 --- a/lua/swift/features/lsp.lua +++ b/lua/swift/features/lsp.lua @@ -38,7 +38,8 @@ function M.find_sourcekit_lsp() -- Try Xcode toolchain if vim.fn.has("mac") == 1 then - local xcrun_path = vim.system({ "xcrun", "--find", "sourcekit-lsp" }, { text = true, timeout = 3000 }):wait().stdout or "" + local xcrun_path = vim.system({ "xcrun", "--find", "sourcekit-lsp" }, { text = true, timeout = 3000 }):wait().stdout + or "" xcrun_path = xcrun_path:gsub("\n", "") if xcrun_path ~= "" and vim.fn.executable(xcrun_path) == 1 then table.insert(possible_paths, 1, xcrun_path) diff --git a/lua/swift/features/project_detector.lua b/lua/swift/features/project_detector.lua index 58b1c49..5a791f9 100644 --- a/lua/swift/features/project_detector.lua +++ b/lua/swift/features/project_detector.lua @@ -142,15 +142,21 @@ function M.detect_project(force) -- Gather all possible project types local candidates = {} - + local workspace_info = M.detect_xcode_workspace(start_path) - if workspace_info then table.insert(candidates, workspace_info) end - + if workspace_info then + table.insert(candidates, workspace_info) + end + local project_info_xcode = M.detect_xcode_project(start_path) - if project_info_xcode then table.insert(candidates, project_info_xcode) end - + if project_info_xcode then + table.insert(candidates, project_info_xcode) + end + local spm_info = M.detect_spm(start_path) - if spm_info then table.insert(candidates, spm_info) end + if spm_info then + table.insert(candidates, spm_info) + end if #candidates > 0 then -- Sort candidates by root path length descending (closer to start_path) @@ -166,7 +172,7 @@ function M.detect_project(force) end return #a.root > #b.root end) - + project_info = candidates[1] end diff --git a/lua/swift/features/target_manager.lua b/lua/swift/features/target_manager.lua index da26f71..960f7a8 100644 --- a/lua/swift/features/target_manager.lua +++ b/lua/swift/features/target_manager.lua @@ -140,7 +140,11 @@ function M.parse_xcode_targets() end -- Use xcodebuild to list schemes (which correspond to targets) - local sh_cmd = { "sh", "-c", string.format('cd "%s" && xcodebuild -list -json 2>/dev/null', vim.fn.fnamemodify(project_file, ":h")) } + local sh_cmd = { + "sh", + "-c", + string.format('cd "%s" && xcodebuild -list -json 2>/dev/null', vim.fn.fnamemodify(project_file, ":h")), + } local obj = vim.system(sh_cmd, { text = true, timeout = 5000 }):wait() local output = obj.stdout or "" diff --git a/lua/swift/features/xcode.lua b/lua/swift/features/xcode.lua index ec9d2c1..1c65aea 100644 --- a/lua/swift/features/xcode.lua +++ b/lua/swift/features/xcode.lua @@ -149,12 +149,13 @@ function M.list_schemes() end local sh_cmd = { - "sh", "-c", + "sh", + "-c", string.format( "xcodebuild -list -workspace %s 2>/dev/null || xcodebuild -list -project %s 2>/dev/null", vim.fn.shellescape(project_file), vim.fn.shellescape(project_file) - ) + ), } local obj = vim.system(sh_cmd, { text = true, timeout = 5000 }):wait() diff --git a/lua/swift/health.lua b/lua/swift/health.lua index b069bff..a5edf1b 100644 --- a/lua/swift/health.lua +++ b/lua/swift/health.lua @@ -71,7 +71,9 @@ function M.check() end end else - local version = vim.system({ "sh", "-c", "swift --version 2>&1 | head -n 1" }, { text = true, timeout = 5000 }):wait().stdout or "" + local version = vim + .system({ "sh", "-c", "swift --version 2>&1 | head -n 1" }, { text = true, timeout = 5000 }) + :wait().stdout or "" health.info("Version: " .. vim.trim(version)) end else diff --git a/lua/swift/integrations/dap.lua b/lua/swift/integrations/dap.lua index 76d5208..55a7a93 100644 --- a/lua/swift/integrations/dap.lua +++ b/lua/swift/integrations/dap.lua @@ -19,7 +19,7 @@ function M.setup() dap.adapters.lldb = { type = "executable", command = command, - name = "lldb" + name = "lldb", } end @@ -35,7 +35,7 @@ function M.setup() local current = target_manager.get_current_target() local detector = require("swift.features.project_detector") local info = detector.get_project_info() - + if current and info.root and info.type == "spm" then -- Guess the build path for SPM local path = info.root .. "/.build/debug/" .. current @@ -43,12 +43,12 @@ function M.setup() return path end end - + return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file") end, cwd = "${workspaceFolder}", stopOnEntry = false, - } + }, } end end diff --git a/lua/swift/integrations/telescope.lua b/lua/swift/integrations/telescope.lua index d50652c..2642b31 100644 --- a/lua/swift/integrations/telescope.lua +++ b/lua/swift/integrations/telescope.lua @@ -21,23 +21,25 @@ function M.xcode_schemes() return end - pickers.new({}, { - prompt_title = "Xcode Schemes", - finder = finders.new_table({ - results = schemes - }), - sorter = conf.generic_sorter({}), - attach_mappings = function(prompt_bufnr, map) - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - if selection then - xcode.build(selection[1]) - end - end) - return true - end, - }):find() + pickers + .new({}, { + prompt_title = "Xcode Schemes", + finder = finders.new_table({ + results = schemes, + }), + sorter = conf.generic_sorter({}), + attach_mappings = function(prompt_bufnr, map) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + if selection then + xcode.build(selection[1]) + end + end) + return true + end, + }) + :find() end -- Show a Telescope picker for Swift targets (SPM) @@ -71,30 +73,32 @@ function M.swift_targets() }) end - pickers.new({}, { - prompt_title = "Swift Targets", - finder = finders.new_table({ - results = display_items, - entry_maker = function(entry) - return { - value = entry.value, - display = entry.display, - ordinal = entry.ordinal, - } - end - }), - sorter = conf.generic_sorter({}), - attach_mappings = function(prompt_bufnr, map) - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - if selection then - target_manager.set_current_target(selection.value.name) - end - end) - return true - end, - }):find() + pickers + .new({}, { + prompt_title = "Swift Targets", + finder = finders.new_table({ + results = display_items, + entry_maker = function(entry) + return { + value = entry.value, + display = entry.display, + ordinal = entry.ordinal, + } + end, + }), + sorter = conf.generic_sorter({}), + attach_mappings = function(prompt_bufnr, map) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + if selection then + target_manager.set_current_target(selection.value.name) + end + end) + return true + end, + }) + :find() end return M diff --git a/tests/swift/project_detector_spec.lua b/tests/swift/project_detector_spec.lua index 8d2418a..065e954 100644 --- a/tests/swift/project_detector_spec.lua +++ b/tests/swift/project_detector_spec.lua @@ -8,15 +8,15 @@ describe("Project Detector", function() it("should return none when no project files are found", function() local temp_dir = vim.fn.tempname() vim.fn.mkdir(temp_dir, "p") - + local old_cwd = vim.fn.getcwd() vim.api.nvim_set_current_dir(temp_dir) - + -- Force refresh cache local info = detector.get_project_info(true) - + assert.are.same("none", info.type) - + vim.api.nvim_set_current_dir(old_cwd) vim.fn.delete(temp_dir, "rf") end)