Improvements on empty rescue and unused params in abstract method#1
Open
antondalgren wants to merge 34 commits into
Open
Improvements on empty rescue and unused params in abstract method#1antondalgren wants to merge 34 commits into
antondalgren wants to merge 34 commits into
Conversation
Author
|
Maybe the empty rescue part should be a linting issue rather than a LSP issue? |
When hovering over a local variable assigned from a method call (e.g. result = Resolver.resolve("foo")), the LSP showed no type because TypeCollector only infers types from literals and .new calls. This adds a fallback: when a local's type is empty, find its assignment value and call infer_type_ref on it. This is done at the use sites (hover, completion,
go-to-definition) rather than inside TypeCollector, avoiding the infinite recursion that a previous attempt caused.
Slice[127u8, 0u8, 0u8, 1u8] showed no type because Slice.[] is a macro, not a method, so method lookup found no candidates. This adds a fallback that treats class-level [] calls as constructors, inferring the type from the receiver and the element type from the first argument (e.g. Slice(UInt8)). Also fixed number_literal_type which used symbol comparisons (:u8) instead of enum predicates (.u8?) against Crystal::NumberKind — meaning all suffixed number literals were incorrectly inferred as Int32.
Add an inference callback to TypeCollector so block params get types when the receiver was assigned from a method call (e.g. results.each).
Look up the method's block arg type restriction (e.g. & : (String, Int32) -> Nil) and use it to type block parameters.
When is_a? narrowing was applied to a variable not yet in the type env, the previous value was saved as the narrowed type instead of nil. On unapply, the variable remained set instead of being removed, causing type leaks through DefIvarCollector which processes all method bodies with a shared env.
fill_ivars_from_getters walks the superclass and include chain so child structs/classes inherit ivar types from parent getters. Also resolves hover for getter variable names, ivar-backed initialize params, and inherited instance variables that have no local assignment.
Crystal::Arg location starts at @ but name_size only counts the name without the prefix, causing the last character to be missed on hover.
Create a synthetic file scope when no enclosing def exists so that
build_type_env and TypeCollector run on top-level code. Also infer
block param type for ClassName.new { |p| } as the receiver type.
- Infer type from default value in getter/property macros (e.g., getter name = "" now expands with : String return type) - Map crystal-macro: URIs back to original source for go-to-definition - Show return type in hover when return_type_ref is missing but string is set - Fall back to infer_type_ref for Var receivers in call resolution
- Index classes/methods inside top-level {% if %} blocks (was skipped)
- Expand both then and else branches of macro-if during indexing
- Resolve typed proc literal parameters (e.g., ip_str : String)
- Add enclosing_proc_def to NodeFinder and pass to find_definitions
The # separator for instance methods (e.g. Foo#bar) was breaking Crystal syntax highlighting inside ```crystal code fences, since # starts a comment in Crystal. Changed to use . for all method signatures so parameter names and types are properly colored.
…lution
- Infer Proc type from proc literal assignments (e.g. handler = ->(x : Int32) { x })
- Handle ProcNotation in type annotations (e.g. Int32 -> String)
- Resolve Self block param types to the actual owner class
- Extract block param types from yield expressions in method bodies
using a two-pass approach: first pass during indexing resolves what it
can, second pass after all files are indexed resolves cross-file
dependencies (e.g. String.build -> String::Builder.build)
Drop "implicit generic return type" test (duplicate of explicit forall T variant) and "narrows type with && and is_a?" test (combination of individually tested narrowing patterns).
Display 0-param instance methods with return types as `name : Type` instead of `def Owner.name : Type`, matching how properties/getters are conventionally read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.