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

Grouped use declarations are shown as invalid #81

Open
NattyNarwhal opened this issue Sep 20, 2024 · 2 comments
Open

Grouped use declarations are shown as invalid #81

NattyNarwhal opened this issue Sep 20, 2024 · 2 comments

Comments

@NattyNarwhal
Copy link

Syntax like this for multiple used classes from the same namespace:

<?php

namespace WebSocket\Trait;

use WebSocket\Message\{
    Binary,
    Close,
    Ping,
    Pong,
    Text
};

I get errors in the editor like this:

image

This is syntactically valid, lints fine with php -l, and has been since PHP 5.

The version of the VS Code extension is v1.3.3.

PHP LS trace
DEBUG     Checking PHPLS_ALLOW_XDEBUG
DEBUG     The Xdebug extension is not loaded

[Trace - 2:56:42 PM] Sending request 'initialize - (0)'.
Params: {
    "processId": 89070,
    "clientInfo": {
        "name": "Visual Studio Code",
        "version": "1.92.2"
    },
    "locale": "en",
    "rootPath": "/Users/calvin/src/php-test",
    "rootUri": "file:///Users/calvin/src/php-test",
    "capabilities": {
        "workspace": {
            "applyEdit": true,
            "workspaceEdit": {
                "documentChanges": true,
                "resourceOperations": [
                    "create",
                    "rename",
                    "delete"
                ],
                "failureHandling": "textOnlyTransactional",
                "normalizesLineEndings": true,
                "changeAnnotationSupport": {
                    "groupsOnLabel": true
                }
            },
            "configuration": true,
            "didChangeWatchedFiles": {
                "dynamicRegistration": true,
                "relativePatternSupport": true
            },
            "symbol": {
                "dynamicRegistration": true,
                "symbolKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25,
                        26
                    ]
                },
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "resolveSupport": {
                    "properties": [
                        "location.range"
                    ]
                }
            },
            "codeLens": {
                "refreshSupport": true
            },
            "executeCommand": {
                "dynamicRegistration": true
            },
            "didChangeConfiguration": {
                "dynamicRegistration": true
            },
            "workspaceFolders": true,
            "semanticTokens": {
                "refreshSupport": true
            },
            "fileOperations": {
                "dynamicRegistration": true,
                "didCreate": true,
                "didRename": true,
                "didDelete": true,
                "willCreate": true,
                "willRename": true,
                "willDelete": true
            },
            "inlineValue": {
                "refreshSupport": true
            },
            "inlayHint": {
                "refreshSupport": true
            },
            "diagnostics": {
                "refreshSupport": true
            }
        },
        "textDocument": {
            "publishDiagnostics": {
                "relatedInformation": true,
                "versionSupport": false,
                "tagSupport": {
                    "valueSet": [
                        1,
                        2
                    ]
                },
                "codeDescriptionSupport": true,
                "dataSupport": true
            },
            "synchronization": {
                "dynamicRegistration": true,
                "willSave": true,
                "willSaveWaitUntil": true,
                "didSave": true
            },
            "completion": {
                "dynamicRegistration": true,
                "contextSupport": true,
                "completionItem": {
                    "snippetSupport": true,
                    "commitCharactersSupport": true,
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "deprecatedSupport": true,
                    "preselectSupport": true,
                    "tagSupport": {
                        "valueSet": [
                            1
                        ]
                    },
                    "insertReplaceSupport": true,
                    "resolveSupport": {
                        "properties": [
                            "documentation",
                            "detail",
                            "additionalTextEdits"
                        ]
                    },
                    "insertTextModeSupport": {
                        "valueSet": [
                            1,
                            2
                        ]
                    },
                    "labelDetailsSupport": true
                },
                "insertTextMode": 2,
                "completionItemKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25
                    ]
                },
                "completionList": {
                    "itemDefaults": [
                        "commitCharacters",
                        "editRange",
                        "insertTextFormat",
                        "insertTextMode"
                    ]
                }
            },
            "hover": {
                "dynamicRegistration": true,
                "contentFormat": [
                    "markdown",
                    "plaintext"
                ]
            },
            "signatureHelp": {
                "dynamicRegistration": true,
                "signatureInformation": {
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "parameterInformation": {
                        "labelOffsetSupport": true
                    },
                    "activeParameterSupport": true
                },
                "contextSupport": true
            },
            "definition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "references": {
                "dynamicRegistration": true
            },
            "documentHighlight": {
                "dynamicRegistration": true
            },
            "documentSymbol": {
                "dynamicRegistration": true,
                "symbolKind": {
                    "valueSet": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7,
                        8,
                        9,
                        10,
                        11,
                        12,
                        13,
                        14,
                        15,
                        16,
                        17,
                        18,
                        19,
                        20,
                        21,
                        22,
                        23,
                        24,
                        25,
                        26
                    ]
                },
                "hierarchicalDocumentSymbolSupport": true,
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "labelSupport": true
            },
            "codeAction": {
                "dynamicRegistration": true,
                "isPreferredSupport": true,
                "disabledSupport": true,
                "dataSupport": true,
                "resolveSupport": {
                    "properties": [
                        "edit"
                    ]
                },
                "codeActionLiteralSupport": {
                    "codeActionKind": {
                        "valueSet": [
                            "",
                            "quickfix",
                            "refactor",
                            "refactor.extract",
                            "refactor.inline",
                            "refactor.rewrite",
                            "source",
                            "source.organizeImports"
                        ]
                    }
                },
                "honorsChangeAnnotations": false
            },
            "codeLens": {
                "dynamicRegistration": true
            },
            "formatting": {
                "dynamicRegistration": true
            },
            "rangeFormatting": {
                "dynamicRegistration": true
            },
            "onTypeFormatting": {
                "dynamicRegistration": true
            },
            "rename": {
                "dynamicRegistration": true,
                "prepareSupport": true,
                "prepareSupportDefaultBehavior": 1,
                "honorsChangeAnnotations": true
            },
            "documentLink": {
                "dynamicRegistration": true,
                "tooltipSupport": true
            },
            "typeDefinition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "implementation": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "colorProvider": {
                "dynamicRegistration": true
            },
            "foldingRange": {
                "dynamicRegistration": true,
                "rangeLimit": 5000,
                "lineFoldingOnly": true,
                "foldingRangeKind": {
                    "valueSet": [
                        "comment",
                        "imports",
                        "region"
                    ]
                },
                "foldingRange": {
                    "collapsedText": false
                }
            },
            "declaration": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "selectionRange": {
                "dynamicRegistration": true
            },
            "callHierarchy": {
                "dynamicRegistration": true
            },
            "semanticTokens": {
                "dynamicRegistration": true,
                "tokenTypes": [
                    "namespace",
                    "type",
                    "class",
                    "enum",
                    "interface",
                    "struct",
                    "typeParameter",
                    "parameter",
                    "variable",
                    "property",
                    "enumMember",
                    "event",
                    "function",
                    "method",
                    "macro",
                    "keyword",
                    "modifier",
                    "comment",
                    "string",
                    "number",
                    "regexp",
                    "operator",
                    "decorator"
                ],
                "tokenModifiers": [
                    "declaration",
                    "definition",
                    "readonly",
                    "static",
                    "deprecated",
                    "abstract",
                    "async",
                    "modification",
                    "documentation",
                    "defaultLibrary"
                ],
                "formats": [
                    "relative"
                ],
                "requests": {
                    "range": true,
                    "full": {
                        "delta": true
                    }
                },
                "multilineTokenSupport": false,
                "overlappingTokenSupport": false,
                "serverCancelSupport": true,
                "augmentsSyntaxTokens": true
            },
            "linkedEditingRange": {
                "dynamicRegistration": true
            },
            "typeHierarchy": {
                "dynamicRegistration": true
            },
            "inlineValue": {
                "dynamicRegistration": true
            },
            "inlayHint": {
                "dynamicRegistration": true,
                "resolveSupport": {
                    "properties": [
                        "tooltip",
                        "textEdits",
                        "label.tooltip",
                        "label.location",
                        "label.command"
                    ]
                }
            },
            "diagnostic": {
                "dynamicRegistration": true,
                "relatedDocumentSupport": false
            }
        },
        "window": {
            "showMessage": {
                "messageActionItem": {
                    "additionalPropertiesSupport": true
                }
            },
            "showDocument": {
                "support": true
            },
            "workDoneProgress": true
        },
        "general": {
            "staleRequestSupport": {
                "cancel": true,
                "retryOnContentModified": [
                    "textDocument/semanticTokens/full",
                    "textDocument/semanticTokens/range",
                    "textDocument/semanticTokens/full/delta"
                ]
            },
            "regularExpressions": {
                "engine": "ECMAScript",
                "version": "ES2020"
            },
            "markdown": {
                "parser": "marked",
                "version": "1.1.0"
            },
            "positionEncodings": [
                "utf-16"
            ]
        },
        "notebookDocument": {
            "synchronization": {
                "dynamicRegistration": true,
                "executionSummarySupport": true
            }
        }
    },
    "trace": "verbose",
    "workspaceFolders": [
        {
            "uri": "file:///Users/calvin/src/php-test",
            "name": "php-test"
        }
    ]
}


