Shows a telescope window with project and file specific actions
(like npm install
).
Supported project types:
cargo
npm
make
gradle
Supported file types:
lua
javascript
typescript
(only with bun)
Install with your favorite package manager. Requires telescope.
Lazy:
require "lazy" .setup {
{
"firanel/project_actions",
dependencies = {
"nvim-telescope/telescope.nvim",
},
lazy = true,
},
}
Use the default configuration (calling setup is optional) unless you want to extend the functionality.
Options object:
project_actions
: list of project actions to supportfile_actions
: list of file actions to support
Builtin actions are lazy loaded.
Set extends = true
to extend default options instead of overriding them.
The elements of the project_actions
array are either names of builtin
actions or objects of the form:
condition
: name of a file which must be present in the project root, list of files or a function which should return a found fileload
: function which returns a project action object or name of a module which exports said function. The function is called with 2 parameters:- The found value (returned from the condition)
- Telescope options
exclude_file_actions
(optional): list of filetypes1 for which to disable file actions
Project action object:
title
: title for telescope windowcmd
(optional): base command for entries withoutrun
specifiedvalues
: telescope entries as a list of entry objects
Entry object:
name
: Name of the entryrun
(optional): function to call, command as string or run prompt object, if none is given usesstring.format("%s %s", project.cmd, entry.name)
as command string
Run prompt object:
prompt
: Prompt textrun
(optional): see entry object run (without run prompt object)empty
(optional): boolean whether to allow empty argument
Set extends = true
to extend default options instead of overriding them.
Elements should be either names of builtin actions or a key value pair,
where the key is the filetype1 and the value is a function which returns
a list of entry objects (see project actions) or the name of a module
which exports said function.
To extend a builtin filetype you will need to merge it into your actions manually. For example:
function my_js_file_actions()
-- get defaults
local actions = require "project_actions.file_actions.javascript" ()
-- add new
table.insert(actions, {
name = "Node: run2",
run = function(buf)
vim.cmd(string.format(":!node '%s'", vim.api.nvim_buf_get_name(buf)))
end
})
return actions
end
Default file actions can be imported from
project_actions.file_actions.<filetype>
.
require "project_actions" .setup {
project_actions = {
extends = true, -- extend default configuration
"cargo", -- include default cargo actions (redundant with extends)
{ -- Adding alternative npm actions
condition = "package.json",
load = "my_lib.project_actions.npm",
exclude_file_actions = { "javascript" }, -- optional
},
},
file_actions = {
"javascript",
"lua" = "my_lib.file_actions.lua_actions",
"typescript" = function ()
-- get my typescript actions
end
},
}
All functions operate on the current working directory and assume that it is the project root. You can use project.nvim to automatically set your working directory to your project root.
local show_project_actions = require "project_actions" .show_actions
vim.keymap.set("n", "<Leader>a", show_project_actions)
Supports all basic cargo commands like cargo add
and cargo run
.
Attempts to read build targets from makefile.
Also shows make
option for user specified targets.
Supports basic npm functions like npm install
and can run scripts from package.json
.
Shows all tasks from gradlew tasks --all
.
Running this the first time can take very long.
Run the current file.
Run the current file with node or bun.
Run the current file with bun.