Skip to content
Closed
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
8 changes: 8 additions & 0 deletions pyrefly/lib/lsp/non_wasm/document_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ fn recurse_stmt_adding_symbols<'a>(
Stmt::ClassDef(stmt_class_def) => {
let mut children = Vec::new();
children.append(&mut recursed_symbols);

// Functions defined inside a class are methods.
for child in &mut children {
if child.kind == lsp_types::SymbolKind::FUNCTION {
child.kind = lsp_types::SymbolKind::METHOD;
}
}

let name = match stmt_class_def.name.as_str() {
"" => "unknown".to_owned(),
name => name.to_owned(),
Expand Down
15 changes: 12 additions & 3 deletions pyrefly/lib/test/lsp/lsp_interaction/document_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,20 @@ fn test_document_symbols_normal_file() {
.iter()
.any(|s| s.name == "normal_function" && s.kind == lsp_types::SymbolKind::FUNCTION);

let has_class = symbols
let class_symbol = symbols
.iter()
.any(|s| s.name == "NormalClass" && s.kind == lsp_types::SymbolKind::CLASS);
.find(|s| s.name == "NormalClass" && s.kind == lsp_types::SymbolKind::CLASS);

let has_class_and_method = match class_symbol {
Some(c) => {
c.children.as_ref().map_or(false, |children| {
children.iter().any(|s| s.name == "normal_method" && s.kind == lsp_types::SymbolKind::METHOD)
})
},
None => false,
};

has_function && has_class
has_function && has_class_and_method
})
.unwrap();

Expand Down
Loading