INFO      Ignored error: Creation of dynamic property LanguageServer\LanguageServer::$mapper is deprecated {"severity":8192,"file":"/Users/calvin/.vscode/extensions/zobo.php-intellisense-1.3.3/vendor/felixfbecker/advanced-json-rpc/lib/Dispatcher.php","line":53}

INFO      Ignored error: Creation of dynamic property LanguageServerProtocol\ServerCapabilities::$xdependenciesProvider is deprecated {"severity":8192,"file":"/Users/calvin/.vscode/extensions/zobo.php-intellisense-1.3.3/vendor/felixfbecker/language-server/src/LanguageServer.php","line":309}
INFO      Ignored error: Creation of dynamic property LanguageServerProtocol\ServerCapabilities::$experimental is deprecated {"severity":8192,"file":"/Users/calvin/.vscode/extensions/zobo.php-intellisense-1.3.3/vendor/felixfbecker/language-server/src/LanguageServer.php","line":310}
INFO      Ignored error: Creation of dynamic property LanguageServerProtocol\ServerCapabilities::$inlineValueProvider is deprecated {"severity":8192,"file":"/Users/calvin/.vscode/extensions/zobo.php-intellisense-1.3.3/vendor/felixfbecker/language-server/src/LanguageServer.php","line":314}

