Skip to content

Commit

Permalink
Add a warning when project root not found
Browse files Browse the repository at this point in the history
  • Loading branch information
desdic committed Feb 19, 2024
1 parent 6bd7ae4 commit d95bb92
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
22 changes: 22 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# FAQ

## "project root not found"

If the project root is not found it can't save the jump points. You can fix this by defining more project roots like

```lua
opts = {
open_callback = require("marlin.callbacks").use_split,
patterns = { ".git", ".svn", "Makefile", "Cargo.toml", "." },
},
```

Or disabling the message with (But jump points won't be saved)

```lua
opts = {
suppress = {
missing_root = false
}
}
```
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ local default = {
datafile = vim.fn.stdpath("data") .. "/marlin.json", -- location of data file
open_callback = callbacks.change_buffer -- default way to open buffer
sorter = sorter.by_buffer -- sort by bufferid
suppress = {
missing_root = false -- don't give warning on project root not found
}
}
```

Expand Down Expand Up @@ -126,6 +129,10 @@ When I first saw harpoon I was immediately hooked but I missed a few key feature

Like anyone else missing a feature I created a patch but it seems that many other did the same.

### Issues/Feature request

[FAQ](FAQ.md) might have what you are looking, but pull request are also welcome.

### Credits

Credit goes to [ThePrimeagen](https://github.com/ThePrimeagen/harpoon/) for the idea.
3 changes: 3 additions & 0 deletions doc/marlin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ Default config
datafile = vim.fn.stdpath("data") .. "/marlin.json",
open_callback = callbacks.change_buffer,
sorter = sorter.by_buffer,
suppress = {
missing_root = false
}
}
<

Expand Down
14 changes: 10 additions & 4 deletions lua/marlin/datafile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ M.read_config = function(datafile)
return {}
end

M.save_data = function(datafile, project, localdata)
local data = M.read_config(datafile)
M.save_data = function(opts, project, localdata)
if project == nil then
if not opts.suppress.missing_root then
vim.notify("project root not found")
end
return
end
local data = M.read_config(opts.datafile)
data[project] = localdata

-- If we have no more files we remove the project
Expand All @@ -22,9 +28,9 @@ M.save_data = function(datafile, project, localdata)
end

local content = vim.fn.json_encode(data)
local fd = io.open(datafile, "w")
local fd = io.open(opts.datafile, "w")
if not fd then
vim.notify("Unable to open " .. datafile .. " for write")
vim.notify("Unable to open " .. opts.datafile .. " for write")
return
end

Expand Down
5 changes: 4 additions & 1 deletion lua/marlin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ local default = {
datafile = vim.fn.stdpath("data") .. "/marlin.json",
open_callback = callbacks.change_buffer,
sorter = sorter.by_buffer,
suppress = {
missing_root = false,
},
}
--minidoc_afterlines_end

Expand All @@ -74,7 +77,7 @@ end

local save = function(m)
vim.schedule(function()
datafile.save_data(m.opts.datafile, m.project_path, m.project_files)
datafile.save_data(m.opts, m.project_path, m.project_files)
end)
end

Expand Down

0 comments on commit d95bb92

Please sign in to comment.