swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
742 stars 51 forks source link

fallback grammar labels operator lexeme precedence groups as invalid syntax #366

Closed tayloraswift closed 2 years ago

tayloraswift commented 2 years ago

Describe the bug

operator lexeme declarations with explicit precedence groups are (incorrectly) flagged as invalid syntax:

infix operator ?= :ComparisonPrecedence

Screenshot from 2022-07-19 15-42-06

there are three bugs here. two are vscode-swift bugs, and the other one is a sourcekit-lsp bug:

lexeme ?= : ComparisonPrecedence
current semantic highlight none none identifier
expected semantic highlight identifier none identifier
sourcekit-lsp bug? yes no no
current fallback label operator invalid invalid
expected fallback label operator none none
vscode-swift bug? no yes yes

Environment

$ swift --version
Swift version 5.8-dev (LLVM 396c6969ee90ef4, Swift 02efc3a2d28e348)
Target: x86_64-unknown-linux-gnu
$ swiftenv version
DEVELOPMENT-SNAPSHOT-2022-07-06-a 
$ code --version
1.69.2
3b889b090b5ad5793f524b5d1d39fda662b96a2a
x64
adam-fowler commented 2 years ago

Again this is most likely Sourcekit-LSP. The vscode-swift extension does nothing with the semantic highlighting

tayloraswift commented 2 years ago

can you please transfer this issue to https://github.com/apple/sourcekit-lsp/issues ? i do not have write access to either repo

adam-fowler commented 2 years ago

It appears transfer issue only works within an organisation. So I can't transfer to the apple organisation.

tayloraswift commented 2 years ago

there are three bugs covered by this issue, you are correct in that one of them was actually a sourcekit-lsp issue, and i have refiled it there. the other two are vscode bugs, as they originate from faulty rules in their repository: https://github.com/microsoft/vscode/blob/main/extensions/swift/syntaxes/swift.tmLanguage.json

closing this issue

jtbandes commented 11 months ago

Hi folks, I'm obviously quite late to this ticket, but I'm the maintainer of the upstream repo that the vscode grammar is generated from. I'm trying to understand the reported issue exactly, but I'm kind of confused because as far as I can tell the grammar is handling this line correctly in TextMate and GitHub (which also uses the TM grammar):

infix operator ?= :ComparisonPrecedence
image

Is the issue only present in the vscode extension specifically?

adam-fowler commented 11 months ago

@tayloraswift can you help here

tayloraswift commented 11 months ago

i am still seeing invalid.illegal.character-not-allowed-here.swift meta.definition.operator.swift source.swift for the colon in that example.

i’m on version v1.7.0 of the swift extension, but i imagine this is coming from the TextMate grammar that ships with VSCode (1.83.1), and not the swift extension.

jtbandes commented 11 months ago

Yep, sounds like it must be a VS Code specific issue then. If anyone knows a quick way to use an updated tmlanguage in vscode for testing purposes, let me know. I will try it out and see if I can figure out where the discrepancy comes from.

jtbandes commented 11 months ago

I believe the root cause of the issue is https://github.com/microsoft/vscode-textmate/issues/140. There seems to be a simple enough workaround so I believe it I can get this fixed easily.