[Trace - 2:56:42 PM] Received response 'initialize - (0)' in 350ms.
Result: {
    "capabilities": {
        "textDocumentSync": 1,
        "hoverProvider": true,
        "completionProvider": {
            "resolveProvider": false,
            "triggerCharacters": [
                "$",
                ">"
            ]
        },
        "signatureHelpProvider": {
            "triggerCharacters": [
                "(",
                ","
            ]
        },
        "definitionProvider": true,
        "typeDefinitionProvider": null,
        "implementationProvider": null,
        "referencesProvider": true,
        "documentHighlightProvider": null,
        "documentSymbolProvider": true,
        "workspaceSymbolProvider": true,
        "codeActionProvider": null,
        "codeLensProvider": null,
        "documentFormattingProvider": null,
        "documentRangeFormattingProvider": null,
        "documentOnTypeFormattingProvider": null,
        "renameProvider": null,
        "executeCommandProvider": null,
        "xworkspaceReferencesProvider": true,
        "xdefinitionProvider": true,
        "dependenciesProvider": null,
        "xdependenciesProvider": true,
        "experimental": {
            "xevaluatableExpressionProvider": true
        },
        "inlineValueProvider": true
    },
    "serverInfo": null
}


[Trace - 2:56:42 PM] Sending notification 'initialized'.
Params: {}


[Trace - 2:56:42 PM] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///Users/calvin/src/php-test/index.php",
        "languageId": "php",
        "version": 1,
        "text": "<?php\n\nnamespace WebSocket\\Trait;\n\nuse WebSocket\\Message\\{\n    Binary,\n    Close,\n    Ping,\n    Pong,\n    Text\n};"
    }
}


[Trace - 2:56:42 PM] Sending notification 'workspace/didChangeConfiguration'.
Params: {
    "settings": {
        "php": {
            "suggest": {
                "basic": true
            },
            "validate": {
                "enable": true,
                "executablePath": null,
                "run": "onSave"
            },
            "debug": {
                "executablePath": null,
                "ideKey": "vsc"
            },
            "memoryLimit": "4095M",
            "executablePath": "/opt/local/bin/php82",
            "files": {
                "exclude": []
            }
        }
    }
}


