Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sanny_builder_core"
version = "0.4.0"
version = "0.4.1"
authors = ["Seemann <mail@sannybuilder.com>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions src/language_service/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ impl LanguageServer {
) -> Option<Vec<String>> {
let st = SYMBOL_TABLES.lock().unwrap();
let table = st.get(&handle)?;
let needle = needle.to_ascii_lowercase();
let needle = needle.to_ascii_lowercase().replace("_", "");

let list = table
.symbols
.iter()
.filter_map(|(name, map)| {
if name.to_ascii_lowercase().starts_with(&needle) {
if name.to_ascii_lowercase().replace("_", "").contains(&needle) {
for symbol_info in map {
if symbol_info.is_visible_at(line_number) {
return Some(name.clone());
Expand Down
38 changes: 18 additions & 20 deletions src/legacy_ini/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl OpcodeTable {
let mut words: HashMap<usize, CString> = HashMap::new();
let iter = c.input.iter().chain(c.output.iter());
for (real_index, param) in iter.enumerate() {
if param.r#type == CommandParamType::Arguments {
if param.r#type.eq_ignore_ascii_case("arguments") {
is_variadic = true;
}

Expand All @@ -409,17 +409,15 @@ impl OpcodeTable {
index,
Param {
real_index: real_index as u8,
param_type: match param.r#type {
CommandParamType::Gxt => ParamType::Gxt,
CommandParamType::Pointer => ParamType::Pointer,
CommandParamType::AnyModel => ParamType::AnyModel,
CommandParamType::ScriptId => ParamType::ScriptId,
CommandParamType::String8 if self.game == Game::LCS => {
ParamType::String8
}
CommandParamType::IdeModel => ParamType::IdeModel,
CommandParamType::Byte128 => ParamType::Byte128,
CommandParamType::Float => ParamType::Float,
param_type: match param.r#type.as_str() {
"zone_key" | "gxt_key" => ParamType::Gxt,
"label" => ParamType::Pointer,
"model_any" | "model_object" => ParamType::AnyModel,
"script_id" => ParamType::ScriptId,
"string" if self.game == Game::LCS => ParamType::String8,
"model_char" | "model_vehicle" => ParamType::IdeModel,
"string128" => ParamType::Byte128,
"float" => ParamType::Float,
_ => ParamType::Any,
},
},
Expand Down Expand Up @@ -518,7 +516,9 @@ impl OpcodeTable {
}

pub fn get_param_is_scr(&self, id: u16) -> bool {
self.get_opcode(id).map(|opcode| opcode.is_scr).unwrap_or(true)
self.get_opcode(id)
.map(|opcode| opcode.is_scr)
.unwrap_or(true)
}

pub fn does_word_exist(&self, id: u16, index: usize) -> bool {
Expand Down Expand Up @@ -648,18 +648,18 @@ mod tests {
input: vec![
CommandParam {
name: "".to_string(),
r#type: CommandParamType::IdeModel,
r#type: "model_char".to_string(),
source: CommandParamSource::Any,
},
CommandParam {
name: "".to_string(),
r#type: CommandParamType::IdeModel,
r#type: "model_char".to_string(),
source: CommandParamSource::Any,
},
],
output: vec![CommandParam {
name: "".to_string(),
r#type: CommandParamType::Any,
r#type: "int".to_string(),
source: CommandParamSource::AnyVar,
}],
platforms: vec![],
Expand All @@ -681,12 +681,12 @@ mod tests {
input: vec![
CommandParam {
name: "".to_string(),
r#type: CommandParamType::IdeModel,
r#type: "model_char".to_string(),
source: CommandParamSource::Any,
},
CommandParam {
name: "".to_string(),
r#type: CommandParamType::AnyModel,
r#type: "model_any".to_string(),
source: CommandParamSource::Any,
},
],
Expand Down Expand Up @@ -718,8 +718,6 @@ mod tests {

assert_eq!(opcode_table.get_param_type(id, 0), ParamType::IdeModel);
assert_eq!(opcode_table.get_param_type(id, 1), ParamType::AnyModel);


}

#[test]
Expand Down
55 changes: 34 additions & 21 deletions src/namespaces/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::common_ffi::*;
use crate::namespaces::{namespaces::*, CommandParamType};
use crate::namespaces::{namespaces::*, snippet, CommandParamType};

#[no_mangle]
pub extern "C" fn classes_new() -> *mut Namespaces {
Expand Down Expand Up @@ -344,26 +344,14 @@ pub unsafe extern "C" fn classes_get_output_count_by_id(
}

#[no_mangle]
pub unsafe extern "C" fn classes_is_input_of_type(
pub unsafe extern "C" fn classes_does_this_argument_have_type_arguments(
ns: *mut Namespaces,
opcode: OpId,
index: usize,
_type: u8,
) -> bool {
boolclosure! {{
ns.as_mut()?.is_input_of_type(opcode, index, _type.into())?.then_some(())
}}
}

#[no_mangle]
pub unsafe extern "C" fn classes_is_output_of_type(
ns: *mut Namespaces,
opcode: OpId,
index: usize,
_type: u8,
) -> bool {
boolclosure! {{
ns.as_mut()?.is_output_of_type(opcode, index, _type.into())?.then_some(())
ns.as_mut()?.is_input_of_type(opcode, index, "arguments")?.then_some(())
}}
}

Expand All @@ -376,9 +364,9 @@ pub unsafe extern "C" fn classes_get_input_type(
) -> bool {
boolclosure! {{
ns.as_mut()?.get_input_type(opcode, index).map(|x| *_type = {
match x {
CommandParamType::Float => 2,
CommandParamType::String8 | CommandParamType::Gxt => 3,
match x.as_str() {
"float" => 2,
"string" | "gxt_key" | "zone_key" => 3,
_ => 1,
}
})
Expand All @@ -394,15 +382,40 @@ pub unsafe extern "C" fn classes_get_output_type(
) -> bool {
boolclosure! {{
ns.as_mut()?.get_output_type(opcode, index).map(|x| *_type = {
match x {
CommandParamType::Float => 2,
CommandParamType::String8 | CommandParamType::Gxt => 3,
match x.as_str() {
"float" => 2,
"string" | "gxt_key" | "zone_key" => 3,
_ => 1,
}
})
}}
}

#[no_mangle]
pub unsafe extern "C" fn classes_get_command_description_with_arguments(
ns: *mut Namespaces,
opcode: OpId,
out: *mut PChar,
) -> bool {
boolclosure! {{
use std::ffi::CString;
let v = ns.as_mut()?.get_command_snippet_line(opcode)?;
*out = CString::new(v).unwrap().into_raw();
Some(())
}}
}

#[no_mangle]
pub unsafe extern "C" fn classes_generate_examples(ns: *mut Namespaces, out: *mut PChar) -> bool {
boolclosure! {{
use std::ffi::CString;
let commands = ns.as_mut()?.commands.values().collect::<Vec<_>>();
let examples = snippet::generate_opcodes_text(commands);
*out = CString::new(examples).unwrap().into_raw();
Some(())
}}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
33 changes: 11 additions & 22 deletions src/namespaces/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl From<u8> for CommandParamType {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum CommandParamSource {
Any,
AnyVar,
Expand Down Expand Up @@ -79,25 +79,6 @@ pub enum Operator {
ShiftRight,
}

impl<'de> Deserialize<'de> for CommandParamType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
match String::deserialize(deserializer).as_deref() {
Ok("gxt_key") | Ok("zone_key") => Ok(Self::Gxt),
Ok("label") => Ok(Self::Pointer),
Ok("model_any") | Ok("model_object") => Ok(Self::AnyModel),
Ok("model_char") | Ok("model_vehicle") => Ok(Self::IdeModel),
Ok("script_id") => Ok(Self::ScriptId),
Ok("string128") => Ok(Self::Byte128),
Ok("string") => Ok(Self::String8),
Ok("arguments") => Ok(Self::Arguments),
Ok("float") => Ok(Self::Float),
_ => Ok(Self::Any),
}
}
}

impl<'de> Deserialize<'de> for CommandParamSource {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down Expand Up @@ -142,11 +123,11 @@ pub struct Attr {
pub is_variadic: bool,
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone)]
pub struct CommandParam {
pub r#name: String,
pub r#source: CommandParamSource,
pub r#type: CommandParamType,
pub r#type: String,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -226,6 +207,14 @@ where
}
}

fn lowercase<'de, D>(deserializer: D) -> Result<String, D::Error>
where
D: Deserializer<'de>,
{
let val = String::deserialize(deserializer)?;
Ok(val.to_lowercase())
}

fn convert_platform<'de, D>(deserializer: D) -> Result<Vec<Platform>, D::Error>
where
D: Deserializer<'de>,
Expand Down
1 change: 1 addition & 0 deletions src/namespaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod enum_parser;
mod ffi;
mod library;
pub mod namespaces;
mod snippet;

pub use library::Command;
pub use library::CommandParam;
Expand Down
Loading
Loading