diff options
| author | git-bruh <prathamIN@proton.me> | 2024-04-08 00:43:44 +0530 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-09 20:08:06 +0100 |
| commit | 386ccd3213adc34ab9e56bb1b99160672771f064 (patch) | |
| tree | 6dae4c11356f77ac10acc421d1038b37482874e3 | |
| parent | f486814e083431d6170fc644338e19220f7f81d5 (diff) | |
| download | vis-lspc-386ccd3213adc34ab9e56bb1b99160672771f064.tar.gz vis-lspc-386ccd3213adc34ab9e56bb1b99160672771f064.zip | |
*: pass rootUri
| -rw-r--r-- | init.lua | 24 | ||||
| -rwxr-xr-x | tools/find-root | 26 |
2 files changed, 49 insertions, 1 deletions
@@ -1228,6 +1228,27 @@ local function ls_shutdown(ls) ls:call_method('shutdown') end +local function get_root_path(ls, file_path) + local globs = '' + + if ls.roots then + for _, glob in ipairs(ls.roots) do + globs = globs .. glob .. '\n' + end + end + + globs = globs .. '.git\n.hg\n' + + local status, out = vis:pipe(globs, source_path .. '/tools/find-root "' .. file_path .. '"') + + if status ~= 0 then + return nil + end + + -- Skip trailing newline + return out:sub(1, #out - 1) +end + local function ls_start(ls, init_options) ls.fd = vis:communicate(ls.name, 'exec ' .. ls.cmd) @@ -1259,7 +1280,7 @@ local function ls_start(ls, init_options) local params = { processId = vis_pid, clientInfo = {name = lspc.name, version = lspc.version}, - rootUri = lspc.json.null, + rootUri = (vis.win.file and path_to_uri(get_root_path(ls, vis.win.file.path))) or lspc.json.null, capabilities = lspc.client_capabilites, } @@ -1281,6 +1302,7 @@ local function new_ls(ls_conf) inflight = {}, parser = parser.new(), capabilities = {}, + roots = ls_conf.roots, -- exported methods of a language server send_notification = ls_send_notification, diff --git a/tools/find-root b/tools/find-root new file mode 100755 index 0000000..d2c71ab --- /dev/null +++ b/tools/find-root @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eu + +if [ ! "${1:-}" ]; then + exit 1 +fi + +BASEDIR="$(dirname "$1")" + +while read -r glob; do + cd "$BASEDIR" + + while [ "$PWD" != "/" ]; do + set -- $glob + + if [ -e "$1" ]; then + echo "$PWD" + exit 0 + fi + + cd .. + done +done + +echo "$BASEDIR" |
