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

Hover and autocomplete can't find macros prefixed with @ #104

Open
PgBiel opened this issue Jan 26, 2025 · 1 comment
Open

Hover and autocomplete can't find macros prefixed with @ #104

PgBiel opened this issue Jan 26, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@PgBiel
Copy link
Contributor

PgBiel commented Jan 26, 2025

Describe the bug
When hovering over a @macroname, either nothing is displayed, or any matches for macroname (without @) are shown instead, even if they have nothing to do with the invoked macro (e.g. some function with that same name). Similarly, autocomplete cannot find macro names beginning with @.

This problem can be traced back to the snippet below in SourceCode.getWordIndexLimits in server/pkg/document/sourcecode/sourcecode.go (and possibly similar for Document.getWordIndexLimits in document_reader.go). When the user clicks on an identifier, we only go back as far as there are letters or numbers, but @s are not included in the identifier.

symbolStart := 0
for i := index; i >= 0; i-- {
r := rune(s.Text[i])
if !utils.IsAZ09_(r) {
// First invalid character found, that means previous iteration contained first character of symbol
symbolStart = i + 1
break
}
}

One potential solution would be to allow @ as part of symbol names, but I guess this could potentially lead to some problems with @attributes, if those ever get their own form of autocomplete.

Alternatively, we could add a property to Word - or a function - which indicates whether or not there is an @ right before the word, and if so we can include that in the search.

To Reproduce
Steps to reproduce the behavior:

  1. Define a macro with @body, which requires an @ prefix, e.g. macro @name(; @body) { @body(); }
  2. Hover on '@name'
  3. Note that nothing appears, or instead you get the hover info of a function called name

Expected behavior
Macro hover info should appear

Screenshots

fn "takesA" followed by macro "@takesA" shows hover info for "takesA" on "@takesA"

no hover info for "@takesB"

Desktop (please complete the following information):

  • OS: Linux
  • Editor: Zed and VSCode (and others)
  • Version: at least 0.3.3

Additional context
There is some related discussion at #103

@pherrymason
Copy link
Owner

pherrymason commented Jan 26, 2025

Branch search_on_astB totally circumvents bugs related to string manipulation like one as I can traverse the code through the AST instead of trying to be smart by manipulating strings.
Let's keep this issue open to remember testing this in the new version, but I would not try to fix it in main branch.

@pherrymason pherrymason added the bug Something isn't working label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants