grep names each file once with its lines under it, the changes header keeps its position whole, and the bash teardown tests stop flaking on macOS
- grep groups its lines under each file, the layout of rg --heading, rather than repeating the path on every line: 9–28% fewer bytes than rg -n on the searches measured. scopes: true labels each run of matches with the function or type around it. - The changes pane's header shortens the path rather than cut its position, and keeps a gap before the FILE / DIFF switch. - The bash teardown tests count a loop still running as a survivor, not one write already under way when the kill landed.
This commit is contained in:
@@ -247,6 +247,17 @@ fn symbol_kind(def_kind: &str, container_kind: Option<&str>) -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// The kinds that can hold code, and so name where a line sits: not fields, variants or constants.
|
||||
const SCOPE_KINDS: [u32; 7] = [
|
||||
kinds::FUNCTION,
|
||||
kinds::METHOD,
|
||||
kinds::CLASS,
|
||||
kinds::STRUCT,
|
||||
kinds::ENUM,
|
||||
kinds::INTERFACE,
|
||||
kinds::MODULE,
|
||||
];
|
||||
|
||||
/// Function lengths for the size standards the edit hook holds, from the same outline
|
||||
/// `module_report` draws.
|
||||
pub struct SyntaxOutline;
|
||||
@@ -272,6 +283,25 @@ impl luxe_core::hooks::file_changed::OutlineSource for SyntaxOutline {
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn scopes(
|
||||
&self,
|
||||
path: &Path,
|
||||
source: &str,
|
||||
) -> Option<Vec<luxe_core::hooks::file_changed::Scope>> {
|
||||
let symbols = outline(path, source)?;
|
||||
Some(
|
||||
symbols
|
||||
.into_iter()
|
||||
.filter(|symbol| SCOPE_KINDS.contains(&symbol.kind))
|
||||
.map(|symbol| luxe_core::hooks::file_changed::Scope {
|
||||
name: symbol.name,
|
||||
start_line: symbol.start_line as usize,
|
||||
end_line: symbol.end_line as usize,
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -337,6 +367,19 @@ mod tests {
|
||||
assert_eq!(method.kind, kinds::METHOD);
|
||||
}
|
||||
|
||||
/// The scopes a search labels with are the ones that hold code, with the lines they span: a
|
||||
/// class and its method, not the attribute beside them.
|
||||
#[test]
|
||||
fn scopes_are_the_code_holding_symbols_and_their_spans() {
|
||||
use luxe_core::hooks::file_changed::{OutlineSource, Scope};
|
||||
let src = "class QuerySet:\n model = None\n\n def delete(self):\n return 1\n";
|
||||
let scopes = SyntaxOutline.scopes(Path::new("query.py"), src).expect("python parses");
|
||||
let scope =
|
||||
|name: &str, start_line, end_line| Scope { name: name.into(), start_line, end_line };
|
||||
assert_eq!(scopes, vec![scope("QuerySet", 0, 4), scope("delete", 3, 4)]);
|
||||
assert_eq!(SyntaxOutline.scopes(Path::new("notes.md"), "# hi"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_language_returns_none() {
|
||||
assert!(outline(Path::new("notes.md"), "# hi").is_none());
|
||||
|
||||
Reference in New Issue
Block a user