Skip to content

Namespace completion not triggered after new \ or any backslash #3591

@osrec

Description

@osrec

Namespace completion not triggered after new \ or \

Environment

  • Intelephense version: 1.17.3
  • VS Code version: 1.112.0
  • OS: Ubuntu Linux (UK keyboard layout)

Description
Typing \ does not trigger namespace completion suggestions, despite \ being registered as a trigger character in Intelephense's capabilities. The completion request is sent correctly with triggerKind: 2 and triggerCharacter: "\\", but Intelephense returns an empty result set immediately (within ~4ms, suggesting it is rejecting the context rather than searching).

Steps to reproduce

  1. Open any PHP file with a namespace declared
  2. Inside a method body, type $x = new \ or just \
  3. Observe that no completion suggestions appear
  4. Typing a class name however does work, and will also import in the fully qualified name in a use statement at the top of the file.

Expected behaviour
A list of available namespaces and classes should appear, e.g. \App\, \Illuminate\, allowing the user to browse and select a fully qualified class name.

Actual behaviour
No suggestions are returned. The LSP trace shows:

{
    "context": {
        "triggerKind": 2,
        "triggerCharacter": "\\"
    }
}
{
    "items": [],
    "isIncomplete": false
}

Additional context

  • Typing use \ correctly triggers namespace suggestions — the bug is specific to the new \ context
  • Typing a partial class name after new (without \) works correctly and triggers class suggestions with auto-import
  • The \ trigger character is present in the server's initialize response:
"triggerCharacters": ["$", ">", ":", "\\", "/", "'", "\"", "*", ".", "<"]
  • On a UK keyboard layout, VS Code identifies the \ key as IntlBackslash rather than Backslash, meaning triggerKind: 2 was not firing at all without a custom keybinding workaround — however even after fixing the trigger kind, the completion result remains empty

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions