Skip to content

Commit 6f176f8

Browse files
committed
Add ability to hide 'private' functions and variables
1 parent 21d5491 commit 6f176f8

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

numbat-cli/src/highlighter.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ impl Highlighter for NumbatHighlighter {
3737
_completion: CompletionType,
3838
) -> Cow<'c, str> {
3939
let ctx = self.context.lock().unwrap();
40-
if ctx.variable_names().iter().any(|n| n == candidate)
41-
|| ctx
42-
.function_names()
43-
.iter()
44-
.any(|n| format!("{}(", n) == candidate)
40+
if ctx.variable_names().any(|n| n == candidate)
41+
|| ctx.function_names().any(|n| format!("{}(", n) == candidate)
4542
{
4643
Cow::Owned(ansi_format(&markup::identifier(candidate), false))
4744
} else if ctx

numbat/modules/physics/temperature_conversion.nbt

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use units::si
22

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

5-
let offset_celsius = 273.15
5+
let _offset_celsius = 273.15
66

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

10-
let offset_fahrenheit = 459.67
11-
let scale_fahrenheit = 5 / 9
10+
let _offset_fahrenheit = 459.67
11+
let _scale_fahrenheit = 5 / 9
1212

13-
fn from_fahrenheit(t_fahrenheit: Scalar) -> Temperature = ((t_fahrenheit + offset_fahrenheit) × scale_fahrenheit) kelvin
14-
fn to_fahrenheit(t_kelvin: Temperature) -> Scalar = (t_kelvin / kelvin) / scale_fahrenheit - offset_fahrenheit
13+
fn from_fahrenheit(t_fahrenheit: Scalar) -> Temperature = ((t_fahrenheit + _offset_fahrenheit) × _scale_fahrenheit) kelvin
14+
fn to_fahrenheit(t_kelvin: Temperature) -> Scalar = (t_kelvin / kelvin) / _scale_fahrenheit - _offset_fahrenheit

numbat/src/lib.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,20 @@ impl Context {
128128
ExchangeRatesCache::set_from_xml(xml_content);
129129
}
130130

131-
pub fn variable_names(&self) -> &[String] {
132-
&self.prefix_transformer.variable_names
131+
pub fn variable_names(&self) -> impl Iterator<Item = String> + '_ {
132+
self.prefix_transformer
133+
.variable_names
134+
.iter()
135+
.filter(|name| !name.starts_with('_'))
136+
.cloned()
133137
}
134138

135-
pub fn function_names(&self) -> &[String] {
136-
&self.prefix_transformer.function_names
139+
pub fn function_names(&self) -> impl Iterator<Item = String> + '_ {
140+
self.prefix_transformer
141+
.function_names
142+
.iter()
143+
.filter(|name| !name.starts_with('_'))
144+
.cloned()
137145
}
138146

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

147155
pub fn print_environment(&self) -> Markup {
148-
let mut functions = Vec::from(self.function_names());
156+
let mut functions: Vec<_> = self.function_names().collect();
149157
functions.sort();
150158
let mut dimensions = Vec::from(self.dimension_names());
151159
dimensions.sort();
152160
let mut units = Vec::from(self.unit_names());
153161
units.sort();
154-
let mut variables = Vec::from(self.variable_names());
162+
let mut variables: Vec<_> = self.variable_names().collect();
155163
variables.sort();
156164

157165
let mut output = m::empty();
@@ -179,15 +187,15 @@ impl Context {
179187
}
180188

181189
pub fn print_functions(&self) -> Markup {
182-
self.print_sorted(self.function_names().into(), FormatType::Identifier)
190+
self.print_sorted(self.function_names().collect(), FormatType::Identifier)
183191
}
184192

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

189197
pub fn print_variables(&self) -> Markup {
190-
self.print_sorted(self.variable_names().into(), FormatType::Identifier)
198+
self.print_sorted(self.variable_names().collect(), FormatType::Identifier)
191199
}
192200

193201
pub fn print_units(&self) -> Markup {

0 commit comments

Comments
 (0)