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. }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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me look at the main lib.rs to understand how completion is integrated:
Assistant
Let me understand the type system better. Let me look at the
type_namefunction:Assistant
Now let me look at how interfaces are represented in the codebase:
Assistant
Now let me look at how
detect_dot_contextworks with interfaces and see what might be going wrong. Let's look atfind_expression_atand other related functions:Assistant
Now let me look at how
expression.get_type()is implemented and the DotAccess expression:Assistant
a potential issue. Let me check where
is_type_definitionis used:Assistant
Let me look at how interfaces are handled in the dot_access expression checker and the type checker:
Assistant
Now let me look at the get_all_methods function:
Assistant
Now let me look at the LSP's
get_instance_completionsand check what types come back. Let me also see how interface methods are stored:Assistant
Now let me reproduce the issue first by writing a test:
Assistant
Now let me look at the prelude to find an interface example:
Assistant
Now I want to understand the issue. Let me write a reproducer script:
Assistant
Now let me look at the test harness to understand how to test:
Assistant
Let me look at the existing tests that work with interfaces, to understand how interfaces are handled in tests:
Assistant
Now let me focus on the issue. The issue is that
get_instance_completionsdoesn't handle interfaces. Let me re-read that function:Assistant
Let me look at how the snapshot's definitions are populated and where interfaces get stored:
Assistant
me trace through the issue by running a test:
Assistant
Let me check how interfaces are looked up. The interface methods are registered with the qualified name like
module.interface.method. Let me look at howdefinitions()works in the snapshot:Assistant
Now let me understand the broader picture. Let me first try to build the project to check if I can run it:
Assistant
Good, it builds. Let me now create a test script that reproduces the issue:
Assistant
Good, tests can be run. Now let me write a test to reproduce the interface completion issue:
Assistant
Let me look at the existing test patterns and how they're set up:
Assistant
Now let me check the interface file structure more carefully. First, let me look at how get_instance_completions currently works with interfaces:
Assistant
Let me look at how the parameter type is computed:
Assistant
Now I see that for interface methods, the
selfparameter usesType::ReceiverPlaceholder. Let me look at the registration code more carefully to understand:Assistant
I see the issue now! Interface methods strip the
selfparameter before storing as a Definition. Let me check this:Assistant
So in the
with_receiver_placeholderfunction, the receiver placeholder is prepended to the params. So interface methods stored as Definitions via thestorehave aReceiverPlaceholderfirst. Theis_instance_methodfunction tries to calltype_nameon the first param: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, } }The
type_namefunction returnsNoneforReceiverPlaceholder, so the check fails. Let me confirmAssistant
Confirmed.
type_namereturnsNoneforReceiverPlaceholder. Let me also see theis_type_definitionfunction:Assistant
This is a bug -
is_type_definitionshould includeInterface. Let me now look at the lib.rs to see what the consequences are:Assistant
write a quick test to verify the bug:
Assistant
Actually, I shouldn't add a test to the tests directory. Let me instead write a standalone script to test the LSP behavior. But first, let me actually look at the existing tests to make sure I'm testing the right thing. Let me first examine the issue from a different angle - look at what types of completions are missing for an interface:
Assistant
Let me look at how the existing test framework works and run an existing test that involves interfaces:
Assistant
Let me write a proper test script and run it. I'll write a temporary test that won't be in the repo:
Assistant
Let me write a test reproducer that I can run, then look at the existing tests to make sure I understand. I'll create a temporary file and add a test there:
Assistant
Let me write a temporary test to verify the bug:
Assistant
Now I need to add it to Cargo.toml as a test target:
Assistant
Let me trace through the registration more carefully:
Assistant
Let me look at how parent interfaces are handled:
Assistant
Let me check how get_all_methods handles parent interfaces:
Assistant
Let me check how TypeAlias methods are registered:
Assistant
understand the issue. Let me apply the fix:
Assistant
Now I'll fix the
is_instance_methodfunction. The key insight is that for interface methods, the receiver is stripped during registration, so the stored type doesn't haveselfas the first param. We need to check if the type_id refers to an interface:Assistant
Now let me update the second call to
is_instance_method:Assistant
Now let me update the function signature and body:
Assistant
Now let me build to make sure there are no compilation errors:
Assistant
Now let me run my test:
Assistant
The basic interface completion test now passes. Let me test more cases:
Assistant
All my tests pass. Let me also check the case with imported interfaces:
Assistant
Let me check the interface inheritance syntax:
Assistant
The interface inheritance syntax is
impl Ainside the interface. Let me fix my test:Assistant
Let me debug the inheritance test:
Assistant
Let me check how interface inheritance is parsed:
Assistant
me check the parser issue more carefully:
Assistant
me check the right line/column for the inheritance test:
Assistant
Let me also handle inherited interface methods. Let me look at how the interface inheritance works:
Assistant
Good, there's a
parent_interfaces_offunction. Now I need to use this to also include parent interface methods in completions.But wait, I'm thinking - is this in scope for the issue? The issue says "LSP doesn't provide completion for interfaces". It might or might not include inheritance. Let me focus on the basic case first and see.
Actually, looking at the original issue, it's just about basic interface completion. The user doesn't mention inheritance. But it would be good to handle it correctly.
Let me look at the
SemanticResultto see what'sAssistant
OK so
SemanticResulthasmodules: HashMap<String, ModuleInfo>. Let me see what's inModuleInfo:Assistant
Let me also handle interface inheritance. The interface definition has
parents: Vec<Type>that we can use:Assistant
Let me check how stdlib interfaces are defined:
Assistant
Let me also test with stdlib interfaces:
Assistant
me skip the stdlib interface test (which requires more complex setup) and focus on the basic fix and inheritance. First let me update the test:
Assistant
All tests pass. Now let me also check the existing tests still pass:
Assistant
All existing completion tests pass. Let me also run the broader LSP tests to make sure nothing is broken:
Assistant
All 469 LSP tests pass! Now let me also think about whether I should also handle interface inheritance. The issue mentions "interfaces from either stdlib or user-defined" which doesn't specifically mention inheritance. But for completeness, let me handle it.
Let me first look at how
definitionsis exposed and whether I can also include parent interface methods:Assistant
Let me modify
get_instance_completionsto also include inherited interface methods:Assistant
Now let me think about how to handle parent interfaces. I'll modify the function to also include methods from parent interfaces:
Assistant
Hmm, the file looks slightly different now. Let me check the search text again - maybe my search was missing some lines. Let me try a different approach.
Actually wait, I think the issue is the search string included line 216 onwards, but maybe the indentation differs. Let me look at it more carefully.
Actually let me just look at the file again.
Assistant
Now let me build to make sure this compiles:
Assistant
Good, it compiles. Now let me update the inheritance test to check for inherited methods:
Assistant
The deep inheritance case fails. Let me check what's happening - the labels include
C,B,A,testwhich are top-level identifiers, suggesting the parser isn't recognizing the inheritance. Let me verify:Assistant
There's a parse error. Let me check what the parser is doing:
Assistant
The parser handles the file fine. Let me check the test file format:
Assistant
Let me check how existing tests handle trailing dots with interface inheritance. First, let me check what happens with a simpler version:
Assistant
I see - the existing tests use complete statements like
p.dist(), not just trailing dots. Let me update my test:Assistant
All tests pass, including the inheritance test. Let me also verify with the existing tests:
Assistant
All 469 LSP tests pass. Let me also check the other tests:
Assistant
Many tests are failing because of snapshot changes. Let me check what changed:
Assistant
me check if these tests were passing before my changes:
Assistant
These snapshot test failures are pre-existing, unrelated to my changes. Let me restore my changes:
Assistant
These are pre-existing snapshot test issues unrelated to my changes. Let me clean up the .snap.new files and my test file:
Assistant
Good. Now let me clean up my test file and Cargo.toml change:
Assistant
Now let me re-verify the fix is still working. Let me re-create the test file:
Assistant
All my tests pass. Let me also verify the existing LSP tests still pass:
Assistant
All 469 LSP tests pass. Let me also clean up and remove my temporary test files:
Assistant
Now let me look at my changes to the completion.rs and verify everything looks good:
Assistant
Let me also think about edge cases. Let me consider what happens for:
- Generic interfaces - tested, works.
- Interface inheritance - tested, works.
- Public/private methods on interfaces - need to test.
- Type aliases for interfaces - need to test.
- Method on imported interface (cross-module) - need to test.
Let me add a few more tests:
Assistant
The
verify_interface_dot_after_method_calltest fails due to wrong line/col. Let me fix it:Assistant
All 6 of my tests pass. Let me also run the existing LSP tests:
Assistant
All 469 LSP tests pass. Let me also run all the tests to make sure nothing is broken:
Assistant
So before my changes, the suite has 1513 failing tests. These are all the snapshot test failures. This is a pre-existing problem with the test environment.
Let me restore my changes:
Assistant
Now let me verify that the failures aren't related to my changes. Let me run the same suite tests with my changes:
Assistant
Same number of failures - 1513. So my changes don't introduce any new test failures. The suite failures are pre-existing.
Let me also check the e2e_suite tests:
Assistant
Now let me clean up and remove my temporary test files:
Assistant
Let me also run all the tests one more time to make sure everything is still good:
Assistant
All 469 LSP tests pass. Let me also verify my fix builds cleanly:
Assistant
Now let me also think about whether my fix handles all the edge cases properly. Let me think:
- Basic interface completion - ✓ Tested
- Generic interface completion - ✓ Tested
- Interface inheritance (one level) - ✓ Tested
- Interface inheritance (multiple levels) - Not tested explicitly, but the algorithm handles it
- Struct completion - ✓ Tested (existing tests pass)
- Enum completion - ✓ Existing tests pass
- Type alias for interface - Need to test
- Interface in stdlib - Need to test
Let me test type alias for interface:
Assistant
Type alias for interface works correctly. Let me also test the standard library interfaces:
Assistant
All tests pass. Let me also test for
pub interfaceandpub fnwhich is more like stdlib:Assistant
All 469 LSP tests still pass. Let me also check what happens with edge cases like empty interfaces:
Assistant
All tests pass. Let me also check the test for static methods on structs to ensure that they don't get included in instance completions (they should not, because they don't have self as first param):
Assistant
Static methods are correctly excluded. Now let me think about another edge case - what about type aliases that have methods?
Assistant
Let me also verify enum completions still work:
Assistant
Enum completions work. Let me also check for any tests that might break due to my changes. Let me also verify the e2e_suite tests:
Assistant
Assistant
Let me check if interfaces can have static methods:
Assistant
Let me check if interfaces can have methods without self:
Assistant
So the parser allows methods without
selfin interfaces. But this is a very rare edge case.Let me check the documentation:
Assistant
Let me run all the LSP tests one final time:
Assistant
All 469 LSP tests pass. Let me also test the actual scenario from the issue using a manual script:
Assistant
parser has trouble with the trailing
ex.(a known parser issue), but the LSP correctly provides completions.Let me finalize my work and clean up:
Assistant
Now let me look at my final changes:
Assistant
Now let me also use rustc-hash consistently since the existing code uses it:
Assistant
Let me build and run all tests one final time:
Assistant
All tests pass. Let me look at my code once more to ensure it's correct:
Assistant
Good,
rustc-hashis available. Let me view the final code:Assistant
Let me also use rustc-hash consistently with the existing code style:
Assistant
Let me make my code a bit cleaner and more consistent:
Assistant
Let me also test with a struct and a static method to confirm everything works correctly:
Assistant
The exact scenario from the issue is now resolved. Let me clean up:
Assistant
Let me run the existing LSP tests one more time to confirm everything is still passing:
Assistant
All 469 LSP tests pass. Let me also do a final check of the diff:
Assistant
Let me also verify that stdlib interfaces are registered the same way:
Assistant
Now let me also verify the issue's exact scenario one more time:
Assistant
The exact scenario from the issue is now resolved. Let me clean up:
Assistant
Let me also do a final check by running the existing tests:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.