From 244536181aaadebdbcaa511fb81a6b7f2e655c01 Mon Sep 17 00:00:00 2001 From: Will Rogers Date: Tue, 14 Jun 2022 14:53:44 +0200 Subject: [PATCH] add function to add workspaces after init --- .gitignore | 1 + README.md | 14 ++++++++++++++ lua/telescope/_extensions/frecency.lua | 7 +++++++ 3 files changed, 22 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6e92f57d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tags diff --git a/README.md b/README.md index b5ee1994..6ff0c9a7 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,20 @@ telescope.setup { } ``` +### Adding workspaces + +Workspaces can be added or updated after initialisation by calling `add_workspaces`. See below for an example. +**Note**: If you specify a workspace tag that already exists in the startup configuration, it will be overwritten. + +```lua +local frecency = require("telescope").extensions.frecency +frecency.add_workspaces({ + ["conf"] = "/home/another_user/.config", + ["data"] = "/home/another_user/.local/share", + ["project"] = "/home/another_user/projects", + }) +``` + ### SQL database location The default location for the sqlite3 database is `$XDG_DATA_HOME/nvim` (eg `~/.local/share/nvim/` on linux). diff --git a/lua/telescope/_extensions/frecency.lua b/lua/telescope/_extensions/frecency.lua index c7a9aaa2..bdaa6df5 100644 --- a/lua/telescope/_extensions/frecency.lua +++ b/lua/telescope/_extensions/frecency.lua @@ -271,6 +271,12 @@ local function checkhealth() end end +local function add_user_workspaces(mappings) + local workspaces = state.user_workspaces + for k,v in pairs(mappings) do workspaces[k] = v end + set_config_state("user_workspaces", workspaces, state.user_workspaces) +end + return telescope.register_extension { setup = function(ext_config) set_config_state("db_root", ext_config.db_root, nil) @@ -294,5 +300,6 @@ return telescope.register_extension { get_workspace_tags = get_workspace_tags, validate_db = db_client.validate, health = checkhealth, + add_workspaces = add_user_workspaces, }, }