-
-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LuaDoc. Fixed the start position of the comment first symbol in docs #3028
base: master
Are you sure you want to change the base?
Conversation
Regarding this question, I think it makes sense because it stores the body of a comment 🤔 --foo bar
|
Damn, I found an issues -- length = comment.finish - comment.start
-- length 26, relative finish 19, actual comment.text `-@param a string?Comment` (24 length, without 2)
-- ok
---@param a string?Comment
-- length 27, relative finish 18, actual comment.text `@param a string?Comment` (23 length, without 4!)
-- also real line length 29! `--` token was skipped before "calculating positions"
-- ok comment but wrong colorizing
--[[@param a string?Comment]]
-- also wrong colorizing, so no comment issue
--[[@param a string?]]
-- length 33, relative finish 21, actual comment.text `@param a string?Comment` (23 length, without 10!!!)
-- wrong our offset 2, now comment text is `ment` :<
-- also wrong colorizing
--[===[@param a string[]Comment]===] I could assume to search for the first character Also the expression |
If you believe this PR is still not complete, I think the first thing is to turn it into draft: I will try to respond to the new found issues one by one when I got time 👀 |
the unconsidered
|
local startOffset = comment.start | |
if comment.type == 'comment.long' then | |
startOffset = startOffset + #comment.mark - 2 | |
end |
--[[@param a string?Comment]]
, comment.mark
= [[
=> this is indeed what we need 😄
=> so we can have a generalized form for the conversion functions pair:
local function convertLinePosToCommentPos(comment, linePos)
-- some new comment explaining the new formula
local textOffset = comment.type == 'comment.long' and #comment.mark or 2
return linePos - comment.start + 1 - textOffset
end
local function convertCommentPosToLinePos(comment, commentPos)
-- the reverse of convertLinePosToCommentPos()
local textOffset = comment.type == 'comment.long' and #comment.mark or 2
return commentPos + textOffset - 1 + comment.start
end
With this fix to both convertLinePosToCommentPos
and convertCommentPosToLinePos
, now all comments can be recognized correctly now, including your last test case --[===[@param a string[]Comment]===]
👍
But still the coloring for ?
after string
seems wrong 🤔 and currently I have no idea why.
After some thought, this is not pointless 🤔
If we can be certain that the length of |
…dLuaDoc, sync with semantic logic. Fix crash 'comment.clong' type for /*, fix typo docGeneric.
…o not try to process a multiline `result`, while `doc` is the first line.
…(pattern is optional)
537aaed
to
4af79e3
Compare
I have redone this.
Actually we call lua-language-server/script/parser/luadoc.lua Lines 1716 to 1736 in 9ba27a6
The startOffset for the comment.shortThe In Later I discovered exactly the same logic in the lua-language-server/script/core/semantic-tokens.lua Lines 906 to 924 in 9ba27a6
The old one implied that the
--[===[ @param a string?ComMMS1]===]
local function new(a) end This pattern is optional My complete test---@type integer, string, string Comment
local a, b, c
---@param a string?Comment
local function new(a) end
--- @param a string?ComSpa1
local function new(a) end
---@ param a string?ComSpa2
local function new(a) end
--- @ param a string?ComSpa3
local function new(a) end
--[[@param a string?ComMult]]
local function new(a) end
--[[ @param a string?ComMuS1]]
local function new(a) end
--[[@ param a string?ComMuS2]]
local function new(a) end
--[[ @ param a string?ComMuS3]]
local function new(a) end
--[===[@param a string?ComMMul]===]
local function new(a) end
--[===[ @param a string?ComMMS1]===]
local function new(a) end
--[===[@ param a string?ComMMS2]===]
local function new(a) end
--[===[ @ param a string?ComMMS3]===]
local function new(a) end
--- @param a string?
local function new(a) end
--[[ @param a string? ]]
local function new(a) end
--[===[ @param a string? ]===]
local function new(a) end
--- @param a string? A
local function new(a) end
--[[ @param a string? B]]
local function new(a) end
--[===[ @param a string? C]===]
local function new(a) end Result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that your latest changes can solve #3034 as well?
Then you can link it by adding this to the first line of original your PR description
fixes #3034
This can let github close the linked issues on this PR merge 👀
No, this is a potential support if the bug is resolved in the future (it will work automatically). But if is not, it does not affect anything. Actually the pattern for short already contained optional spaces, but not for long ones. I did for the long ones as well. |
@tomlau10 can I just add This will eliminate the ambiguity, and we will no longer keep the lua-language-server/script/parser/compile.lua Lines 578 to 597 in 9ba27a6
|
I don't think so 😕 lua-language-server/script/parser/luadoc.lua Lines 697 to 719 in cb964c6
Back to comment, for short comment there is no mark concept, as nothing is used to quote the comment body. Maybe you can just keep this PR as is. |
The positions were calculated slightly incorrectly there, because it got confused with the lengths.now its
Comment
instead ofomment
.But I came across the fact that the comment textscomment.text
do not contain--
at the beginning, because this token is uuuh... being skipped?That is, we were working with a string of a different length and start pos (-2). I made a variablelocal textOffset = 2
so that it could be easily fixed in the future.p.s. Maybe you should figure out why this is happening.upd. Please see the latest message for actual changes.