typst-lsp icon indicating copy to clipboard operation
typst-lsp copied to clipboard

Incorrect type flags used to mark parameters and functions

Open Complex2-Liu opened this issue 1 year ago • 10 comments

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the discussions and believe that my question is not already covered.

Feature Request

Motivated by package tidy. See also LuaLs for someone familiar with Neovim.

/// Check if the given value is defined
///
/// @param v any
/// @return boolean
#let has(v) = {
  type(v) != type(none)
}

/// Like html rem
///
/// @param n integer
/// @param fontsize? length The root font size
/// @return length
#let rem(n, fontsize: 11pt) { return n * fontsize }

Complex2-Liu avatar Jan 02 '24 16:01 Complex2-Liu

Hey there :) What's the request here specifically ?

astrale-sharp avatar Jan 02 '24 16:01 astrale-sharp

rem is defined as a function, but typst-lsp prompts that it is a constant.

rem is a function, not constant

For packages (say physica) inside @preview, tensor is identified correctly as a function.

packages inside @preview

However, when I invoke this function, typst-lsp prompts that it is a constant again.

tensor is a function, not constant

The image below shows how LuaLs works. It displays the comment of a function, and the information about parameters of this function: it takes only one parameter, v, which can be of any type.

LuaLs example

Complex2-Liu avatar Jan 09 '24 09:01 Complex2-Liu

I see thanks, it's clearer now ;)

astrale-sharp avatar Jan 09 '24 09:01 astrale-sharp

This is probably a good first issue (I haven't investigated but it doesn't seem too complex). What do you think @Myriad-Dreamin ?

astrale-sharp avatar Jan 09 '24 09:01 astrale-sharp

typst-lsp just uses typst-ide for autocompletion. So imo, the inperfect is more probably caused by typst-ide, and less by typst-lsp. @astrale-sharp Is it time to check it by our awesome ide testing framework, :)?

https://github.com/nvarner/typst-lsp/blob/0d5b9330a1d515fa47456e755f751ea4056282b8/src/server/lsp.rs#L426-L429

Myriad-Dreamin avatar Jan 09 '24 12:01 Myriad-Dreamin

Supplement. If I understand webapp's completion correctly, webapp tells me the add function is a constant as well (c character in the following figure).

image

Myriad-Dreamin avatar Jan 09 '24 12:01 Myriad-Dreamin

Agreed, this is almost certainly a Typst bug. From a quick look at the relevant code, the scope_completions function looks a little ad-hoc, and improving its implementation is probably the fix. https://github.com/typst/typst/blob/main/crates/typst-ide/src/complete.rs#L1280

nvarner avatar Jan 09 '24 16:01 nvarner

@astrale-sharp Is it time to check it by our awesome ide testing framework, :)?

Unfortunately I just added functionality for testing the actual string being autocompleted, not it's kind which is globally a bit more weird to check if there are many possible completions :sweat_smile:

astrale-sharp avatar Jan 09 '24 16:01 astrale-sharp

Then I propose we should close this and open a typst issue, any objection @Complex2-Liu ?

astrale-sharp avatar Jan 09 '24 16:01 astrale-sharp

We may open a typst issue and keep this open. And this can be closed once the upstream bug get fixed

Enter-tainer avatar Jan 10 '24 10:01 Enter-tainer