From 795beac9e6a98794fd8320bd2317e01ed329148b Mon Sep 17 00:00:00 2001 From: Michiel van den Heuvel Date: Sun, 27 Aug 2023 16:20:46 +0200 Subject: Add function to open a file to lspc object --- README.md | 19 +++++++++++++++++++ init.lua | 8 +++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffd98d6..749673f 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,25 @@ ls_map.lua = { Language servers configured in vis-lspc can be found in `supported_servers.lua`. +### Extensibility + +The returned module table also includes functions you can use in your own vis +configuration. + +#### `lspc.lspc_open` + +Navigate between or in files, while remembering the current position in a runtime history. + +```lua +lspc_open(win, path, line, col, cmd) +``` + + - `win` - a window in which to open the file + - `path` - the path to the file to open + - `line` - the line to open. (`nil` for no position within the file). + - `col` - same as `line`, but for the column. + - `cmd` - vis command to open the file. (`e` or `o`, see vis commands) + ## License All code except otherwise noted is licensed under the term of GPL-3. diff --git a/init.lua b/init.lua index ae3622e..de98490 100644 --- a/init.lua +++ b/init.lua @@ -419,13 +419,19 @@ local function vis_open_doc_pos(doc_pos, cmd, win) end end vis_open_file(doc_pos.file, cmd) - vis.win.selection:to(doc_pos.line, doc_pos.col) + if doc_pos.line then + vis.win.selection:to(doc_pos.line, doc_pos.col or 0) + end vis:command('lspc-open') else vis.win.selection:to(doc_pos.line, doc_pos.col) end end +lspc.open_file = function(win, path, line, col, cmd) + vis_open_doc_pos({file = path, line = line, col = col}, cmd or 'e', win) +end + -- Support jumping between document positions -- Stack of edited document positions local doc_pos_history = {} -- cgit v1.2.3