language server features upgrade#1175
Merged
sbillig merged 36 commits intoargotorg:masterfrom Dec 12, 2025
Merged
Conversation
b159e14 to
fd2c56c
Compare
sbillig
reviewed
Dec 9, 2025
| } | ||
| } | ||
|
|
||
| // Collect glob imports |
Collaborator
There was a problem hiding this comment.
Name resolution rules dictate that explicitly named imports and local items trump glob imports.
Collaborator
There was a problem hiding this comment.
Here's codex's version; prompted to encourage reuse of the name resolution machinery to get the precedence rules right. It looks right, but please verify. Also not sure if we want primitives included for this use-case.
#[salsa::tracked(return_ref)]
fn items_in_scope_impl<'db>(
db: &'db dyn HirAnalysisDb,
i_scope: ItemScope<'db>,
) -> IndexMap<String, NameRes<'db>> {
let scope = i_scope.scope_kind(db).to_scope();
let domain = i_scope.domain(db);
let mut items: IndexMap<String, NameResBucket<'db>> = IndexMap::default();
let mut resolver = NameResolver::new(db, &DefaultImporter);
let local_resolutions =
resolver.collect_all_resolutions_for_glob(scope, scope, FxHashSet::default());
// Local definitions + imports (named then glob) with resolver precedence.
for (ident, resolutions) in local_resolutions {
let name = ident.data(db).to_string();
let bucket = items.entry(name).or_default();
for name_res in resolutions {
if name_res.domain & domain != NameDomain::Invalid {
bucket.push(&name_res);
}
}
}
// Collect unnamed/prelude imports (treated like named imports).
let imports = &resolve_imports(db, scope.ingot(db)).1;
if let Some(unnamed) = imports.unnamed_resolved.get(&scope) {
for bucket in unnamed {
for name_res in bucket.iter_ok() {
if name_res.domain & domain != NameDomain::Invalid
&& let Some(res_scope) = name_res.scope()
&& let Some(name) = res_scope.name(db)
&& name_res.is_visible(db, scope)
{
items
.entry(name.data(db).to_string())
.or_default()
.push(name_res);
}
}
}
}
// Recursively collect from parent scope (lexical shadowing handled via derivation).
if let Some(parent) = scope.parent(db) {
let parent_items = items_in_scope(db, parent, domain);
for (name, name_res) in parent_items {
let mut inherited = name_res.clone();
inherited.derivation.lexed();
items.entry(name.clone()).or_default().push(&inherited);
}
}
// External ingots (lowest before primitives).
for (ext_name, ingot) in scope.top_mod(db).ingot(db).resolved_external_ingots(db) {
let res = NameRes::new_from_scope(
ScopeId::from_item((ingot.root_mod(db)).into()),
NameDomain::TYPE,
NameDerivation::External,
);
if res.domain & domain != NameDomain::Invalid {
items
.entry(ext_name.data(db).to_string())
.or_default()
.push(&res);
}
}
// Builtin primitive types (lowest precedence).
if domain & NameDomain::TYPE != NameDomain::Invalid {
for &prim in PrimTy::all_types() {
let res = NameRes {
kind: NameResKind::Prim(prim),
domain: NameDomain::TYPE,
derivation: NameDerivation::Prim,
};
items
.entry(prim.name(db).data(db).to_string())
.or_default()
.push(&res);
}
}
// Pick the best resolution per requested domain using resolver ordering.
let mut flattened = IndexMap::default();
for (name, bucket) in items {
match bucket.pick(domain) {
Ok(res) => {
flattened.insert(name, res.clone());
}
Err(NameResolutionError::Ambiguous(cands)) => {
if let Some(first) = cands.first() {
flattened.insert(name, first.clone());
}
}
Err(_) => {}
}
}
flattened
}
Draft
Add a generic items_in_scope API to HIR that collects all visible items in a given scope across the specified name domains. This follows the same pattern as available_traits_in_scope and properly handles: - Named imports - Glob imports - Unnamed/prelude imports - Direct child items - Parent scope items (recursively) Add ScopeId::items_in_scope() as a convenient traversal-like method. Rewrite completion handler to: - Find the most specific scope at cursor position - Use items_in_scope to get properly scoped completions - Convert NameRes items to appropriate CompletionItem kinds This fixes completion showing random unrelated symbols and provides context-aware suggestions that respect lexical scope.
- Set insert_text, insert_text_format, and insert_text_mode to prevent unwanted text replacement and indentation issues - Detect when completion is triggered by '.' for future member access implementation - Add TODO for member completion (needs proper public API for type members) This fixes the issue where completion would replace existing text and add extra indentation.
Use top_mod.target_at() instead of reference_at() + target_at() so that rename works when cursor is on a definition name, not just references.
- Add textDocument/implementation handler for traits and trait methods
- On traits: navigates to all impl Trait blocks
- On trait methods: navigates to all implementations of that method
- Fix trait method rename to also rename implementations
- When renaming a trait method, all corresponding method definitions
in impl blocks are also renamed
c2137f8 to
43d9b0f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #1165 (reference view API) to add all kinds of new language server features including code completion, signature help, inlay hints, and more.
Changes
HIR layer additions:
items_in_scopequery for collecting all visible items in a scope (imports,child items, parent scopes)
ScopeId::items_in_scope()convenience method for scope-aware nameresolution
ModuleTree::tree_node()to returnResultinstead of panicking oncross-ingot queries
diagnostics)
LSP handlers (
language-server):auto-import for symbols from current ingot
etc.
Misc fixes:
(was applying label mismatch errors at call sites)
.and::) for path completionsWhat's left for followup