Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to hide 'private' functions and variables #325

Merged
merged 1 commit into from
Feb 9, 2024
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
7 changes: 2 additions & 5 deletions numbat-cli/src/highlighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ impl Highlighter for NumbatHighlighter {
_completion: CompletionType,
) -> Cow<'c, str> {
let ctx = self.context.lock().unwrap();
if ctx.variable_names().iter().any(|n| n == candidate)
|| ctx
.function_names()
.iter()
.any(|n| format!("{}(", n) == candidate)
if ctx.variable_names().any(|n| n == candidate)
|| ctx.function_names().any(|n| format!("{}(", n) == candidate)
{
Cow::Owned(ansi_format(&markup::identifier(candidate), false))
} else if ctx
Expand Down
14 changes: 7 additions & 7 deletions numbat/modules/physics/temperature_conversion.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use units::si

### Temperature conversion functions K <-> °C and K <-> °F

let offset_celsius = 273.15
let _offset_celsius = 273.15

fn from_celsius(t_celsius: Scalar) -> Temperature = (t_celsius + offset_celsius) kelvin
fn to_celsius(t_kelvin: Temperature) -> Scalar = t_kelvin / kelvin - offset_celsius
fn from_celsius(t_celsius: Scalar) -> Temperature = (t_celsius + _offset_celsius) kelvin
fn to_celsius(t_kelvin: Temperature) -> Scalar = t_kelvin / kelvin - _offset_celsius

let offset_fahrenheit = 459.67
let scale_fahrenheit = 5 / 9
let _offset_fahrenheit = 459.67
let _scale_fahrenheit = 5 / 9

fn from_fahrenheit(t_fahrenheit: Scalar) -> Temperature = ((t_fahrenheit + offset_fahrenheit) × scale_fahrenheit) kelvin
fn to_fahrenheit(t_kelvin: Temperature) -> Scalar = (t_kelvin / kelvin) / scale_fahrenheit - offset_fahrenheit
fn from_fahrenheit(t_fahrenheit: Scalar) -> Temperature = ((t_fahrenheit + _offset_fahrenheit) × _scale_fahrenheit) kelvin
fn to_fahrenheit(t_kelvin: Temperature) -> Scalar = (t_kelvin / kelvin) / _scale_fahrenheit - _offset_fahrenheit
24 changes: 16 additions & 8 deletions numbat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,20 @@ impl Context {
ExchangeRatesCache::set_from_xml(xml_content);
}

pub fn variable_names(&self) -> &[String] {
&self.prefix_transformer.variable_names
pub fn variable_names(&self) -> impl Iterator<Item = String> + '_ {
self.prefix_transformer
.variable_names
.iter()
.filter(|name| !name.starts_with('_'))
.cloned()
}

pub fn function_names(&self) -> &[String] {
&self.prefix_transformer.function_names
pub fn function_names(&self) -> impl Iterator<Item = String> + '_ {
self.prefix_transformer
.function_names
.iter()
.filter(|name| !name.starts_with('_'))
.cloned()
}

pub fn unit_names(&self) -> &[Vec<String>] {
Expand All @@ -145,13 +153,13 @@ impl Context {
}

pub fn print_environment(&self) -> Markup {
let mut functions = Vec::from(self.function_names());
let mut functions: Vec<_> = self.function_names().collect();
functions.sort();
let mut dimensions = Vec::from(self.dimension_names());
dimensions.sort();
let mut units = Vec::from(self.unit_names());
units.sort();
let mut variables = Vec::from(self.variable_names());
let mut variables: Vec<_> = self.variable_names().collect();
variables.sort();

let mut output = m::empty();
Expand Down Expand Up @@ -179,15 +187,15 @@ impl Context {
}

pub fn print_functions(&self) -> Markup {
self.print_sorted(self.function_names().into(), FormatType::Identifier)
self.print_sorted(self.function_names().collect(), FormatType::Identifier)
}

pub fn print_dimensions(&self) -> Markup {
self.print_sorted(self.dimension_names().into(), FormatType::TypeIdentifier)
}

pub fn print_variables(&self) -> Markup {
self.print_sorted(self.variable_names().into(), FormatType::Identifier)
self.print_sorted(self.variable_names().collect(), FormatType::Identifier)
}

pub fn print_units(&self) -> Markup {
Expand Down
Loading