wojciech-kulik / xcodebuild.nvim

Neovim plugin to Build, Debug, and Test applications created for Apple devices (iOS, macOS, watchOS, etc.)
MIT License
707 stars 18 forks source link

Unable to launch app #68

Closed milo-the-dev closed 8 months ago

milo-the-dev commented 8 months ago

Recently I've redone my configuration to clean it up and add support for other languages that I'm working in and upon switching back to iOS I'm unable to run any projects, not even test project. It was working before and when I try your ios-dev-starter-nvim config I can run the projects fine.

The LSP is working fine and I'm able to run all the Xcodebuild commands so it seems to be wired up properly but when I run tests I get this error and my tests don't run although it installs the app to the simulator and the Test explorer shows image When I try to run the app itself the build succeeds but it never launches the application in the booted simulator and I get this from xcode.lua image

It seems all other aspects are working including my integration with other plugins but xcodebuild.nvim is not right and I cannot seem to find the issue. Again I'm able to run these projects as expected if I use the ios-dev-starter-nvim config so I don't think it's any thing wrong with the project setup.

checkhealth: image

running xcrun simctl launch passing the bundle id and destination found in the project's settings.json launches the application just fine.

Here's my xcodebuild.nvim setup

return {
    "wojciech-kulik/xcodebuild.nvim",
    dependencies = {
        "j-hui/fidget.nvim",
        "MunifTanjim/nui.nvim",
        "nvim-telescope/telescope.nvim",
    },
    config = function()
        local progress_handle
        local utils = require("config.utils")

        require("xcodebuild").setup({
            show_build_progress_bar = false,
            logs = {
                auto_open_on_success_tests = false,
                auto_open_on_failed_tests = false,
                auto_open_on_success_build = false,
                auto_open_on_failed_build = false,
                auto_focus = false,
                auto_close_on_app_launch = true,
                only_summary = true,
                notify = function(message, severity)
                    local fidget = require("fidget")
                    if progress_handle then
                        progress_handle.message = message
                        if not message:find("Loading") then
                            progress_handle:finish()
                            progress_handle = nil
                            if vim.trim(message) ~= "" then
                                fidget.notify(message, severity)
                            end
                        end
                    else
                        fidget.notify(message, severity)
                    end
                end,
                notify_progress = function(message)
                    local progress = require("fidget.progress")

                    if progress_handle then
                        progress_handle.title = ""
                        progress_handle.message = message
                    else
                        progress_handle = progress.handle.create({
                            message = message,
                            lsp_client = { name = "xcodebuild.nvim" },
                        })
                    end
                end,
            },
            marks = {
                success_sign = utils.diagnostic_signs.success,
                failure_sign = utils.diagnostic_signs.error,
            },
            test_explorer = {
                auto_focus = false,
                success_sign = utils.common_icons.success,
                failure_sign = utils.common_icons.error,
            },
        })

        vim.keymap.set("n", "<leader>X", "<cmd>XcodebuildPicker<CR>", { desc = "Show Xcodebuild Actions" })
        vim.keymap.set("n", "<leader>xl", "<cmd>XcodebuildToggleLogs<CR>", { desc = "Toggle Xcodebuild Logs" })

        vim.keymap.set("n", "<leader>xb", "<cmd>XcodebuildBuild<CR>", { desc = "Build Project" })
        vim.keymap.set("n", "<leader>xr", "<cmd>XcodebuildBuildRun<CR>", { desc = "Build & Run Project" })

        vim.keymap.set("n", "<leader>xe", "<cmd>XcodebuildTestExplorerToggle<CR>", { desc = "Toggle Test Explorer" })
        vim.keymap.set("n", "<leader>xt", "<cmd>XcodebuildTest<CR>", { desc = "Run Tests" })
        vim.keymap.set("v", "<leader>xt", "<cmd>XcodebuildTestSelected<CR>", { desc = "Run Selected Tests" })
        vim.keymap.set("n", "<leader>xT", "<cmd>XcodebuildTestClass<CR>", { desc = "Run This Test Class" })

        vim.keymap.set("n", "<leader>xq", "<cmd>Telescope quickfix<CR>", { desc = "Show QuickFix List" })
    end,
}
wojciech-kulik commented 8 months ago

Hi! Can you paste the stacktrace you see in Neovim? Call :message to see the whole output.

milo-the-dev commented 8 months ago

@wojciech-kulik I've been looking for a way to print that message all morning. Went as far as modifying the code in xcodebuild to send a notification to fidget when the function to install simulator is called smh

here's what I get for the build and run command:

image

wojciech-kulik commented 8 months ago

Looks like the problem is caused by an outdated nvim-dap-ui plugin. Probably:

:lua print(vim.inspect(require("dapui").elements.console))

will fail in your case.

Please try updating plugins using lazy.

milo-the-dev commented 8 months ago

Running lua print(vim.inspect(require("dapui").elements.console)) gives me back nil

My current vim-dap-ui is up to date image

Here's the output I get for tests: image

wojciech-kulik commented 8 months ago

Running lua print(vim.inspect(require("dapui").elements.console)) gives me back nil

It shouldn't print nil, I believe. Can you check with nvim-dap-ui configuration from ios-dev-starter?

wojciech-kulik commented 8 months ago

Just to confirm, are you using Neovim 0.9.5?

milo-the-dev commented 8 months ago

Just to confirm, are you using Neovim 0.9.5?

image

I'll redo my nvim-dap-ui configuration and report back. I was so certain it was the xcodebuild configuration.

wojciech-kulik commented 8 months ago

Maybe there are more problems, but let's first focus on the obvious one :). The code fails because it is trying to access:

require("dapui").elements.console

but

require("dapui").elements

returns nil for some reason when you are trying to launch the app.

Maybe you configured nvim-dap-ui to be lazy? And it's not loaded properly for some reason?

milo-the-dev commented 8 months ago

Fixed!

Maybe you configured nvim-dap-ui to be lazy? And it's not loaded properly for some reason?

Unfortunately it was simpler than that, I never properly called setup on nvim-dap-ui 🤦🏿‍♂️ At least it wasn't a total lost of time, I now know of the :message command.

Thank you so much for the help!

wojciech-kulik commented 8 months ago

Great to hear! I'm glad you fixed the problem!

milo-the-dev commented 8 months ago

@wojciech-kulik might've closed prematurely. Building and running working but my tests are still being skipped and I'm getting this stacktrace

image

should I reopen or create another ticket?

wojciech-kulik commented 8 months ago

Could you:

  1. Run tests from Xcode

  2. Go to reports (last tab)

  3. Click on "Logs":

    image
  4. Export logs:

    image
  5. Find a line that looks like Test Case XYZ started and show me here.

It looks like the plugin is unable to extract class name from this line

milo-the-dev commented 8 months ago
Connection has no local endpoint
Test Suite 'All tests' started at 2024-03-05 16:04:07.363.
Test Suite 'UnitTests.xctest' started at 2024-03-05 16:04:07.363.
Test Suite 'AdditionalInfoToDiscountsRXTests' started at 2024-03-05 16:04:07.363.
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testGoodRxPharmacyId]' started.
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testGoodRxPharmacyId]' passed (0.004 seconds).
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testInvalidId]' started.
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testInvalidId]' passed (0.000 seconds).
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testNilGoodPharmacyId]' started.
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testNilGoodPharmacyId]' passed (0.000 seconds).
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testValidId]' started.
Test Case '-[UnitTests.AdditionalInfoToDiscountsRXTests testValidId]' passed (0.000 seconds).
…
wojciech-kulik commented 8 months ago

The lines you provided are parsed correctly. Probably some other line from logs is causing this problem.

Could you do one test for me?

  1. Open neovim in a folder where your logs are.
  2. Create a new file test.lua:
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)

for _, line in ipairs(lines) do
  if string.find(line, "^Test Case.*started%.") then
    local target, testClass, testName = string.match(line, "^Test Case .*.%-%[([%w_]+)%.([%w_]+) (%g+)%]")

    if not testClass then
      print("BUG: " .. line)
    else
      -- print("Target: " .. target, "Class: " .. testClass, "Test: " .. testName)
    end
  end
end
  1. Open your logs and run :so test.lua

It should print the line which is causing problem.

milo-the-dev commented 8 months ago

The logs located under the {project_root}/.nvim/xcodebuild/?

wojciech-kulik commented 8 months ago

yes original_logs.log file

milo-the-dev commented 8 months ago

I might be misunderstanding, no luck trying to source the file I created, get an error cannot find file.

image

Despite the message about test cases looks like the UT are in fact running correctly.

image

wojciech-kulik commented 8 months ago

:so file is relative to your working directory (you can check it by calling :pwd). So it depends on where you opened your nvim and where you created the file. So it's a matter of pointing to the right file. If you are having problems with your working directory, you can specify an absolute path.

So the issue with tests no longer occurs?

milo-the-dev commented 8 months ago

So the issue with tests no longer occurs?

Yeah I'm able to run and get the proper test results. Closing this issue as fixed. Thank you for your time!