Skip to content
Merged
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
66 changes: 45 additions & 21 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion lua/swift/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lua/swift/features/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 13 additions & 7 deletions lua/swift/features/project_detector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -166,7 +172,7 @@ function M.detect_project(force)
end
return #a.root > #b.root
end)

project_info = candidates[1]
end

Expand Down
6 changes: 5 additions & 1 deletion lua/swift/features/target_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""

Expand Down
5 changes: 3 additions & 2 deletions lua/swift/features/xcode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion lua/swift/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lua/swift/integrations/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function M.setup()
dap.adapters.lldb = {
type = "executable",
command = command,
name = "lldb"
name = "lldb",
}
end

Expand All @@ -35,20 +35,20 @@ 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
if vim.fn.executable(path) == 1 then
return path
end
end

return vim.fn.input("Path to executable: ", vim.fn.getcwd() .. "/", "file")
end,
cwd = "${workspaceFolder}",
stopOnEntry = false,
}
},
}
end
end
Expand Down
86 changes: 45 additions & 41 deletions lua/swift/integrations/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions tests/swift/project_detector_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading