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.
codeinterface Example { fn example(self, name: string) -> string } fn example_call(ex: Example) -> string { ex. }Interface
No new interfaces are introduced.
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 relevant code for LSP completions.
- Assistant
Let me explore the repository structure more broadly.
- Assistant
Let me look at the crates directory to understand the structure better.
- Assistant
Let me explore the LSP crate since that's where completion would be handled.
- Assistant
Let me look at the completion.rs file first to understand how completions work.
- Assistant
Now let me understand the semantics and type system to see how interfaces are represented:
- Assistant
Let me look at how interfaces are represented in the syntax/program types.
- Assistant
Let me look at the syntax crate structure more broadly.
- Assistant
Let me look at the definition file to understand how interfaces are defined.
- Assistant
Now I understand the structure. The issue is that when LSP provides completions for interface methods, it needs to find methods associated with interfaces. Let me look at how completions work for dot access and how interface methods are stored.
The key issue is likely in
get_instance_completionswhich looks for methods by prefix{type_id}.but interface methods are defined differently. Let me check how interface methods are stored in the definitions. - Assistant
Let me understand how the type system handles interface types:
- Assistant
Now let me look at the semantics crate to understand how interface methods are stored:
- Assistant
Let me look at how dot access resolution works for interfaces:
- Assistant
Let me look at
as_instance_methodandget_all_methodsmore carefully: - Assistant
Let me see the full as_instance_method implementation
- Assistant
Now let me look at
get_all_methodsto understand how it resolves methods: - Assistant
Let me find the implementation of
get_all_methods. - Assistant
Let me look at the implementation in the checker/mod.rs.
- Assistant
Let me now look at how types are resolved in the LSP's completion context. The issue is likely in how
detect_dot_contextresolves the type of a parameter with an interface type: - Assistant
Let me look at the
type_namefunction: - Assistant
Let me see the type_name function.
- Assistant
Now I need to understand the key flow. When a user types
ex., the completion handler:- Calls
detect_dot_context()or usesresolve_variable_type()to find the type - Then calls
get_instance_completions()with the type_id
Let me trace through the flow more carefully. Let me look at how interfaces are stored in the Store:
- Calls
- Assistant
Let me look at the
get_all_methodsin the Store to see how interface methods are handled: - Assistant
Let me continue reading the get_all_methods to understand how it handles interface methods.
- Assistant
Now I need to understand the full picture. Let me check how interface methods are registered in the definitions:
- Assistant
Let me look at how interface methods are registered to understand their naming convention in the definitions store.
- Assistant
Let me look at how
detect_dot_contextworks in the completion module more carefully. It tries to get the expression type. Let me trace the issue: - Assistant
Let me look at the DotAccess expression's get_type and the Expression enum to understand the flow:
- Assistant
Let me look at the complete
completionhandler in lib.rs to see the exact flow: - Assistant
Let me see the full completion handler.
- Assistant
Let me look at the LSP tests to understand the testing patterns:
- Assistant
Let me look at the snapshot and how the file AST is stored:
- Assistant
So the snapshot has the analyzed files. Let me look at how interface methods' types look. Let me check the interface method registration more carefully.
- Assistant
Now let me understand the flow. Let me look at how
find_expression_atworks: - Assistant
Let me look at how the parser handles dot access expressions:
- Assistant
Let me look at how the dot access completion resolves. The issue is likely that
detect_dot_contextcan't find the type for interface parameters orget_instance_completionsdoesn't handle interfaces. Let me trace through more carefully.Let me check what happens in
detect_dot_contextfor an interface variable. Theexpression.get_type()needs to resolve to the interface type, thentype_nameneeds to extract the ID. - Assistant
Let me look at the interface registration in methods.rs to understand how the interface methods are stored:
- Assistant
Let me search for where interfaces are registered
- Assistant
Let me look at the populate_interface function to understand how interface methods are stored:
- Assistant
Now I can see the issue! When interface methods are registered, the
selfparameter is stripped from the method type:rustlet fn_ty = if has_self_receiver { match fn_ty { Type::Function { params, param_mutability, bounds, return_type } => Type::Function { params: params[1..].to_vec(), // strips first param (self) ...So interface methods stored as
Definition::Valueentries don't haveselfas the first parameter. This meansis_instance_method()returnsfalsefor them.Let me also look at how
with_receiver_placeholderworks: - Assistant
Let me see the
with_receiver_placeholdermethod: - Assistant
Now I understand the issue. Let me verify by creating a test file and tracing through the code:
- Assistant
Now I understand the root cause! The issue is in
get_instance_completionsin/lisette/crates/lsp/src/completion.rs. When the type is an interface:- Interface methods are registered as
Definition::Valueentries BUT with theselfparameter stripped is_instance_method()checks if the first parameter's type matchestype_id, but sinceselfwas stripped, this check fails- So interface methods are never included in completions
The fix: Add explicit handling for
Interfacedefinitions inget_instance_completions, similar to howStore::get_all_methods()handles interfaces. - Interface methods are registered as
- Assistant
Let me now look at the full
get_instance_completionsfunction: - Assistant
Now I understand the problem completely. Let me implement the fix. The
get_instance_completionsfunction needs to handleInterfacetypes by reading methods from the interface definition'smethodsHashMap: - Assistant
Now I'll add interface method support to
get_instance_completions. The key insight is that interface methods are stored in theInterfacedefinition body'smethodsHashMap, and they haveselfstripped. I need to:- Check if the type is an interface
- Get methods from the interface definition
- Also handle parent (embedded) interfaces
- Assistant
Let me verify the patch was applied correctly:
- Assistant
Good, the patch looks correct. Now let me build the project to make sure it compiles:
- Assistant
Let me check the package name.
- Assistant
Let me use the correct package name.
- Assistant
Build succeeded. Now let me check if there are any existing tests:
- Assistant
Let me look at the LSP tests:
- Assistant
Let me search for existing interface-related tests:
- Assistant
Let me look for existing tests that deal with dot completion on variables:
- Assistant
Let me check if there's already a test for completion on interface types:
- Assistant
Let me check whether the parser handles
ex.(with nothing after the dot) correctly: - Assistant
Let me look at the full parsing of dot access:
- Assistant
Let me check what happens when the parser expects an Identifier but encounters a different token:
- Assistant
Let me look at how the parser handles when there's no identifier after the dot:
- Assistant
Now let me understand the full picture. When the user types
ex., the parser will parseexas an Identifier and then.as a Dot token. After the dot, it callsparse_field_access, which reads the next token as the field name. If the next token is}(closing brace) or EOF, the member will be}or empty.In either case,
detect_dot_contextwill find the DotAccess and resolve the type ofexto the interface type. Thenget_instance_completionsis called with the interface's qualified name.The problem is that
get_instance_completionsdoesn't find interface methods because:- The
is_instance_methodcheck fails because interface methods haveselfstripped from their type - There's no explicit handling for
DefinitionBody::Interface
My fix adds
collect_interface_methodsto directly extract methods from theInterfacedefinition body. Let me now run the existing LSP tests to make sure nothing is broken: - The
- Assistant
All 469 tests pass. Let me also think about whether the
is_type_definitioncheck in the completion handler's fallback path needs updating. Looking at the completion handler, when the user typesExample.(where Example is an interface), the code checks:rustif let Some(definition) = snapshot.definitions().get(qualified.as_str()) && definition.is_type_definition() { // type-level completions (like enum variants) }Since
is_type_definition()returns false for interfaces, it skips this. But then it falls through toresolve_variable_typewhich only works for variables. TheExample.pattern wouldn't work for interfaces becauseExampleat the top level is an identifier, not a variable. However, this is fine because interfaces don't have static members — they only have instance methods.Now let me also verify that my fix works for the stdlib interfaces (like the
stringerinterface from Go). Let me check if there are any stdlib interfaces: - Assistant
No interfaces in the prelude. Let me check the stdlib.
- Assistant
The fix looks correct. Let me also verify my understanding of the edge case where
memberis empty vs. not empty indetect_dot_context. Let me also write a small test to verify the fix works for the exact scenario described in the issue: - Assistant
Let me look at the test harness to understand how tests are structured:
- Assistant
Let me also verify that the
detect_dot_contextfunction can correctly handle the case where a function parameter has an interface type. Let me look at how the AST type is set for function parameters: - Assistant
Let me see that test:
- Assistant
Good, I can see how existing tests are structured. Now let me also verify the overall correctness by running the full test suite:
- Assistant
All 469 LSP tests pass. Let me also run the broader test suite to make sure nothing is broken:
- Assistant
There are many failures in the full test suite. Let me check if these failures existed before my change:
- Assistant
Let me check if those failures existed before my change by stashing and running:
- Assistant
Good - the same 1513 failures exist before my change. They are pre-existing and unrelated. Let me restore my changes:
- Assistant
Good - those 1513 failures are pre-existing snapshot tests (
.snap.newfiles) that exist before my change. My change only affects the LSP package. Let me verify the LSP tests still pass: - Assistant
Let me now trace through the actual code path to make sure the completion works for the exact scenario described. Let me look at how the parser handles
ex.}: - Assistant
Now let me also verify the fix handles the
DotAccesscorrectly. When the user typesex., the parser produces a DotAccess withmember = "}"(the next token after the dot). Thedetect_dot_contextfunction correctly resolves the type through the!member.is_empty()path.Let me now check if there are any compilation warnings:
- Assistant
No warnings or errors. Let me also run the LSP tests one final time to confirm:
- Assistant
All 469 tests pass. Let me review the final diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.