From 2580893630af08fd38810a74a4f02013367ae17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 18 Jul 2022 18:48:50 +0800 Subject: parse path in `source` --- script/core/jump-source.lua | 32 ++++++++++++++++++++++++++++---- script/parser/luadoc.lua | 11 ++--------- 2 files changed, 30 insertions(+), 13 deletions(-) (limited to 'script') diff --git a/script/core/jump-source.lua b/script/core/jump-source.lua index 2de23b29..6fb8414f 100644 --- a/script/core/jump-source.lua +++ b/script/core/jump-source.lua @@ -1,4 +1,26 @@ local guide = require 'parser.guide' +local furi = require 'file-uri' +local ws = require 'workspace' + +---@param doc parser.object +---@return uri +local function parseUri(doc) + local uri + local scheme = furi.split(doc.path) + if scheme and #scheme >= 2 then + uri = doc.path + else + local suri = guide.getUri(doc):gsub('[/\\][^/\\]*$', '') + local path = ws.getAbsolutePath(suri, doc.path) + if path then + uri = furi.encode(path) + else + uri = doc.path + end + end + ---@cast uri uri + return uri +end ---@param results table return function (results) @@ -7,8 +29,9 @@ return function (results) or result.target.type == 'doc.class.name' then local doc = result.target.parent.source if doc then - result.uri = doc.source - result.target.uri = doc.source + local uri = parseUri(doc) + result.uri = uri + result.target.uri = uri result.target.start = guide.positionOf(doc.line - 1, doc.char) result.target.finish = guide.positionOf(doc.line - 1, doc.char) end @@ -22,8 +45,9 @@ return function (results) for _, doc in ipairs(target.bindDocs) do if doc.type == 'doc.source' and doc.bindSource == target then - result.uri = doc.source - result.target.uri = doc.source + local uri = parseUri(doc) + result.uri = uri + result.target.uri = uri result.target.start = guide.positionOf(doc.line - 1, doc.char) result.target.finish = guide.positionOf(doc.line - 1, doc.char) end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 6bf1a338..b4b311ae 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -3,7 +3,6 @@ local re = require 'parser.relabel' local guide = require 'parser.guide' local compile = require 'parser.compile' local util = require 'utility' -local furi = require 'file-uri' local TokenTypes, TokenStarts, TokenFinishs, TokenContents, TokenMarks ---@type integer @@ -148,7 +147,7 @@ Symbol <- ({} { ---@field async? boolean ---@field versions? table[] ---@field names? parser.object[] ----@field source? parser.object +---@field path? string local function parseTokens(text, offset) Ci = 0 @@ -1419,17 +1418,11 @@ local docSwitch = util.switch() source = source or fullSource line = tonumber(line) or 1 char = tonumber(char) or 0 - local uri - if furi.split(source) then - uri = source - else - uri = furi.decode(source) - end local result = { type = 'doc.source', start = getStart(), finish = getFinish(), - source = uri, + path = source, line = line, char = char, } -- cgit v1.2.3