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 to understand its structure and locate the LSP implementation. Let's first see what's in the root directory.
- Assistant
Let me explore the repository structure more carefully.
- Assistant
Let me look at the crates directory to understand the project structure.
- Assistant
Let me look at the LSP crate since the issue is about LSP completions.
- Assistant
The issue is about LSP not providing completions for interfaces. Let me look at the completion module.
- Assistant
Let me look at the completion logic more carefully. The issue is that interfaces aren't providing completions. Let me look at the
detect_dot_contextfunction and theget_instance_completionsfunction.When we have
ex.whereexis of typeExample(an interface), the LSP needs to provide completions for the interface methods. Let me look at how interfaces are defined and how their methods are stored.Let me look at the syntax module to understand how interfaces work.
- Assistant
Let me look at the completion logic in lib.rs more carefully, specifically the
completionmethod. - Assistant
Let me look at the full completion method.
- Assistant
Now I need to understand how interface methods are resolved. Let me look at the
analysismodule and how interface types are handled. - Assistant
Now let me look at the
get_instance_completionsfunction more carefully. The issue is that when we have an interface type, the LSP doesn't provide completions for its methods. Looking atget_instance_completions, it currently only handlesStructdefinitions. It doesn't look for interface methods.Let me look at how interfaces are defined in the syntax crate to understand how methods are stored.
- Assistant
Now let me look at the DefinitionBody for Interface to understand its structure.
- Assistant
Now I understand the issue. Let me look at how interface methods are stored in the definitions map and how the semantic analyzer processes interfaces.
- Assistant
Let me understand the problem. The issue is that when a variable has an interface type (e.g.,
ex: Example), typingex.doesn't provide completions for the interface's methods.Let me look at how interface methods are stored.
- Assistant
Now I can see the issue. Let me trace through the code. The interface methods ARE stored as definitions, but the problem might be in the
detect_dot_contextoris_instance_methodlogic. Let me first look at how interface methods are stored and what type they have: - Assistant
Now let me check the existing LSP tests to see if there are any for interface completions:
- Assistant
Let me search for test cases that test interface completion specifically:
- Assistant
Let me see if there are any existing interface completion tests:
- Assistant
Now let me look at how completions work for dot access specifically. Let me trace through the logic more carefully. Let me check the
detect_dot_contextfunction more carefully: - Assistant
Let me look at the
detect_dot_contextfunction in detail: - Assistant
Now let me understand the type system for interfaces. Let me check how interface types are represented:
- Assistant
Let me look at the Type enum definition:
- Assistant
Let me look more closely at how interface methods are stored. In the
populate_interface_methodsfunction, I saw that interface methods are stored asValuedefinitions. But the key question is: what is the first parameter type of interface methods? Let me look at how the method type is constructed: - Assistant
Let me look for the method that registers interface methods.
- Assistant
Let me look at the full interface registration code:
- Assistant
Now I understand the issue clearly! Looking at the
populate_interfacecode (lines 330-350), I can see that interface methods have theirselfparameter stripped out when stored:// Strip bare `self` parameter from the interface method type.This means that when
get_instance_completionscallsis_instance_method, the method types don't have the interface type as the first parameter, so they fail the check.Let me also check how
is_type_definitionworks: - Assistant
Now let me check the existing LSP tests to see how they test completions:
- Assistant
Now I understand the issue. Let me create a test to reproduce the problem and confirm my understanding.
- Assistant
Let me look at the test infrastructure to understand how to write a test:
- Assistant
Let me look at how to run existing tests:
- Assistant
Now I understand the problem completely. Let me trace through the flow for interfaces:
- When user types
ex.withex: Example,detect_dot_contextreturnsDotContext::Instance("module.Example") get_instance_completions("module.Example", ...)is called- It checks for
Structfields - not a struct, skipped - It looks for definitions prefixed with
module.Example.- findsmodule.Example.example - It checks
is_instance_method(definition.ty(), "module.Example")- but the interface method definition hasselfSTRIPPED (see thepopulate_interfacecode), so the first parameter isstringnotExample, causingis_instance_methodto return false
So interface methods are not shown because their
selfparameter is stripped from the definition stored in the definitions map.Let me also check if the
Interfacebody itself contains the methods: - When user types
- Assistant
Now let me look at how to handle interface methods in completions. The Interface struct has
methods: HashMap<EcoString, Type>which contains the methods (with self stripped). Let me also check for parent interfaces. - Assistant
Now I understand the complete picture. The fix needs to be in
get_instance_completionsto also handleInterfacedefinitions. Let me also look at thesnapshotAPI to understand how to get parent interface methods: - Assistant
Now I have a complete understanding. Let me look at how the
get_instance_completionsfunction works and also check if interface methods are stored with the method body having the stripped self parameter vs the original with self: - Assistant
Now I understand the complete problem. Let me write the fix. The
get_instance_completionsfunction needs to handleInterfacedefinitions by directly accessing the interface's methods: - Assistant
Now let me first write a test to reproduce the issue, then fix it. Let me check the existing tests for how completions are tested:
- Assistant
Now let me think about the fix. The issue is that interface methods stored as
Valuedefinitions have theirselfstripped, sois_instance_methodreturns false. We need to also handleInterfacedefinitions inget_instance_completions. Let me also check if theis_type_definitionmethod needs to includeInterface: - Assistant
Now let me look at how the
detect_dot_contextfunction handles this - there are two paths: one foris_type_definition(TypeLevel) and one for instance types. For the instance path,expression.get_type()needs to work for interface types. Let me verify that it works: - Assistant
Let me look at the
get_typemethod forExpression: - Assistant
Now I understand the complete flow. The problem is:
- When
ex: Exampleand user typesex.,detect_dot_contextcorrectly identifiesDotContext::Instance("module.Example") get_instance_completionsis called but:- Interface definitions don't have
Structfields (so no field completions) - The interface method
module.Example.exampleis stored as aValuedefinition withselfSTRIPPED, sois_instance_methodreturns false - Result: empty completions
- Interface definitions don't have
The fix: Add interface method handling in
get_instance_completions. Let me implement the fix: - When
- Assistant
Now let me implement the fix. I need to add handling for
Interfacedefinitions inget_instance_completions: - Assistant
Now let me write the fix. I need to add handling for
Interfacedefinitions inget_instance_completions. Let me also check if I need to handle parent interfaces: - Assistant
Now let me implement the fix. I'll add interface method handling in
get_instance_completions: - Assistant
Now let me apply the fix. I'll modify
get_instance_completionsto handleInterfacedefinitions: - Assistant
It seems there might be an issue with the edit. Let me check the full file:
- Assistant
The file looks correct. Now let me check if the
get_qualified_idmethod exists onType: - Assistant
Good, that method exists. Now let me verify the code compiles:
- Assistant
The first cargo check timed out because it was downloading the Rust toolchain. Let me wait a bit and try again.
- Assistant
Let me check the crate name:
- Assistant
The crate name is "lisette-lsp", so I should use
-p lisette-lsp. Let me check with that. - Assistant
There's a duplicate/malformed code. Let me look at the file around line 274:
- Assistant
I see - the
get_type_completionsfunction declaration got cut off. The edit accidentally replaced the start ofget_type_completions. Let me fix this: - Assistant
The
get_type_completionsfunction header was partially deleted. I need to restore it. The function should start with:pub(crate) fn get_type_completions( type_id: &str, snapshot: &AnalysisSnapshot, same_module: bool, ) -> Vec<CompletionItem> {Let me fix this.
- Assistant
Good, the file looks correct now. Let me check if it compiles:
- Assistant
Good, it compiles with just a warning about unused
type_id. Let me fix that: - Assistant
Let me verify the file compiles cleanly:
- Assistant
Good, no warnings or errors. Now let me run the existing LSP tests to make sure I haven't broken anything:
- Assistant
All 469 tests pass. Now let me also write a quick test to verify that the fix works for the specific case described in the issue. Let me create a test script:
- Assistant
Let me look at how existing completion tests work and create a simple test script:
- Assistant
Let me check the test URI and also understand the test structure better:
- Assistant
Now let me also handle the visibility check for interface methods. Looking at the code, interface methods inherit the interface's visibility. Let me update
collect_interface_methods: - Assistant
I need to also pass the interface definition's visibility to
collect_interface_methods. Let me update the code: - Assistant
I see there's an extra
}on line 226 and thecollect_interface_methodssignature needs to be updated. Let me fix: - Assistant
Good, the extra
}was removed. Now I need to update thecollect_interface_methodsfunction signature to match the call site. Let me update it: - Assistant
Let me verify the code compiles:
- Assistant
Good, it compiles cleanly. Now let me run the existing tests to make sure nothing is broken:
- Assistant
All 469 tests pass. Now let me also think about whether we need to add
Interfacetois_type_definition(). Let me check where it's used: - Assistant
Let me check if
is_type_definitionshould also includeInterface: - Assistant
Let me check the
is_type_definitionusage inlib.rs: - Assistant
I see that
is_type_definitionis also used inlib.rsfor completions. Let me check if the issue might also be in thedetect_dot_contextpath. Let me trace through the flow more carefully: - Assistant
Now let me think about whether there are any additional places where we might need to handle interfaces. Let me check if
is_type_definition()needs to includeInterface: - Assistant
Now let me also consider if
is_type_definitionshould includeInterface. This is relevant because indetect_dot_context, if a variable is used asExample.(type-level access), it checksis_type_definition(). But for the reported issue,ex.(instance access), it should work through the type expression. Let me also check if there's a potential issue with how interfaces are handled indetect_dot_context: - Assistant
Now let me also check if the type of an interface-typed parameter is stored correctly. Let me look at how interface types are resolved:
- Assistant
Now let me also check if
is_type_definition()should includeInterface. Let me look at its usage indetect_dot_contextand the completion handler inlib.rs. The issue might be that when a variable of interface type callsdetect_dot_context, the flow goes correctly through the type expression path, but we should also consider addingInterfacetois_type_definition()for completeness: - Assistant
Now let me check the full file to see
is_type_definition: - Assistant
I should also add
Interfacetois_type_definition()since interfaces are type definitions. This would help with type-level completion (e.g.,Example.). Let me check howis_type_definitionis used in the semantic checker: - Assistant
I see that
is_type_definitionis used in the semantic checker to detect type-level receivers. AddingInterfaceto it could affect the semantic checker behavior. Since the main fix is inget_instance_completions, let me leaveis_type_definition()as is for now and focus on the completion fix.Let me review the final state of the completion.rs file:
- Assistant
The file looks correct. Let me verify the code compiles and all tests pass:
- Assistant
Good, it compiles cleanly. Let me now think about whether there's also an issue with
detect_dot_contextfor the reported case. Let me trace through the flow forex.whereex: Example(interface):detect_dot_contextfindsDotAccess { expression: Identifier("ex"), member: "" }- Since
memberis empty, it goes to the type-level check - It checks if "ex" matches a type definition → no (it's a variable name)
- It gets
expression.get_type()→ this is the type assigned by the type checker - For interface types, this should be
Nominal { id: "module.Example", ... } type_name(&ty)returnsSome("module.Example")- Returns
DotContext::Instance("module.Example") get_instance_completions("module.Example", ...)is called → my fix handles this
The flow looks correct. Let me now also consider if
is_type_definition()needs to includeInterfacefor thedetect_dot_contextTypeLevel path. Looking at the issue description, the problem is aboutex.(variable of interface type), notExample.(type-level access). So my fix should handle the reported issue.However, I should also check if
is_type_definition()not includingInterfacecould cause issues elsewhere. Let me check thedetect_dot_contextTypeLevel path forExample.: - Assistant
All 469 tests pass. Let me now review the full diff to make sure my changes are correct:
- Assistant
The diff looks correct. Now let me also think about whether there might be a second issue. Looking at
detect_dot_contextfor the caseex.whereex: Example:- The
DotAccessexpression hasmemberempty - The identifier check (
is_type_definition) won't match sinceexis not a type definition expression.get_type()returns the type of the identifierex, which should be the interface type (Nominal)type_name(&ty)extracts the type ID from the Nominal type
This should work correctly. But let me also verify that when a parameter is
ex: Example, the type assigned to the identifier expression is indeed aNominaltype: - The
- Assistant
Now let me verify the final state of the file is correct and run the tests one more time:
- Assistant
Good, everything compiles and all 469 tests pass. Let me also run the full test suite to make sure nothing is broken:
- Assistant
The failures in the
testscrate are likely pre-existing or related to Go/emit tests, not the LSP tests. Let me check if they fail on the main branch too: - Assistant
Let me check if the test failures are from my change or pre-existing:
- Assistant
The LSP crate has
test = falsein its Cargo.toml. Let me check if the test failures in the suite are pre-existing: - Assistant
The test failures are pre-existing. Let me restore my 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 →