Skip to content
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

Incorrect type flags used to mark parameters and functions #408

Open
Complex2-Liu opened this issue Jan 2, 2024 · 10 comments
Open

Incorrect type flags used to mark parameters and functions #408

Complex2-Liu opened this issue Jan 2, 2024 · 10 comments

Comments

@Complex2-Liu
Copy link

  • 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 }
@astrale-sharp
Copy link
Collaborator

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

@Complex2-Liu
Copy link
Author

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

@astrale-sharp
Copy link
Collaborator

I see thanks, it's clearer now ;)

@astrale-sharp astrale-sharp changed the title Annotations to mark parameters, returns and more Incorrect type flags used to mark parameters and functions Jan 9, 2024
@astrale-sharp
Copy link
Collaborator

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

@Myriad-Dreamin
Copy link
Collaborator

Myriad-Dreamin commented Jan 9, 2024

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, :)?

typst-lsp/src/server/lsp.rs

Lines 426 to 429 in 0d5b933

let (typst_start_offset, completions) =
typst_ide::autocomplete(&world, Some(&doc), &source, typst_offset, explicit)?;
let lsp_start_position =
offset_to_position(typst_start_offset, position_encoding, &source);

@Myriad-Dreamin
Copy link
Collaborator

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

@nvarner
Copy link
Owner

nvarner commented Jan 9, 2024

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

@astrale-sharp
Copy link
Collaborator

@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 😅

@astrale-sharp
Copy link
Collaborator

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

@Enter-tainer
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants