Merge pull request #894 from zed-industries/typescript-outline-fixes
Fix missing TypeScript outline entries and breadcrumbs
This commit is contained in:
commit
d12df4224a
5 changed files with 72 additions and 8 deletions
|
@ -63,7 +63,7 @@ pub fn build_language_registry(login_shell_env_loaded: Task<()>) -> LanguageRegi
|
|||
languages
|
||||
}
|
||||
|
||||
fn language(
|
||||
pub(crate) fn language(
|
||||
name: &str,
|
||||
grammar: tree_sitter::Language,
|
||||
lsp_adapter: Option<Arc<dyn LspAdapter>>,
|
||||
|
|
|
@ -144,3 +144,54 @@ impl LspAdapter for TypeScriptLspAdapter {
|
|||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui::MutableAppContext;
|
||||
use unindent::Unindent;
|
||||
|
||||
#[gpui::test]
|
||||
fn test_outline(cx: &mut MutableAppContext) {
|
||||
let language = crate::languages::language(
|
||||
"typescript",
|
||||
tree_sitter_typescript::language_typescript(),
|
||||
None,
|
||||
);
|
||||
|
||||
let text = r#"
|
||||
function a() {
|
||||
// local variables are omitted
|
||||
let a1 = 1;
|
||||
// all functions are included
|
||||
async function a2() {}
|
||||
}
|
||||
// top-level variables are included
|
||||
let b: C
|
||||
function getB() {}
|
||||
// exported variables are included
|
||||
export const d = e;
|
||||
"#
|
||||
.unindent();
|
||||
|
||||
let buffer = cx.add_model(|cx| {
|
||||
language::Buffer::new(0, text, cx).with_language(Arc::new(language), cx)
|
||||
});
|
||||
let outline = buffer.read(cx).snapshot().outline(None).unwrap();
|
||||
assert_eq!(
|
||||
outline
|
||||
.items
|
||||
.iter()
|
||||
.map(|item| (item.text.as_str(), item.depth))
|
||||
.collect::<Vec<_>>(),
|
||||
&[
|
||||
("function a ( )", 0),
|
||||
("async function a2 ( )", 1),
|
||||
("let b", 0),
|
||||
("function getB ( )", 0),
|
||||
("const d", 0),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
"enum" @context
|
||||
name: (_) @name) @item
|
||||
|
||||
(type_alias_declaration
|
||||
"type" @context
|
||||
name: (_) @name) @item
|
||||
|
||||
(function_declaration
|
||||
"async"? @context
|
||||
"function" @context
|
||||
|
@ -18,6 +22,12 @@
|
|||
"interface" @context
|
||||
name: (_) @name) @item
|
||||
|
||||
(export_statement
|
||||
(lexical_declaration
|
||||
["let" "const"] @context
|
||||
(variable_declarator
|
||||
name: (_) @name) @item))
|
||||
|
||||
(program
|
||||
(lexical_declaration
|
||||
["let" "const"] @context
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue