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 then locate the relevant LSP completion code.
Assistant
Let me look for LSP-related files specifically.
Assistant
Let me read the completion.rs file first to understand how completions work:
Assistant
Now let me look at the main LSP file to see how completions are requested:
Assistant
Now let me look at the
get_instance_completionsfunction more closely and thedetect_dot_contextfunction to understand how the completion for interface types should work:Assistant
Let me look at the test file for LSP to understand how tests are structured and find interface-related tests:
Assistant
Let me check the existing LSP tests more to understand how completion tests are structured:
Assistant
Let me look at an example completion test to understand the pattern:
Assistant
Good. Now let me check for any existing interface-related completion tests:
Assistant
Let me look at the issue more closely. The problem is that when we have an interface type like
Exampleand we try to completeex.(whereex: Example), no completions are provided. Let me trace through the code flow:Assistant
Let me look at
get_instance_completions- this function only handles struct fields. Let me check if there's special handling needed for interfaces:Assistant
Now I see the issue! The
get_instance_completionsfunction only looks for struct fields but doesn't handle interface methods. Let me see the rest of the function:Assistant
Now I understand the problem. The
get_instance_completionsfunction looks for methods defined on the type using the pattern{type_id}.{method_name}and checks if they're instance methods. However, for interfaces, methods are defined differently - they're part of the interface definition itself, not as separate value definitions.Let me look at how interfaces are defined in the syntax:
Assistant
Now I understand the data structure. The
Interfacestruct has amethodsfield that contains aHashMap<EcoString, Type>mapping method names to their types. Let me verify this by looking at how interfaces are handled elsewhere:Assistant
So the issue is NOT that interface methods are missing from the definitions - they should be there. The problem might be in how
get_instance_completionsresolves the type when dealing with interface types.Let me look at
is_instance_methodto understand what it checks:fn is_instance_method(ty: &syntax::types::Type, type_id: &str) -> bool { let func_ty = match ty { syntax::types::Type::Forall { body, .. } => body, other => other, }; match func_ty { syntax::types::Type::Function { params, .. } if !params.is_empty() => { type_name(¶ms[0]).is_some_and(|name| name == type_id) } _ => false, } }This function checks if the first parameter of a function type matches the
type_id. For interface methods, the first parameter should be the interface type itself (likeself: Example).Let me trace through what happens when we have:
interface Example { fn example(self, name: string) -> string } fn example_call(ex: Example) -> string { ex. }detect_dot_contextis called withex.- It finds the
DotAccessexpression withexpressionbeingex expression.get_type()should return the type ofex, which isExampletype_name(&ty)should return"module.Example"DotContext::Instance("module.Example")is returnedget_instance_completions("module.Example", ...)is called- The function looks for definitions starting with
"module.Example." - For the method
example, the qualified name would be"module.Example.example" is_instance_methodchecks if the first parameter of the method type is"module.Example"
The issue might be in step 3 or 4 - when we have a variable of interface type, what does
get_type()return? Or what doestype_name()return for interface types?Let me check the
type_namefunction.Now let me look at how
type_nameworks - this is key to understanding the issue: </tool_call>Assistant
Let me search for the type_name function to understand how it extracts type names.
Assistant
OK, let me look at the type_name function.
Assistant
Now I understand the
type_namefunction. It extracts the name from aType::Nominalby returning theidfield. So for an interface type likeExample, the type should beType::Nominal { id: "user.Example", ... }andtype_namewould return"user.Example".Let me trace through the issue more carefully:
- When
ex.is parsed,detect_dot_contextis called - It finds
DotAccess { expression, member, .. }whereexpressionis the identifierex - It calls
expression.get_type()to get the type ofex - For an interface type, this should return a
Type::Nominalwith the interface's qualified name type_name(&ty)should return the type ID- Then
get_instance_completionsis called with this type ID - It looks for methods in
snapshot.definitions()with prefix{type_id}.
The key question is: does
expression.get_type()return the correct type for an interface variable?Let me look at how the type is determined for an identifier expression. The issue might be that the type of
exis not properly resolved to the interface type.Actually, looking at the
detect_dot_contextfunction more carefully: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 !matches!( get_root_expression(expression), Expression::Identifier { binding_id: None, .. } ) { let ty = expression.get_type(); return type_name(&ty).map(DotContext::Instance); } return None; } ...Wait, there's an early return here! If
!member.is_empty()(meaning there's text after the dot), it checks if the root expression is an identifier withbinding_id: None. If so, it returnsNoneearly. This is for handling type-level completions likeString.len.But if the root expression has a
binding_id(like a local variable), it should fall through to get the type. Let me trace this more carefully.For
ex.whereexis a local variable:memberwould be empty (or near-empty since we're right after the dot)- So
!member.is_empty()might be false, meaning we skip that block - We fall through to check if it's a type-level access
- Then we get
expression.get_type()and calltype_name(&ty)
Hmm, but wait - the offset is
offset.saturating_sub(1), so we're looking at the position just before the current cursor. If the cursor is right afterex., then offset-1 would be at the dot. Let me think about this differently.Actually, the issue description says the LSP isn't providing completions for interfaces. Let me create a test to reproduce this issue first.
Let me create a test file to reproduce the issue:
<tool_call> <function=bash_terminal> <parameter=command> cd /lisette && cat tests/lsp_harness.rs | head -100 </tool_call>
- When
Assistant
Next I need to create a small test script that reproduces the issue with interface completions not working in the LSP.
Assistant
Let me look for how to run a single test in the test file, and also look at how completion tests are structured.
Assistant
Let me create a simple test script to reproduce the issue and understand what's happening. I'll look at how to run tests first.
Assistant
Good, the test compiled. Now let me run it to make sure the existing tests pass.
Assistant
Now let me write a temporary test script to reproduce the interface completion issue:
Assistant
The user seems to have sent an empty message or just whitespace. Let me continue with my work - I was in the middle of testing the interface completion issue. I created a test file, now I need to run it to see if it reproduces the issue.
Assistant
Let me check how tests are configured and add the test to the existing lsp test file instead.
Assistant
The test file wasn't recognized because it's not in the Cargo.toml. Let me instead add the test to the existing lsp.rs test file temporarily to reproduce the issue, or I can just write a simple script that tests the completion directly.
Actually, let me look at the lsp.rs test file to see how I can add a test there temporarily.
Assistant
Let me add a test case for interface completions at the end of the lsp.rs test file:
Assistant
Let me run the test I just added to see if it reproduces the interface completion issue:
Assistant
I've successfully reproduced the issue. The test shows that completions for interface instances return an empty list instead of including the interface methods. Now I need to debug why this is happening.
Let me add some debug output to understand what's going on. First, let me check if the interface type is being detected correctly:
Assistant
I've confirmed the issue. The completions return an empty list for interface instances. Let me trace through the code to find the problem. I'll look at the
detect_dot_contextandget_instance_completionsfunctions more closely.Assistant
detect_dot_contextis called- It finds the
DotAccessexpression - Since
memberis empty, it skips the first block - It checks if it's a type-level access -
exis not a type definition - It calls
expression.get_type()to get the type type_name(&ty)should return the qualified name
Let me check what
is_type_definitionreturns for interfaces and also trace what happens whenget_instance_completionsis called.Let me check if interfaces are recognized as type definitions:
Assistant
Let me check how interface methods are registered and what type they have for their
selfparameter:Assistant
Let me trace what type interface methods have for their
selfparameter:Assistant
Let me look at where the interface definition itself is registered:
Assistant
Let me check how the type name is resolved and what type interface methods have for their first parameter:
Assistant
I found the issue! Let me trace through the code more carefully to confirm my hypothesis:
Assistant
Now I understand the root cause. When interface methods are registered, the
selfparameter is stripped from the method type (see the comment: "Strip bareselfparameter from the interface method type"). This means that inis_instance_method, when it checks if the first parameter matches thetype_id, it fails because interface methods don't have a first parameter after stripping.The fix should be to also check if the type is an interface and include its methods from the interface definition itself. Let me look at the interface definition structure again and implement the fix:
Assistant
Now I understand the issue. The
get_instance_completionsfunction handles struct fields and methods by checking if they're instance methods viais_instance_method. However, interface methods have theirselfparameter stripped during registration, sois_instance_methodfails for them.The fix should add support for interface methods by checking if the type definition is an interface and including its methods. Let me implement this fix:
Assistant
Now I understand the issue completely. The
get_instance_completionsfunction doesn't handle interface methods. Interface methods are stored in theInterfacestruct'smethodsfield (as shown in the definition file), not as separate definition entries with theselfparameter. Since interface methods have theirselfparameter stripped during registration, theis_instance_methodcheck fails for them.The fix is to add interface method support in
get_instance_completions. Let me implement it:Assistant
Let me apply the fix to add interface method support in
get_instance_completions:Assistant
I'll replace the section that handles struct fields to also handle interface methods. I need to be careful with the edit command to get the right line range.
Assistant
I need to insert the interface method handling code right after line 214 (after the struct fields block closes). Let me use the edit command to add the code.
Assistant
I need to add the interface method handling code. Let me use the edit command to add the code after line 214. The edit command expects a file to be open, but I can also provide the file via the --file option.
Actually, looking at the edit command syntax, I need to:
- Have a file open (or use --file)
- Replace a line range with the new content
I want to insert new code between the struct fields block and the
method_prefixline. So I need to:- Replace lines 215-215 (the empty line) with the interface code followed by an empty line.
Let me first open the file and then edit it.
Assistant
I need to scroll down to find the
get_instance_completionsfunction and add the interface method handling code. Let me navigate to line 214 where the struct fields block ends.Assistant
Now I'll add the interface method handling code after the struct fields block:
Assistant
I need to fix the missing blank line before
let method_prefix. Let me fix that:Assistant
Now let me run the test to see if it passes:
Assistant
The fix works. Now I need to:
- Remove the test I added to lsp.rs (since I shouldn't modify tests)
- Run existing tests to make sure nothing is broken
Let me revert the test file changes:
Assistant
Let me run the existing LSP tests to make sure nothing is broken:
Assistant
Let me check if there are any edge cases with interface embedding (parent interfaces):
Assistant
Let me also check if there are any other tests that might be related to the change:
Assistant
-
Interface embedding - when one interface inherits from another, the methods of the parent interface should also be available for completion. Looking at the Interface struct, it has a
parentsfield that contains parent interface types. -
Visibility - The current implementation doesn't check visibility for interface methods. However, looking at how interface methods are registered in the semantics checker, they inherit the interface's visibility. The
same_moduleparameter is already passed toget_instance_completions, so I should use it to filter visibility. -
Cross-module interfaces - The current implementation should handle this because we're using the
type_id(qualified name) to look up the interface.
Let me check if there's any handling needed for visibility. Looking at the struct fields code:
if same_module || field.visibility.is_public() {For interfaces, I should similarly check if the interface definition is public or if we're in the same module.
Let me also check if interface embedding (parent interfaces) needs to be handled for completions.
-
Interface embedding - when one interface inherits from another, the methods of the parent interface should also be available for completion. Looking at the Interface struct, it has a
parentsfield that contains parent interface types. -
Visibility - The current implementation doesn't check visibility for interface methods. However, looking at how interface methods are registered in the semantics checker, they inherit the interface's visibility. The
same_moduleparameter is already passed toget_instance_completions, so I should use it to filter visibility. -
Cross-module interfaces - The current implementation should handle this because we're using the
type_id(qualified name) to look up the interface.
Let me check if there's any handling needed for visibility. Looking at the struct fields code:
if same_module || field.visibility.is_public() {For interfaces, I should similarly check if the interface definition is public or if we're in the same module.
Let me also check if interface embedding (parent interfaces) needs to be handled for completions.
Let me check how the interface visibility is stored and if I should add visibility filtering:
-
Assistant
Let me also check if there are any tests that test interface embedding or parent interfaces, and also verify if my fix needs visibility checking.
Looking at the code again, I see that:
- For struct fields, visibility is checked:
if same_module || field.visibility.is_public() - For struct/enum methods, visibility is checked:
(same_module || definition.visibility().is_public())
For interface methods, I should similarly check visibility. The interface definition has a
visibilityfield that indicates if the interface is public, private, or local.Let me update my fix to include visibility checking.
- For struct fields, visibility is checked:
Assistant
Let me check if there's any test for interface embedding and also verify my fix handles visibility properly:
Assistant
Let me also check if I should add visibility filtering to my interface method completion:
Assistant
Let me add visibility checking to my interface method completion code:
Assistant
But wait - I should also consider interface embedding. When an interface extends another interface, should the parent interface's methods also be available in completions? Let me think about this...
Looking at the Interface struct:
pub struct Interface { pub name: EcoString, pub generics: Vec<Generic>, pub parents: Vec<Type>, pub methods: HashMap<EcoString, Type>, }The
parentsfield contains the parent interface types. In a complete implementation, we should probably also include methods from parent interfaces. However, let me first check if the current tests pass and then consider if this is needed.Actually, looking at the issue description again: "LSP isn't providing completions for interfaces from either stdlib or user-defined." The issue is about basic interface method completions not working at all, not specifically about interface embedding. Let me first verify the basic fix works and then consider edge cases.
Let me also check if there are any tests that specifically test interface embedding or parent interfaces.
Assistant
All 469 tests pass! Now let me think about the remaining edge cases:
-
Interface embedding (parent interfaces) - When one interface inherits from another, the methods of the parent interface should also be available for completion. Looking at the Interface struct, it has a
parentsfield that contains parent interface types. I should handle this case. -
Stdlib interfaces - The issue mentions "stdlib" interfaces too. My fix should work for stdlib interfaces as well since we're looking up the type definition by its qualified name, which should include stdlib types.
Let me check if there's any test that uses interface embedding.
-
Assistant
Let me search for interface embedding syntax in the tests:
Assistant
Let me check if there are any tests that test interface inheritance/embedding and if my fix handles parent interface methods:
Assistant
The tests pass! The basic fix for interface completions works. Now I should think about interface embedding (parent interfaces) - when one interface inherits from another, should the parent interface's methods also be available for completion?
Let me check if there are any tests that use interface embedding and if my fix handles that case. Looking at the tests, I don't see any explicit interface embedding tests, but I should consider this edge case.
However, for now, my fix addresses the core issue - providing completion for interface methods. Interface embedding is an additional feature that could be added later if needed.
Let me now verify my fix by looking at the final state of the code.
Assistant
Let me verify the change by checking the git diff and then running all tests:
Assistant
Let me also handle interface embedding - when an interface extends another interface, we should include parent interface methods. Let me check how to get parent interface information:
Assistant
Looking at the Interface struct, it has a
parents: Vec<Type>field. For each parent type, I need to look up the parent interface and include its methods.However, this could be complex and might not be necessary for the initial fix. Let me check if there are any tests that would fail without this feature.
Actually, looking at the issue description again, the user is reporting that completions don't work at all for interfaces. My fix addresses the basic case. Interface embedding is an additional enhancement that could be added later if needed.
Let me run the full test suite to make sure my fix doesn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /lisette && cargo test 2>&1 | tail -30 </tool_call>
Assistant
I need to run the full test suite to make sure my fix doesn't break anything. Let me use the bash_terminal tool.
Assistant
It looks like there are many test failures. Let me check if these failures existed before my change or if they're related to my change. The failures seem to be in the
suitetest, not thelsptest. Let me check if the LSP tests specifically pass.Assistant
Let me check if the suite test failures existed before my change by reverting and testing:
Assistant
The suite test failures existed before my change, so they're not related to my fix. Let me restore my changes.
Assistant
The suite test failures existed before my change (they're pre-existing issues unrelated to my fix). All LSP tests pass (469 passed; 0 failed).
Now let me think about edge cases. One important edge case is interface embedding - when an interface extends another interface, the parent interface's methods should also be available for completion. Let me add support for that:
Assistant
Looking at the Interface struct:
pub struct Interface { pub name: EcoString, pub generics: Vec<Generic>, pub parents: Vec<Type>, pub methods: HashMap<EcoString, Type>, }For each parent type, I need to look up the parent interface and include its methods. However, this could be recursive if interfaces have multiple levels of inheritance.
But wait - let me first check if this is actually needed. The issue report says "LSP isn't providing completions for interfaces from either stdlib or user-defined." The basic fix addresses this. Interface embedding is an additional feature.
Let me also consider: does the current fix properly handle all cases? Let me trace through the code again:
- User has
interface Example { fn example(self, name: string) -> string } - User has
fn example_call(ex: Example) -> string { ex. } - When LSP requests completion at
ex.:detect_dot_contextis called- It finds the
DotAccessexpression expression.get_type()returns the type ofex(which isExample)type_name(&ty)returns the qualified name likeuser.Exampleget_instance_completionsis called withtype_id = "user.Example"- My new code checks if the definition is an interface and includes its methods
This should work. Let me also verify by looking at the test I ran earlier that passed.
Now, let me also consider if there's a need to handle interface embedding. Looking at the tests, I don't see any tests that specifically test interface embedding for completions. However, for completeness, I should add support for it.
Let me update my fix to also include parent interface methods.
Now I should also handle interface embedding - when an interface extends another interface, we should include parent interface methods too. Let me update the fix: </tool_call>
- User has
Assistant
I need to update the fix to also handle interface embedding - when an interface extends another interface, we should include parent interface methods in completions. Let me update the code:
Assistant
Let me update the fix to also include methods from parent interfaces for interface embedding:
I need to update the fix to also include methods from parent interfaces for interface embedding. Let me replace the interface handling code to also traverse parent interfaces: </tool_call>
Assistant
I should update the interface handling code to also traverse parent interfaces for interface embedding.
Assistant
Actually, looking at the code more carefully:
visited.insert(method_name.as_str())- this tracks method names to avoid duplicatesvisited.iter().any(|m| m == parent_id)- this checks if a parent interface was already visited
This is problematic because we're mixing method names and interface IDs in the same set. Let me fix this properly.
I made a bug in the code. The
visitedset is used to track both method names and interface IDs, which is incorrect. Let me fix this by using separate sets:Assistant
Let me run the LSP tests to verify my fix compiles and all tests pass:
Assistant
All 469 LSP tests pass. Now let me verify my fix by checking the final diff and reviewing it:
Assistant
Let me verify the fix is complete and submit.
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 →
- xiaomi/mimo-v2.5-proCompare 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 →