Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Tauri app forecd recompile when opening or editing C++ files #1572

Open
5 tasks done
Dosx001 opened this issue May 21, 2023 · 3 comments
Open
5 tasks done

Tauri app forecd recompile when opening or editing C++ files #1572

Dosx001 opened this issue May 21, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Dosx001
Copy link

Dosx001 commented May 21, 2023

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Issues

  • I have checked existing issues and there are no issues with the same problem.

Neovim Version

v0.9.0

Dev Version?

  • I am using a stable Neovim release version, or if I am using a dev version of Neovim I have confirmed that my issue is reproducible on a stable version.

Operating System

Arch Linux

Minimal Config

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
    local path_sep = on_windows and "\\" or "/"
    local result = table.concat({ ... }, path_sep)
    return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local null_ls_config = function()
    local null_ls = require("null-ls")
    -- add only what you need to reproduce your issue
    null_ls.setup({
        sources = {
            null_ls.builtins.diagnostics.cppcheck,
        },
        debug = true,
    })
end

local function load_plugins()
    -- only add other plugins if they are necessary to reproduce the issue
    require("packer").startup({
        {
            "wbthomason/packer.nvim",
            {
                "jose-elias-alvarez/null-ls.nvim",
                requires = { "nvim-lua/plenary.nvim" },
                config = null_ls_config,
            },
        },
        config = {
            package_root = package_root,
            compile_path = compile_path,
        },
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
    load_plugins()
    require("packer").sync()
else
    load_plugins()
    require("packer").sync()
end

Steps to Reproduce

# On Arch Linux
pacman -S webkit2gtk pnpm
git clone https://github.com/dosx001/suit
cd suit
pnpm i
pnpm tauri dev
cd suit/src-tauri/clib
nvim --clean -u YOUR/PATH/minimal_init.lua TestExec.cpp

Reproducibility Check

  • I confirm that my minimal config is based on the minimal_init.lua template and that my issue is reproducible by running nvim --clean -u minimal_init.lua and following the steps above.

Expected Behavior

When I save a C++ file my Tauri app recompiles.

Actual Behavior

When I open, edit, or save a C++ file my Tauri app recompiles.

Debug Log

[TRACE Sun 21 May 2023 03:08:33 PM PDT] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:102: received LSP request for method shutdown
[TRACE Sun 21 May 2023 03:08:33 PM PDT] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method exit
[TRACE Sun 21 May 2023 03:08:34 PM PDT] ...te/pack/packer/start/null-ls.nvim/lua/null-ls/client.lua:97: starting null-ls client
[TRACE Sun 21 May 2023 03:08:34 PM PDT] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:102: received LSP request for method initialize
[DEBUG Sun 21 May 2023 03:08:34 PM PDT] ...te/pack/packer/start/null-ls.nvim/lua/null-ls/client.lua:152: unable to notify client for method textDocument/didOpen (client not active): {
textDocument = {
uri = "file:///home/dosx/repos/gui/suit/src-tauri/clib/TestExec.cpp"
}
}
[TRACE Sun 21 May 2023 03:08:34 PM PDT] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method initialized
[TRACE Sun 21 May 2023 03:08:34 PM PDT] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method textDocument/didOpen
[TRACE Sun 21 May 2023 03:08:34 PM PDT] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_OPEN
[DEBUG Sun 21 May 2023 03:08:34 PM PDT] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:320: spawning command "cppcheck" at /home/dosx/repos/gui/suit with args { "--enable=warning,style,performance,portability", "--template=gcc", "/home/dosx/repos/gui/suit/src-tauri/clib/.null-ls_814785_TestExec.cpp" }
[TRACE Sun 21 May 2023 03:08:34 PM PDT] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:204: error output: Checking /home/dosx/repos/gui/suit/src-tauri/clib/.null-ls_814785_TestExec.cpp ...

[TRACE Sun 21 May 2023 03:08:34 PM PDT] ...t/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:205: output: nil
[TRACE Sun 21 May 2023 03:08:34 PM PDT] ...ck/packer/start/null-ls.nvim/lua/null-ls/diagnostics.lua:181: received diagnostics from source 1
[TRACE Sun 21 May 2023 03:08:34 PM PDT] ...ck/packer/start/null-ls.nvim/lua/null-ls/diagnostics.lua:182: {}

Help

Yes

Implementation Help

Background

Tauri is a framework for building cross-platform applications. Backend is written
in Rust and frontend is written in web technologies like JavaScript frameworks.
When running your Tauri app in dev mode, your app will recompile on any saved
changes on the backend.

My Usage Case

In my Tauri app backend, I'm using Rust C++ bindings to run C++ code I've written.

Debugging

I wasn't seeing the same behavior with CMake and CMake_lint.

I also tested with a random python file and PyLint, same behavior as CMake.

I tried switching between CppCheck with CppLint, end up seeing the same behavior CppCheck.

I tried changing CppCheck's method to methods.internal.DIAGNOSTICS_ON_SAVE, no luck.

Finding the Bug

diagnostic.lua
M.handler

-- line 171
require("null-ls.generators").run_registered

generator.lua
M.run_registered

-- line 156
M.run(generators, params, { postprocess = postprocess, after_each = after_each }, callback)

generator.lua
M.run

-- lines 65-67
local to_run = generator.async and a.wrap(generator.fn, 2) or generator.fn
local protected_call = generator.async and a.util.apcall or pcall
local ok, results = protected_call(to_run, copied_params)

Requirements

  • I have read and followed the instructions above and understand that my issue will be closed if I did not provide the required information.
@Dosx001 Dosx001 added the bug Something isn't working label May 21, 2023
@Dosx001
Copy link
Author

Dosx001 commented May 21, 2023

I found a solution by creating a .taurignore and adding the following.

.null-ls_*.cpp
.null-ls_*.hpp

I am leaving this issue open because maybe we can add visibility to this issue like adding this to the wiki for any future developers.

@jose-elias-alvarez
Copy link
Owner

It sounds like the compiler is reacting to the creation of temp files in the project. You could also try overriding the temp file directory for the source.

@Dosx001
Copy link
Author

Dosx001 commented May 29, 2023

@jose-elias-alvarez that's a better solution since C/C++ has so many different file extensions and now I don't need to create a .taurignore per project. Thxs!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants