Skip to content

Fails to infer the type of my_instance = SomeClass.new #3407

@eliwang2025-ws

Description

@eliwang2025-ws

Description

Ruby LSP Information

VS Code Version

1.99.3

Ruby LSP Extension Version

0.9.16

Ruby LSP Server Version

0.23.14

Ruby LSP Add-ons

Ruby Version

3.4.2

Ruby Version Manager

rbenv

Installed Extensions

Click to expand
  • ruby-lsp (0.9.16)

Ruby LSP Settings

Click to expand
Workspace
{}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "featureFlags": {},
  "sigOpacityLevel": "1"
}

Reproduction steps

Create an empty ruby file, put

class SomeClass
  def print_debug_info
  end
end

sc = SomeClass.new

Hover the mouse over the variable sc I don't see its type. And type sc. in the following lines, print_debug_info is not among the auto suggestions, while method_missing is, along with a bunch of others.

Is this something wrong with my configuration? I did a bit of searching, noticed that when I type SomeClass.new, the suggestion comes from class.rbs, where the .new method is marked untyped. And I talked to Google Gemini a bit, it replied that the .rbs system lacks generics for the moment, something like Class<T> in Java, therefore the return value can only be untyped for the moment.

Not sure if this is true, but should ruby-lsp make some workaround about this? It's just everyday life.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions