@@ -5,7 +5,7 @@ local util = require("down.mod.workspace.util")
55local utils = require (" down.util" )
66
77local fn , fs , it , uv , dbg =
8- vim .fn , vim .fs , vim .iter , (vim .uv or vim .loop ), vim .print
8+ vim .fn , vim .fs , vim .iter , (vim .uv or vim .loop ), vim .print
99
1010--- @class down.Workspace : string
1111--- @class down.Workspaces : { [string ]?: string }
@@ -114,30 +114,8 @@ Workspace.setup = function()
114114end
115115
116116Workspace .maps = {
117- {
118- " n" ,
119- " ,D" ,
120- function ()
121- dbg (Workspace .data )
122- end ,
123- " hi" ,
124- },
125- {
126- " n" ,
127- " ,dfw" ,
128- " <CWorkspaceD>Telescope down workspace<CR>" ,
129- " Telescope down workspaces" ,
130- },
131- { " n" , " ,d." , " <CWorkspaceD>Down workspace cwd<CR>" , " Down workspace in cw" },
132- { " n" , " ,di" , " <CWorkspaceD>Down index<CR>" , " Down index" },
133- { " n" , " ,dw" , " <CWorkspaceD>Down workspace<CR>" , " Down workspaces" },
134- {
135- " n" ,
136- " ,dfw" ,
137- " <CWorkspaceD>Telescope down workspace<CR>" ,
138- " Telescope down workspaces" ,
139- },
140- { " n" , " ,d." , " <CWorkspaceD>Down workspace cwd<CR>" , " Down workspace in cw" },
117+ { " n" , " ,di" , " <cmd>Down index<CR>" , " Down index" },
118+ { " n" , " ,dw" , " <cmd>Down workspace<CR>" , " Down workspaces" },
141119}
142120
143121--- Returns an iterator for the workspaces
@@ -153,26 +131,37 @@ end
153131Workspace .as_lsp_workspace = function (name , path )
154132 return {
155133 name = name or Workspace .data .active ,
156- uri = vim .uri_from_fname (path or Workspace .path (name or Workspace .data .active )),
134+ uri = vim .uri_from_fname (
135+ path or Workspace .path (name or Workspace .data .active )
136+ ),
157137 }
158138end
159139
160140--- Returns the workspace folders as lsp
161141--- @return lsp.WorkspaceFolder[]
162142Workspace .as_lsp_workspaces = function ()
163- return vim .iter (Workspace .data .workspaces ):map (Workspace .as_lsp_workspace ):totable ()
143+ return vim
144+ .iter (Workspace .data .workspaces )
145+ :map (Workspace .as_lsp_workspace )
146+ :totable ()
164147end
165148
166149--- Loads the workspace module
167150Workspace .load = function ()
168151 vim .iter (Workspace .config .workspaces ):each (function (k , v )
169152 Workspace .config .workspaces [k ] = fs .normalize (fn .resolve (fn .expand (v )))
170153 end )
171- Workspace .data .workspaces = Workspace .config .workspaces or Workspace .data .workspaces or {}
154+ Workspace .data .workspaces = Workspace .config .workspaces
155+ or Workspace .data .workspaces
156+ or {}
172157 Workspace .data .history = Workspace .data .history or {}
173- Workspace .data .default = Workspace .config .default or Workspace .data .default or " default"
158+ Workspace .data .default = Workspace .config .default
159+ or Workspace .data .default
160+ or " default"
174161 Workspace .data .previous = Workspace .data .previous or " default"
175- Workspace .data .active = Workspace .data .active or Workspace .data .default or " default"
162+ Workspace .data .active = Workspace .data .active
163+ or Workspace .data .default
164+ or " default"
176165 vim .api .nvim_create_autocmd (" BufEnter" , {
177166 pattern = " *" ,
178167 callback = function ()
187176--- Returns the index file for a workspace
188177--- @class down.mod.workspace.Data
189178Workspace .index = function (p )
190- return vim .fs .joinpath (p or Workspace .current_path (), Workspace .config .index .. Workspace .config .ext )
179+ return vim .fs .joinpath (
180+ p or Workspace .current_path (),
181+ Workspace .config .index .. Workspace .config .ext
182+ )
191183end
192184
193185--- Returns the current workspace name
@@ -260,7 +252,8 @@ Workspace.add_workspace = function(wsname, wspath)
260252 wspath = Workspace .path (wspath )
261253 Workspace .data .workspaces [wsname ] = Workspace .path (wspath )
262254 mod .broadcast (
263- mod .new_event (Workspace , " workspace.events.wsadded" , { wsname , wspath }) or {}
255+ mod .new_event (Workspace , " workspace.events.wsadded" , { wsname , wspath })
256+ or {}
264257 )
265258 Workspace .sync ()
266259 return true
@@ -288,26 +281,26 @@ end
288281--- @param fn ? fun ( item : number | string , idx : number | string )| nil
289282Workspace .select = function (prompt , fmt , fn )
290283 local format = fmt
291- or function (item )
292- local current = Workspace .current ()
293- if item == current then
294- return " • " .. item
295- end
296- return item
284+ or function (item )
285+ local current = Workspace .current ()
286+ if item == current then
287+ return " • " .. item
297288 end
289+ return item
290+ end
298291 local func = fn
299- or function (item , idx )
300- local current = Workspace .current ()
301- if not item then
302- return
303- elseif item == current then
304- vim .notify (" Already in workspace " .. current )
305- else
306- vim .notify (" Workspace set to " .. item )
307- Workspace .set_workspace (item )
308- end
309- Workspace .open (item )
292+ or function (item , idx )
293+ local current = Workspace .current ()
294+ if not item then
295+ return
296+ elseif item == current then
297+ vim .notify (" Already in workspace " .. current )
298+ else
299+ vim .notify (" Workspace set to " .. item )
300+ Workspace .set_workspace (item )
310301 end
302+ Workspace .open (item )
303+ end
311304 return vim .ui .select (Workspace .names (), {
312305 prompt = prompt or " Select workspace" ,
313306 format_items = format ,
@@ -374,8 +367,8 @@ Workspace.set_last_workspace = function()
374367 if not wspath then
375368 log .trace (
376369 " Unable to switch to workspace '"
377- .. prev
378- .. " '. The workspace does not exist."
370+ .. prev
371+ .. " '. The workspace does not exist."
379372 )
380373 return
381374 end
@@ -508,26 +501,26 @@ end
508501--- @param fn ? fun ( item : number | string , idx : number | string )| nil
509502Workspace .select_file = function (prompt , fmt , fn )
510503 local format = fmt
511- or function (item )
512- local current = vim .fn .expand (" %:p" )
513- if item == current then
514- return " • " .. item
515- end
516- return item
504+ or function (item )
505+ local current = vim .fn .expand (" %:p" )
506+ if item == current then
507+ return " • " .. item
517508 end
509+ return item
510+ end
518511 local func = fn
519- or function (item , idx )
520- local current = vim .fn .expand (" %:p" )
521- if not item then
522- return
523- elseif item == current then
524- vim .notify (" Already editing " .. current )
525- else
526- vim .notify (" Editing " .. item )
527- Workspace .edit (item )
528- end
512+ or function (item , idx )
513+ local current = vim .fn .expand (" %:p" )
514+ if not item then
515+ return
516+ elseif item == current then
517+ vim .notify (" Already editing " .. current )
518+ else
519+ vim .notify (" Editing " .. item )
529520 Workspace .edit (item )
530521 end
522+ Workspace .edit (item )
523+ end
531524 return vim .ui .select (Workspace .markdown (Workspace .current ()) or {}, {
532525 prompt = prompt or " Select markdown file in workspace" ,
533526 format_items = format ,
@@ -563,11 +556,11 @@ end
563556
564557Workspace .fmt = function ()
565558 return vim
566- .iter (Workspace .workspaces ())
567- :map (function (k , v )
568- return k .. " -> " .. v
569- end )
570- :totable ()
559+ .iter (Workspace .workspaces ())
560+ :map (function (k , v )
561+ return k .. " -> " .. v
562+ end )
563+ :totable ()
571564end
572565
573566--- @class down.mod.workspace.Commands : { [string ]: down.Command }
0 commit comments