From 2266b94af5faad86184e0de47de64d5e3383f360 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 11 Feb 2025 20:21:26 +0100 Subject: [PATCH 1/3] fix: incorrect file names in doc.json File names in doc.json were broken since #2821. See discussion #2971. --- changelog.md | 1 + script/cli/doc/export.lua | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 454301b2e..97cac7f0c 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## Unreleased * `FIX` incorrect argument skip pattern for `--check_out_path=`, which incorrectly skips the next argument +* `FIX` incorrect file names in file doc.json ## 3.13.6 `2025-2-6` diff --git a/script/cli/doc/export.lua b/script/cli/doc/export.lua index 8d9b7d6f6..fd6d8b188 100644 --- a/script/cli/doc/export.lua +++ b/script/cli/doc/export.lua @@ -8,6 +8,8 @@ local getLabel = require 'core.hover.label' local jsonb = require 'json-beautify' local util = require 'utility' local markdown = require 'provider.markdown' +local fs = require 'bee.filesystem' +local furi = require 'file-uri' ---@alias doctype ---| 'doc.alias' @@ -55,13 +57,12 @@ local markdown = require 'provider.markdown' local export = {} function export.getLocalPath(uri) - --remove uri root (and prefix) - local local_file_uri = uri - local i, j = local_file_uri:find(DOC) - if not j then - return '[FOREIGN] '..uri + local relativePath = fs.relative(furi.decode(uri), DOC):string() + if relativePath:sub(1, 2) == '..' then + -- not under project directory + return '[FOREIGN] ' .. uri end - return local_file_uri:sub( j + 1 ) + return relativePath end function export.positionOf(rowcol) From 43d135edb878c2e87cd7d51ab53dbf671142090e Mon Sep 17 00:00:00 2001 From: Andreas Matthias Date: Thu, 13 Feb 2025 18:19:20 +0100 Subject: [PATCH 2/3] fix: fix last commit for Windows The test `relativePath:sub(1, 2) == '..'` doesn't work on windows if the paths are on different drives. --- script/cli/doc/export.lua | 9 ++++++--- script/cli/doc/init.lua | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/script/cli/doc/export.lua b/script/cli/doc/export.lua index fd6d8b188..b9c82ee14 100644 --- a/script/cli/doc/export.lua +++ b/script/cli/doc/export.lua @@ -57,10 +57,13 @@ local furi = require 'file-uri' local export = {} function export.getLocalPath(uri) - local relativePath = fs.relative(furi.decode(uri), DOC):string() - if relativePath:sub(1, 2) == '..' then + local file_canonical = fs.canonical(furi.decode(uri)):string() + local doc_canonical = fs.canonical(DOC):string() + local relativePath = fs.relative(file_canonical, doc_canonical):string() + local _, j = file_canonical:find(doc_canonical, 1, true) + if not j then -- not under project directory - return '[FOREIGN] ' .. uri + return '[FOREIGN] ' .. file_canonical end return relativePath end diff --git a/script/cli/doc/init.lua b/script/cli/doc/init.lua index 3492b3d9c..afb4e4da0 100644 --- a/script/cli/doc/init.lua +++ b/script/cli/doc/init.lua @@ -185,7 +185,7 @@ function doc.runCLI() return end - local rootUri = furi.encode(fs.absolute(fs.path(DOC)):string()) + local rootUri = furi.encode(fs.canonical(fs.path(DOC)):string()) if not rootUri then print(lang.script('CLI_CHECK_ERROR_URI', DOC)) return From cf934f495b5653f4e3aebcebbec98263df77d8e6 Mon Sep 17 00:00:00 2001 From: Andreas Matthias Date: Thu, 13 Feb 2025 18:45:20 +0100 Subject: [PATCH 3/3] chore: refactoring --- script/cli/doc/export.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/script/cli/doc/export.lua b/script/cli/doc/export.lua index b9c82ee14..1b72f8af1 100644 --- a/script/cli/doc/export.lua +++ b/script/cli/doc/export.lua @@ -60,8 +60,7 @@ function export.getLocalPath(uri) local file_canonical = fs.canonical(furi.decode(uri)):string() local doc_canonical = fs.canonical(DOC):string() local relativePath = fs.relative(file_canonical, doc_canonical):string() - local _, j = file_canonical:find(doc_canonical, 1, true) - if not j then + if relativePath == "" or relativePath:sub(1, 2) == '..' then -- not under project directory return '[FOREIGN] ' .. file_canonical end