[Trace - 2:56:42 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "OK!"
}


[Info  - 2:56:42 PM] OK!
[Trace - 2:56:42 PM] Received request 'workspace/configuration - (1)'.
Params: {
    "items": [
        {
            "section": "php.files.exclude"
        }
    ]
}


[Trace - 2:56:42 PM] Sending response 'workspace/configuration - (1)'. Processing request took 0ms
Result: [
    []
]


[Trace - 2:56:42 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///Users/calvin/src/php-test/index.php",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 4,
                    "character": 23
                },
                "end": {
                    "line": 4,
                    "character": 23
                }
            },
            "severity": 1,
            "source": "php",
            "message": "'}' expected."
        },
        {
            "range": {
                "start": {
                    "line": 4,
                    "character": 23
                },
                "end": {
                    "line": 4,
                    "character": 23
                }
            },
            "severity": 1,
            "source": "php",
            "message": "';' expected."
        },
        {
            "range": {
                "start": {
                    "line": 5,
                    "character": 10
                },
                "end": {
                    "line": 5,
                    "character": 10
                }
            },
            "severity": 1,
            "source": "php",
            "message": "';' expected."
        },
        {
            "range": {
                "start": {
                    "line": 5,
                    "character": 10
                },
                "end": {
                    "line": 5,
                    "character": 10
                }
            },
            "severity": 1,
            "source": "php",
            "message": "Unexpected ','"
        },
        {
            "range": {
                "start": {
                    "line": 6,
                    "character": 9
                },
                "end": {
                    "line": 6,
                    "character": 9
                }
            },
            "severity": 1,
            "source": "php",
            "message": "';' expected."
        },
        {
            "range": {
                "start": {
                    "line": 6,
                    "character": 9
                },
                "end": {
                    "line": 6,
                    "character": 9
                }
            },
            "severity": 1,
            "source": "php",
            "message": "Unexpected ','"
        },
        {
            "range": {
                "start": {
                    "line": 7,
                    "character": 8
                },
                "end": {
                    "line": 7,
                    "character": 8
                }
            },
            "severity": 1,
            "source": "php",
            "message": "';' expected."
        },
        {
            "range": {
                "start": {
                    "line": 7,
                    "character": 8
                },
                "end": {
                    "line": 7,
                    "character": 8
                }
            },
            "severity": 1,
            "source": "php",
            "message": "Unexpected ','"
        },
        {
            "range": {
                "start": {
                    "line": 8,
                    "character": 8
                },
                "end": {
                    "line": 8,
                    "character": 8
                }
            },
            "severity": 1,
            "source": "php",
            "message": "';' expected."
        },
        {
            "range": {
                "start": {
                    "line": 8,
                    "character": 8
                },
                "end": {
                    "line": 8,
                    "character": 8
                }
            },
            "severity": 1,
            "source": "php",
            "message": "Unexpected ','"
        },
        {
            "range": {
                "start": {
                    "line": 9,
                    "character": 8
                },
                "end": {
                    "line": 9,
                    "character": 8
                }
            },
            "severity": 1,
            "source": "php",
            "message": "';' expected."
        },
        {
            "range": {
                "start": {
                    "line": 10,
                    "character": 0
                },
                "end": {
                    "line": 10,
                    "character": 0
                }
            },
            "severity": 1,
            "source": "php",
            "message": "Unexpected '}'"
        }
    ]
}


[Trace - 2:56:42 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "1 files total (unfiltered 1)"
}


[Info  - 2:56:42 PM] 1 files total (unfiltered 1)
[Trace - 2:56:42 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "Indexing project for definitions and static references"
}


[Info  - 2:56:42 PM] Indexing project for definitions and static references
[Trace - 2:56:42 PM] Received request 'window/workDoneProgress/create - (2)'.
Params: {
    "token": "pls-66edb75aa4f05"
}


[Trace - 2:56:42 PM] Sending response 'window/workDoneProgress/create - (2)'. Processing request took 0ms
No result returned.


