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

Issues with type annotations when type includes a method, which includes a string #133

Open
a-stewart opened this issue Oct 13, 2022 · 6 comments
Labels
bug Something isn't working grammar Related to the TextMate grammar, i.e. syntax highlighting

Comments

@a-stewart
Copy link

Consider the following code:

image

The type annotations include a callable type which can have string arguments which fail - but then if the string contains either > or ) that ends the type annotation early, resulting in the closing string tag being mistakenly recognized as opening a string.

Note that, I expect that it is not just strings that are not considered here, but other primitives too. I am not familiar with Kotlin though to be fully certain on what is allowed in the language here though.

@fwcd
Copy link
Owner

fwcd commented Oct 13, 2022

I am assuming this issue also occurs while the language server is starting/disabled? In that case, it's probably an issue with the grammar.

@fwcd fwcd added bug Something isn't working grammar Related to the TextMate grammar, i.e. syntax highlighting labels Oct 13, 2022
@a-stewart
Copy link
Author

a-stewart commented Oct 13, 2022

Hi,

Sorry, yes this is an issue with the grammar, not with the language server.

In particular:

        "type-annotation": {
            "match": "(?<![:?]):\\s*(\\w|\\?|\\s|->|(?<GROUP>[<(]([^<>()]|\\g<GROUP>)+[)>]))+",

The problem is that it does not like it if we include a > or ) in the grammar since that essentially ends where it thinks the type-parameters goes up to. I'm currently playing with the grammar a bit to see if I can find a simple solution to match more generously - but the challenge is trying to find something that should trigger the end of a type annotation.

@fwcd
Copy link
Owner

fwcd commented Oct 13, 2022

Sure no problem, since this repo hosts the canonical version of the grammar, opening the issue here is totally fine! There's even a tiny VSCode extension for tinkering with the grammar here.

@a-stewart
Copy link
Author

I have created a PR for a small patch which slightly improves things by not including parameters if there is a quote.

This won't help with the issue fully though, as I think we can also confuse it by introducing parenthesis around numbers.

I think the best solution is likely to involve updating type-annotation to use begin and end - but I am not sure how best to support both generics and parameters in that way.

@themkat
Copy link
Contributor

themkat commented Feb 21, 2023

@a-stewart , did your PR solve the issue completely? Or are there still something missing? Just asking in case we can close this 🙂

@a-stewart
Copy link
Author

The PR doesn't solve the issue completely - I think that type annotations which include a string will not be tokenised correctly.

@fwcd fwcd transferred this issue from fwcd/kotlin-language-server Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working grammar Related to the TextMate grammar, i.e. syntax highlighting
Projects
None yet
Development

No branches or pull requests

3 participants