Comments (7)
Project-specific tasks can be implemented pretty easily with a .vscode
folder in your project root. Overseer will read these tasks and add them to your task selector. This can be done in lua, but I wouldn't recommend it, as it pollutes your dotfiles with task templates that only work for specific projects.
However, if you want to use lua, see the callback
field of condition
, which can execute a function to determine whether a task should be visible in the task runner.
A project-specific lua task can be implemented like this:
{
name = 'Compile',
builder = function()
local file = vim.fn.expand '%:p'
return {
cmd = { 'g++' },
args = { file },
name = 'Compile ' .. file,
components = { 'default' },
}
end,
condition = {
filetype = { 'cpp' },
-- Only show if this function returns true
callback = function()
-- Assume project root is the directory containing '.git'
local git_path = vim.fn.finddir('.git', vim.fn.getcwd() .. ';')
local proj_path = vim.fn.fnamemodify(git_path, ':h')
-- Make sure that the project path ends in a '/'
if vim.fn.fnamemodify(proj_path, ':p') == 'path/to/project/' then
return true
end
return false
end,
},
}
from overseer.nvim.
Damn, @dzfrias again you're so fast!
I would generally agree that for project-specific tasks .vscode/tasks.json
is the way to go. It's a data-only format so it's safer than running arbitrary code in your editor, and it's not neovim-specific, so people with other editors can benefit from it.
If you want to do it with lua, you definitely can. If you want to load and run files that are local to your project, you'll have to pick some other plugin to do that or roll your own. Overseer does not have a system for auto-loading lua files in a directory, and I don't plan to add one.
Referencing the docs on custom tasks, you can dynamically register a task with overseer.register_template
. The example above is great, but I would make one slight tweak: there is a dir
condition that's easier to use than the callback
.
require('overseer').register_template({
name = 'Compile',
builder = function()
local file = vim.fn.expand '%:p'
return {
cmd = { 'g++' },
args = { file },
name = 'Compile ' .. file,
components = { 'default' },
}
end,
condition = {
filetype = { 'cpp' },
dir = "/path/to/project",
},
})
from overseer.nvim.
The builder function is called when the task is selected for running, so yes, you could get the name of the file in the current buffer. A lot of good examples of task templates and other things in the Overseer ecosystem are in the source code. This link has a bunch of built-ins that you should check out if you want to write your own.
Here is an example of a task template to compile a cpp file:
{
-- Name in the task selector
name = 'Compile',
builder = function()
-- Get file's absolute path
local file = vim.fn.expand '%:p'
return {
cmd = { 'g++' },
args = { file },
-- Name in the task list
name = 'Compile ' .. file,
components = { 'default' },
}
end,
condition = {
-- Only show this task if the filetype is cpp
filetype = { 'cpp' },
},
}
Feel free to ask any questions about this code.
You can get vscode variables pretty easily, using lua (for example, "${file}"
for vscode is equivalent to vim.fn.expand("%:p")
in lua, as shown in the example above). See the source for their actual implementation in lua.
from overseer.nvim.
Thanks @dzfrias for jumping in here! That is an excellent explanation and example, I couldn't have said it better.
@dcordb based on your question (and others I've received), I've decided to overhaul the documentation. I have a work-in-progress PR at #29, and you can browse the new docs by going to https://github.com/stevearc/overseer.nvim/tree/stevearc-doc.
I've taken the example here and added it to the new tutorials doc, along with some others. Please feel free to leave feedback on the PR! There's a few more things I have to get working (mostly API doc generation) before I can merge it.
from overseer.nvim.
This is really good! Great editorial, I could configure it without a problem. To add something to what @dzfrias wrote that might be useful for others, I also created a mapping to build the cpp file.
I created a cpp.lua
in after/ftplugin
directory, the file looks like this:
local overseer = require("overseer")
vim.keymap.set("n",
"<M-b>",
function() overseer.run_template({ name = "g++ build" }) end,
{ buffer = true }
)
This way the mapping only appears in buffers with cpp
filetype.
from overseer.nvim.
I have other questions that may go in a different issue:
- What about project specific tasks?
- Do vscode tasks work as project specific tasks?
- Can this be done also in Lua? (although this would mean that the plugin needs to read Lua files from some folder, this might be insecure).
from overseer.nvim.
I see the recipes are already on master. The issue is resolved, so I'm closing this.
from overseer.nvim.
Related Issues (20)
- bug: `$eslint-stylish` triggers error HOT 2
- feature request: ToggleTerm strategy - go to previous window on terminal close
- feature request: Is there any way to create custom strategy?
- feature request: strategy to read output from a log file instead of stdout and stderr
- bug: The sidebar buffer doesn't render after opening overseer before job start HOT 2
- bug: The scroll doesn't work with the toggleterm strategy when opening a preview
- feature request: Hidden vscode tasks HOT 3
- bug: Wrong autocomplete parameters with enum type
- bug: Orchestrator strategy undefined behavior HOT 1
- bug: open vsplit doesn't open (split) on the right HOT 1
- bug: telescope picker not shown but a fallback HOT 1
- feature request: [windows] remove (nonstandard?) escape sequences
- on_result_diagnostics_quickfix.set_empty_results not clearing diagnostics list HOT 1
- -
- bug: Targets from included Makefile only visible on first execution HOT 5
- bug: shell escape single quote HOT 2
- bug: How to keep in task log window HOT 2
- feature request: OverseerToggle!top
- How to change select multi parameters( TAB is no effect)
- bug: ephemeral docker containers do not stop HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from overseer.nvim.