Skip to content

Commit

Permalink
Split completions into multiple files
Browse files Browse the repository at this point in the history
commit-id:9774fc9a
  • Loading branch information
Draggu committed Feb 11, 2025
1 parent ceabbe3 commit 0598c85
Show file tree
Hide file tree
Showing 12 changed files with 547 additions and 489 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@ use lsp_types::{CompletionItem, CompletionItemKind};

use crate::lang::db::AnalysisDatabase;

pub fn attribute_completions(
db: &AnalysisDatabase,
attribute: Attribute,
) -> Option<Vec<CompletionItem>> {
let plugins = db.macro_plugins();

let attr_name = attribute.attr(db).as_syntax_node().get_text(db);

Some(
plugins
.iter()
.flat_map(|plugin| plugin.declared_attributes())
.filter(|name| {
// Don't suggest already typed one.
name.starts_with(&attr_name) && name != &attr_name
})
.map(macro_completion)
.collect(),
)
}

pub fn derive_completions(
db: &AnalysisDatabase,
derive_name: &str,
Expand All @@ -41,11 +20,11 @@ pub fn derive_completions(
.iter()
.flat_map(|plugin| plugin.declared_derives())
.filter(|name| name.starts_with(derive_name) && name != derive_name)
.map(macro_completion)
.map(|name| CompletionItem {
label: name,
kind: Some(CompletionItemKind::FUNCTION),
..Default::default()
})
.collect()
})
}

fn macro_completion(name: String) -> CompletionItem {
CompletionItem { label: name, kind: Some(CompletionItemKind::FUNCTION), ..Default::default() }
}
33 changes: 33 additions & 0 deletions src/ide/completion/attribute/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use cairo_lang_defs::db::DefsGroup;
use cairo_lang_syntax::node::TypedSyntaxNode;
use cairo_lang_syntax::node::ast::Attribute;
use lsp_types::{CompletionItem, CompletionItemKind};

use crate::lang::db::AnalysisDatabase;

pub mod derive;

pub fn attribute_completions(
db: &AnalysisDatabase,
attribute: Attribute,
) -> Option<Vec<CompletionItem>> {
let plugins = db.macro_plugins();

let attr_name = attribute.attr(db).as_syntax_node().get_text(db);

Some(
plugins
.iter()
.flat_map(|plugin| plugin.declared_attributes())
.filter(|name| {
// Don't suggest already typed one.
name.starts_with(&attr_name) && name != &attr_name
})
.map(|name| CompletionItem {
label: name,
kind: Some(CompletionItemKind::FUNCTION),
..Default::default()
})
.collect(),
)
}
56 changes: 0 additions & 56 deletions src/ide/completion/colon_colon.rs

This file was deleted.

Loading

0 comments on commit 0598c85

Please sign in to comment.