[Trace - 2:56:42 PM] Received notification '$/progress'.
Params: {
    "token": "pls-66edb75aa4f05",
    "value": {
        "kind": "begin",
        "title": "Indexing project for definitions and static references",
        "message": "0/1 files",
        "percentage": 0
    }
}


[Trace - 2:56:42 PM] Received notification '$/progress'.
Params: {
    "token": "pls-66edb75aa4f05",
    "value": {
        "kind": "report",
        "message": "0/1 files",
        "percentage": 0
    }
}


[Trace - 2:56:42 PM] Received notification '$/progress'.
Params: {
    "token": "pls-66edb75aa4f05",
    "value": {
        "kind": "end",
        "message": null
    }
}


[Trace - 2:56:42 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "Indexing project for dynamic references"
}


[Info  - 2:56:42 PM] Indexing project for dynamic references
[Trace - 2:56:42 PM] Received request 'window/workDoneProgress/create - (3)'.
Params: {
    "token": "pls-66edb75aa5670"
}


[Trace - 2:56:42 PM] Sending response 'window/workDoneProgress/create - (3)'. Processing request took 0ms
No result returned.


[Trace - 2:56:42 PM] Received notification '$/progress'.
Params: {
    "token": "pls-66edb75aa5670",
    "value": {
        "kind": "begin",
        "title": "Indexing project for dynamic references",
        "message": "0/1 files",
        "percentage": 0
    }
}


[Trace - 2:56:42 PM] Received notification '$/progress'.
Params: {
    "token": "pls-66edb75aa5670",
    "value": {
        "kind": "report",
        "message": "0/1 files",
        "percentage": 0
    }
}


[Trace - 2:56:42 PM] Received notification '$/progress'.
Params: {
    "token": "pls-66edb75aa5670",
    "value": {
        "kind": "end",
        "message": null
    }
}


[Trace - 2:56:42 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "0 Packages"
}


[Info  - 2:56:42 PM] 0 Packages
[Trace - 2:56:42 PM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "All 1 PHP files parsed in 0 seconds. 192 MiB allocated."
}


[Info  - 2:56:42 PM] All 1 PHP files parsed in 0 seconds. 192 MiB allocated.
[Trace - 2:56:42 PM] Sending request 'textDocument/documentSymbol - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/calvin/src/php-test/index.php"
    }
}


[Trace - 2:56:42 PM] Received response 'textDocument/documentSymbol - (1)' in 2ms.
Result: [
    {
        "name": "WebSocket\\Trait",
        "kind": 3,
        "location": {
            "uri": "file:///Users/calvin/src/php-test/index.php",
            "range": {
                "start": {
                    "line": 2,
                    "character": 0
                },
                "end": {
                    "line": 2,
                    "character": 26
                }
            }
        },
        "containerName": "WebSocket"
    }
]


[Trace - 2:56:44 PM] Sending request 'textDocument/documentSymbol - (2)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/calvin/src/php-test/index.php"
    }
}


[Trace - 2:56:44 PM] Received response 'textDocument/documentSymbol - (2)' in 2ms.
Result: [
    {
        "name": "WebSocket\\Trait",
        "kind": 3,
        "location": {
            "uri": "file:///Users/calvin/src/php-test/index.php",
            "range": {
                "start": {
                    "line": 2,
                    "character": 0
                },
                "end": {
                    "line": 2,
                    "character": 26
                }
            }
        },
        "containerName": "WebSocket"
    }
]


[Trace - 2:56:44 PM] Sending notification '$/setTrace'.
Params: {
    "value": "verbose"
}


[Trace - 2:56:44 PM] Sending notification '$/setTrace'.
Params: {
    "value": "verbose"
}


@zobo
Copy link
Owner

zobo commented Sep 28, 2024

Strange, as this has been supported since 2017 or so... But I do see the diagnostics error, has to come from tolerant-php-parser. will have another look

@zobo
Copy link
Owner

zobo commented Sep 28, 2024

I found the issue. "Binary" is regarded as a reserved word here https://github.com/microsoft/tolerant-php-parser/blob/main/src/TokenStringMaps.php#L103 but I think this is invalid. I'll open an issue with upstream.

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

2 participants