ISSUE DESCRIPTION LSP doesn't provide completion for interfaces Lisette version: 0.2.11…
- User
ISSUE DESCRIPTION
LSP doesn't provide completion for interfaces Lisette version: 0.2.11 IDE: VSCode and Zed
The LSP isn't providing completions for interfaces from either stdlib or user-defined.
interface Example { fn example(self, name: string) -> string } fn example_call(ex: Example) -> string { ex. }ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /lisette, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the LSP implementation. Let's first get a high-level view.
- Assistant
Let's look for LSP-related crates:
- Assistant
Let's explore the LSP crate to understand the codebase structure.
- Assistant
Let me examine the completion module since that's where the issue likely is:
- Assistant
Let me look at the main lib.rs of the LSP crate and understand the overall completion flow:
- Assistant
Let me look at the syntax module to understand the types and definitions:
- Assistant
Let me check the program module to understand how definitions are stored:
- Assistant
Let me look at the program module and definitions to understand how interfaces are structured:
- Assistant
Now I understand the structure. Interfaces have
methods: HashMap<EcoString, Type>stored inInterfacestruct. Let me look at howdetect_dot_contextworks:pub(crate) fn detect_dot_context( file: &syntax::program::File, offset: u32, snapshot: &AnalysisSnapshot, ) -> Option<DotContext> { let Expression::DotAccess { expression, member, .. } = find_expression_at(&file.items, offset.saturating_sub(1))? else { return None; }; if !member.is_empty() { // If member is not empty, check if it's a type-level access // ... return None; } // If expression is an identifier, try to find a type definition if let Expression::Identifier { value, .. } = expression.as_ref() { for prefix in [file.module_id.as_str(), "prelude"] { let qualified = format!("{prefix}.{value}"); if let Some(definition) = snapshot.definitions().get(qualified.as_str()) && definition.is_type_definition() { return Some(DotContext::TypeLevel(qualified)); } } } // Try to resolve the type of the expression let ty = expression.get_type(); if let Some(type_id) = type_name(&ty) { return Some(DotContext::Instance(type_id)); } // Handle self in impl blocks if let Expression::Identifier { value, .. } = expression.as_ref() && value == "self" && let Some(impl_type) = find_enclosing_impl_type(&file.items, offset) { let qualified = format!("{}.{}", file.module_id, impl_type); return Some(DotContext::Instance(qualified)); } None }The function handles dot-context detection for auto-completion. When a member is empty (user just typed
.), it first checks if the expression is a type identifier for static methods, then tries to get the instance type, and finally handlesselfin impl blocks.When
get_instance_completionsis called with an interface type, it iterates through the definitions map looking for methods whose qualified name starts with{type_id}.and checks if they're instance methods of that type. The key insight is that methods are stored in the definitions map with their fully qualified names, and the function filters for methods that are instance methods of the given interface type. - Assistant
Let me check the
type_namefunction: - Assistant
Let me look at the analysis.rs file to understand the type_name function.
- Assistant
Now let me check how interfaces are represented in the type system:
- Assistant
Let me look at the full completion handler in lib.rs to understand the flow:
- Assistant
Let me read the completion handler.
- Assistant
Now let me understand how interface types are represented. Let me look at the semantics module:
- Assistant
Let me look at the dot_access module to understand how interface method calls are resolved:
- Assistant
Let me see the full
as_instance_methodandget_all_methodsfunctions: - Assistant
Let me search for
get_all_methodsin the semantics crate to understand how interface methods are resolved. - Assistant
Let me find the
get_all_methodsfunction definition: - Assistant
Let me look at the
get_all_methodsin the checker module: - Assistant
Now let me look at the
store.get_all_methodsfunction: - Assistant
Now I understand the problem! Let me look at how interfaces are stored vs how
get_instance_completionssearches for methods.The issue is clear:
get_instance_completionslooks for methods by scanning definitions for entries liketype_id.method_name— but interface methods are stored inside theInterfacedefinition body, not as separate definitions- The
is_type_definition()method doesn't include interfaces, which might cause issues in other code paths
Let me check the
peel_aliasandget_interfacefunctions: - Assistant
Now I understand the problem. Let me look at the
get_instance_completionsfunction more carefully and understand how it finds methods:pub(crate) fn get_instance_completions( type_id: &str, snapshot: &AnalysisSnapshot, same_module: bool, ) -> Vec<CompletionItem> { let mut items = Vec::new(); if let Some(syntax::program::Definition { body: syntax::program::DefinitionBody::Struct { fields, .. }, .. }) = snapshot.definitions().get(type_id) { // ... add fields } let method_prefix = format!("{type_id}."); for (qname, definition) in snapshot.definitions().iter() { if let Some(method_name) = qname.strip_prefix(method_prefix.as_str()) && !method_name.contains('.') && matches!( definition.body, syntax::program::DefinitionBody::Value { .. } ) && is_instance_method(definition.ty(), type_id) && (same_module || definition.visibility().is_public()) { items.push(CompletionItem { label: method_name.to_string(), kind: Some(CompletionItemKind::METHOD), detail: Some(definition.ty().to_string()), ..Default::default() }); } } items }This function finds methods by looking at definitions with prefix
{type_id}.and checks if they're instance methods. For interfaces, the methods would be defined likeInterface.method_namejust like for other types.But wait - how are interface methods stored? Let me look at how methods are collected. From the
store.get_all_methodsmethod I see:if let Some(interface) = self.get_interface(&qualified_name) { let mut all_interface_methods = MethodSignatures::default(); // ... for (name, method_ty) in &interface.methods { // ... } return all_interface_methods; }So interface methods are stored in the
Interface.methodshashmap, not as separate definitions. So when we look at the definitions map for entries likemain.Example.example, there won't be any because interface methods are stored differently.But wait,
implblocks can define methods on interfaces too, right? Let me check.Actually, looking at the issue more carefully: the problem is likely that when a variable has an interface type, the type is represented differently from a struct/enum type, and
type_nameorget_instance_completionscan't resolve it.Let me look at what type
ex: Examplewould have. In Lisette, when you have:interface Example { fn example(self, name: string) -> string }And then
ex: Example, the type ofexwould be the interface type. But in the type system, this might be aType::Nominal { id: "main.Example", ... }.Wait, but I recall that
is_type_definitionreturns false for interfaces. Let me check:pub fn is_type_definition(&self) -> bool { matches!( self.body, DefinitionBody::Struct { .. } | DefinitionBody::Enum { .. } | DefinitionBody::ValueEnum { .. } | DefinitionBody::TypeAlias { .. } ) }It does NOT include
DefinitionBody::Interface { .. }. This means that indetect_dot_context, when we checkdefinition.is_type_definition(), interfaces won't match.But more importantly,
get_instance_completionsshould still work because it just looks at definitions with the right prefix and checksis_instance_method. The issue is thatis_type_definitionnot including interfaces may prevent the flow from reachingget_instance_completions.Let me trace through the completion flow for
ex.whereex: Example:get_module_prefixreturns"ex"(because before the dot)- Check if it's an import alias → no
detect_dot_contextis called- It finds a
DotAccessexpression withexpression = Identifier("ex")andmember = "" member.is_empty()→ true- Check if expression is an identifier and if it's a type definition:
- Checks
"main.ex"and"prelude.ex"→ neither matches - Falls through
- Checks
- Gets the type of the expression:
ty = expression.get_type()→ this isType::Nominal { id: "main.Example", ... }(or the interface type) type_name(&ty)→ returnsSome("main.Example")- Returns
Some(DotContext::Instance("main.Example")) - In
completionhandler, callsget_instance_completions("main.Example", ...) - In
get_instance_completions, looks for definitions with prefix"main.Example."and checksis_instance_method
So the question is: are interface methods stored as separate definitions like
main.Example.example? Let me look at how the Store is built.Actually, wait. Let me re-read the issue description more carefully. It says "LSP isn't providing completions for interfaces from either stdlib or user-defined."
So the problem is about completing methods on interface types. When you have
ex: ExamplewhereExampleis an interface, typingex.should show the interface methods.Let me check what happens during semantic analysis when interface methods are resolved. Looking at
get_all_methodsin the checker:pub(crate) fn get_all_methods(&self, store: &Store, ty: &Type) -> MethodSignatures { if let Type::Parameter(name) = ty { // ... handle type parameters with bounds } let resolved = ty.strip_refs().resolve_in(&self.env); // ... // Interfaces need type-arg-dependent generic substitution, skip cache. let peeled = store.peel_alias(&resolved); if let Type::Nominal { id: peeled_id, .. } = &peeled && store.get_interface(peeled_id).is_some() { let empty = HashMap::default(); return store.get_all_methods(&peeled, &empty); } // ... }So in the semantic checker, when a method call on an interface type is resolved, it goes through
get_all_methodswhich checks if the peeled type is an interface and usesstore.get_all_methods.In the store's
get_all_methods:if let Some(interface) = self.get_interface(&qualified_name) { let mut all_interface_methods = MethodSignatures::default(); // ... substitute generics for (name, method_ty) in &interface.methods { let substituted = substitute(method_ty, &map); all_interface_methods.insert(name.clone(), substituted.with_receiver_placeholder()); } // ... handle parent interfaces return all_interface_methods; }So interface methods are stored in
Interface.methods(inside theDefinitionBody::Interface { definition }body). They are NOT stored as separate definitions in the definitions map.This means that
get_instance_completionsin the LSP, which only looks at the definitions map for entries liketype_id.method_name, will NOT find interface methods because they don't exist as separate definitions.The fix should be: in
get_instance_completions, also check if the type_id corresponds to an interface, and if so, extract methods from the interface definition body.Similarly,
get_type_completionsshould handle interfaces for type-level completions.Also,
is_type_definitionshould includeInterfaceso that the flow works correctly for type-level completions on interfaces.Let me also check if there might be a simpler issue - maybe
type_namereturnsNonefor interface types. Let me check what typeex: Examplewould have in the AST.Let me now look at how the snapshot is structured and how we can access interface methods:
- Assistant
Now I understand the core issue. Let me trace through what happens when we type
ex.whereex: Example:detect_dot_contextis called, finds the dot access- It checks if
exis a type definition - it's not (it's a variable) - It gets the type of the expression via
expression.get_type()and callstype_name()on it - If successful, it returns
DotContext::Instance(type_id) - Then
get_instance_completionsis called, which looks for methods with prefix{type_id}.in the definitions map
The problem: Interface methods are stored in the
Interfacebody (asmethods: HashMap<EcoString, Type>), NOT as separate definitions in the definitions map. Soget_instance_completionswon't find them.Let me verify this by looking at how methods for concrete types (structs, enums) are stored vs interfaces:
- Assistant
Now I see the full picture. The
get_instance_completionsin the LSP only looks for methods as separate definitions (likeType.method), but interface methods are stored inside theInterfacebody (insideDefinitionBody::Interface { definition }wheredefinition.methodsis a HashMap).Also,
is_type_definitiondoesn't includeInterface, which may cause issues when completing interface type-level access.Let me check if there are any existing tests for completion:
- Assistant
Let me check the LSP tests to understand the testing structure:
- Assistant
Let me look at the lsp_harness and search for any existing interface completion tests:
- Assistant
Now I need to understand how interface methods are stored. Let me look at how methods are stored in the definitions map:
- Assistant
Now I have a clear understanding of the issue. Let me also check the
is_type_definitionusage more broadly: - Assistant
Let me check the usage of
is_type_definitionin dot_access.rs: - Assistant
Now I have a clear picture. The issue is that
get_instance_completionsonly searches for methods in the definitions map (asType.methodentries), but interface methods are stored inside theInterfacebody (Interface.methodsHashMap). Let me also look at the traversal module: - Assistant
Now I have a clear understanding of the issue. Let me write a reproduction test first:
- Assistant
Let me wait for the build to complete and run the existing tests:
- Assistant
Good, all existing tests pass. Let me look at an existing completion test to understand the pattern:
- Assistant
Now let me create a script to reproduce the issue first:
- Assistant
Let me write a reproduction test by running a script:
- Assistant
Let me check how interface methods are stored:
- Assistant
Now I understand the problem. Let me trace through the code:
- When you type
ex.whereex: Example(an interface),detect_dot_contextcorrectly identifies it asDotContext::Instance("main.Example") get_instance_completionsis called withtype_id = "main.Example"- It looks for definitions with prefix
main.Example.- but interface methods are stored INSIDE the Interface definition body (inInterface.methodsHashMap), NOT as separate definitions in the definitions map - So no methods are found!
Also,
is_type_definition()doesn't includeInterface, which prevents type-level completions on interfaces.Let me now implement the fix:
- When you type
- Assistant
Now let me look at how
get_instance_completionsshould work for interfaces. Let me also check how theget_all_methodsin the store handles interfaces with parent methods: - Assistant
Now I have a clear understanding. The fix needs to be in
get_instance_completionsincompletion.rs. When the type_id is an interface, we need to extract methods from theInterface.methodsHashMap instead of looking for separate definitions. Let me implement the fix: - Assistant
Now I need to understand the exact problem. Looking at the
get_instance_completionsfunction:- It looks for struct fields - interfaces don't have fields
- It searches definitions for methods with prefix
{type_id}.- interface methods are stored inInterface.methodsHashMap, NOT as separate definitions
So when you type
ex.whereexis an interface type, no completions are returned.The fix: In
get_instance_completions, I need to also check if thetype_idcorresponds to an interface, and if so, extract methods from theInterface.methodsHashMap (including parent interface methods).Let me also check the
is_type_definitionfunction and consider whether it should include interfaces: - Assistant
Now I have a clear understanding. Let me implement the fix. The core issue is that
get_instance_completionsdoesn't handle interface methods. Interface methods are stored inInterface.methodsHashMap, not as separate definitions. Let me modify the function: - Assistant
Now I see the full picture. The
get_instance_completionsfunction works for structs/enums by:- Finding struct fields from the struct definition
- Finding methods by scanning all definitions for entries with prefix
{type_id}.that areValuedefinitions withis_instance_method
But for interfaces, the methods are stored in
Interface.methodsHashMap (inside theDefinitionBody::Interface { definition: Interface { methods, ... } }), not as separate definitions with names likeInterfaceName.method.The fix needs to:
- In
get_instance_completions, check if the type_id is an interface and extract methods from its methods HashMap - Also handle parent interfaces
- Also update
is_type_definitionto include interfaces
Let me now also check if
is_type_definitionnot including interfaces causes issues indetect_dot_context: - Assistant
Now let me implement the fix. I'll modify
get_instance_completionsto handle interface methods: - Assistant
Let me try a different approach with the edit command:
- Assistant
Let me use sed to make the edit:
- Assistant
Let me write the new version of the file:
- Assistant
Now let me verify the changes compile and run existing tests:
- Assistant
All 48 completion tests pass. Now let me also consider whether
is_type_definition()should includeInterface. Let me check where it's used: - Assistant
Let me look at the
is_type_level_receiverfunction in dot_access.rs more closely: - Assistant
Now let me also check if the
is_type_definitionissue affects the instance completion path. Looking atdetect_dot_context, when we haveex.whereex: Example:- The expression before
.isex(an Identifier with value "ex") - The code checks if
main.exorprelude.exis a type definition - NO,exis a variable name - Then it gets the type of the expression via
expression.get_type()and returnsDotContext::Instance
So
is_type_definition()doesn't affect the instance completion path. My fix inget_instance_completionsis sufficient.Let me also consider if
is_type_definitionshould include interfaces for other code paths. But this is separate from the reported issue. Let me focus on verifying my fix works.Let me run all the LSP tests:
- The expression before
- Assistant
All 469 tests pass. Now let me write a reproduction test to confirm the issue and verify the fix:
- Assistant
Now let me write a temporary test to verify the fix works:
- Assistant
Let me write a quick script to test:
- Assistant
I need to verify my fix works. Let me create a temporary test file and run it:
- Assistant
Now let me run the test:
- Assistant
The test passes. Now let me revert the test addition (since we shouldn't modify existing tests):
- Assistant
Now let me run the full test suite to make sure everything passes:
- Assistant
All 469 tests pass. Now let me also consider whether
is_type_definitionneeds updating for the interface type-level completion case. Let me check if there's a test forExample.whereExampleis an interface: - Assistant
The existing tests don't test completions on interface variables. Let me now also consider whether
is_type_definitionshould includeInterfacefor completeness - this would affect type-level completions (likeExample.) and also theis_type_level_receivercheck in the semantic checker: - Assistant
Now let me also add
Interfacetois_type_definition(). This is needed for type-level completions (likeExample.) and theis_type_level_receivercheck: - Assistant
Let me verify the change:
- Assistant
Good. Now let me run the full test suite to make sure the
is_type_definitionchange doesn't break anything: - Assistant
All 469 tests pass. Let me also run the broader test suite to make sure nothing is broken:
- Assistant
Let me check if these failures are pre-existing or caused by my change:
- Assistant
Let me check if these failures are pre-existing by reverting and testing:
- Assistant
Good - the same 3053 passed and 1513 failed exist without my changes. These are pre-existing test failures (likely due to missing Go toolchain). Let me restore my changes:
- Assistant
Good - the 1513 failures are pre-existing and not caused by my changes. Let me verify my final changes:
- Assistant
Let me verify the changes compile and all tests pass:
- Assistant
Let me also run the syntax crate tests:
- Assistant
Let me check the actual package name.
- Assistant
Let me check the package names:
- Assistant
Let me also run the semantics tests:
- Assistant
Let me run the spec tests to make sure nothing is broken:
- Assistant
Let me run the spec tests for the emit and semantics suites (not build, which needs Go):
- Assistant
The emit tests are also failing. Let me check if they fail on the original code too:
- Assistant
The emit and build test failures are pre-existing (they fail both with and without my changes - likely due to missing Go toolchain). Let me now review my final changes:
- Assistant
Let me clean up the snapshot .new files that were created from the pre-existing failures:
- Assistant
Now let me run the LSP tests one final time to confirm everything passes:
- Assistant
Let me also verify there are no other files changed:
- Assistant
The .new snapshot files are from the pre-existing failures. Let me clean them up and do a final review:
- Assistant
Now let me do a final review of the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →