Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Kill attached flutter processes on nvim exit #401

Open
p4-k4 opened this issue Oct 28, 2024 · 2 comments
Open

[Feature Request] Kill attached flutter processes on nvim exit #401

p4-k4 opened this issue Oct 28, 2024 · 2 comments

Comments

@p4-k4
Copy link

p4-k4 commented Oct 28, 2024

A simple and small but potentially resource saving feature, as it's sometimes easy to forget to quit flutter processes before exiting nvim.

Whenever exiting nvim, stop any current attached flutter processes.

@iDefyU
Copy link

iDefyU commented Nov 21, 2024

i have the same problem too.

@p4-k4
Copy link
Author

p4-k4 commented Nov 21, 2024

Haven't tested this, but could potentially do something like:

local function is_dart_project()
  -- Check for pubspec.yaml in the current directory or parent directories
  local function find_pubspec(path)
    if vim.fn.filereadable(path .. '/pubspec.yaml') == 1 then
      return true
    end
    
    local parent = vim.fn.fnamemodify(path, ':h')
    if parent == path then
      return false
    end
    
    return find_pubspec(parent)
  end

  return find_pubspec(vim.fn.getcwd())
end

-- Create an autocommand group
vim.api.nvim_create_augroup('FlutterAutoQuit', { clear = true })

-- Create the autocommand
vim.api.nvim_create_autocmd('VimLeavePre', {
  group = 'FlutterAutoQuit',
  callback = function()
    if is_dart_project() then
      vim.cmd('FlutterQuit')
    end
  end,
  desc = 'Automatically run FlutterQuit when exiting Neovim in a Dart project'
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants